Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (dr_panther, Quad, AndrewAMD, 7th_zorro), 945 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Reading from dat, or ini #228737
09/22/08 02:28
09/22/08 02:28
Joined: Sep 2008
Posts: 29
L
log2 Offline OP
Newbie
log2  Offline OP
Newbie
L

Joined: Sep 2008
Posts: 29
so far I only know of one way to read from an INI, or DAT, but I would like to know if there is a way to read from one of those files in a standard ini format..

In case you're not familiar with the standard ini format it looks something like this:
Quote:
[topic]
subject=answer
subject2=answer2
[topic2]
subject=answer


So in other words I'd like to know if I could specify the topic, then obviously specify the subject and receive the answer..

Or even if there is a way to do it without the topics would definitely help, so I can just call out the subject and receive the answer

Any help appreciated, thanks

Re: Reading from dat, or ini [Re: log2] #228743
09/22/08 05:02
09/22/08 05:02
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
The following is probably not helpful at all:

A6.60
http://testdummy93.tripod.com/3DGS/3DGS_index.html
tDe.zip -> tDe.dll + tDe.wdl

Code:
STRING sAnswer[256];
// set path
ifdef DEVELOP;
inif_wp(work_dir, "questions.ini");
ifelse;
inif_wp(exe_dir, "questions.ini");
endif;

inif_wSect("topic"); 	// set section
inif_rs("subject", "?", sAnswer);	// read string
// ...
inif_rs("subject2", "?", sAnswer);	// read string
// ...
inif_wSect("topic2");	// set section
inif_rs("subject", "?", sAnswer);  // read string
// ...


Re: Reading from dat, or ini [Re: testDummy] #228745
09/22/08 05:16
09/22/08 05:16
Joined: Sep 2008
Posts: 29
L
log2 Offline OP
Newbie
log2  Offline OP
Newbie
L

Joined: Sep 2008
Posts: 29
thanks looks good, but I take it there is currently no way to do it without a plugin?

Re: Reading from dat, or ini [Re: log2] #228746
09/22/08 05:47
09/22/08 05:47

M
mercuryus
Unregistered
mercuryus
Unregistered
M



read:
1. read the ini file in a text object
2. normalize the text object
3. search for your [topic]
4. search for your key=
5. return the value

add/delete:
1. read the ini file in a text object
2. create a temp dest. textobject
3. copy untouched entries to the dest textobject
4. when found your [topic] your key=
change the value(change) or skip copying the line(del)
6. write the dest. textobject


Re: Reading from dat, or ini [Re: ] #229133
09/24/08 19:00
09/24/08 19:00
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
have a look at
Code:
var_for_name()


Re: Reading from dat, or ini [Re: MrGuest] #229177
09/25/08 05:23
09/25/08 05:23
Joined: Sep 2008
Posts: 29
L
log2 Offline OP
Newbie
log2  Offline OP
Newbie
L

Joined: Sep 2008
Posts: 29
hmmm can't really tie that to an answer
Originally Posted By: "From Manual"
Returns a pointer to a variable with the given name. If the name string contains a '=' followed by a number, the variable is set to that number. Otherwise a '=' and the current variable value is appended to the string. This function can be used to display or alter variables during gameplay for debugging purposes.


Also mercuryus, do you have any code example, I can only assume from your message that you mean to open the ini file in a
Code:
TEXT whatever = {}
however I can't really find any reference in the manual as to how to search an ini/txt file or how to open the ini file in a text object

but I appreciate both of your help, and am awaiting a reply, thanks a bunch

Re: Reading from dat, or ini [Re: log2] #229229
09/25/08 17:55
09/25/08 17:55
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Code:
// not complete; just an example
// tested quickly; may have errors
TEXT ini_t1 {
	strings = 256;

}
var ini_nLinesC = 0;
var ini_bSect = 0;
STRING ini_sValue[256];
STRING ini_s1[256];
STRING ini_s2[256];
STRING ini_s3[256];
var ini_n1 = 0;
var ini_n2 = 0;

function inif_get(_sSection, _sKey) {
	ini_n1 = 0;
	str_cpy(ini_sValue, "");
	ini_bSect = 0;
	while(ini_n1 < ini_nLinesC) {
		if (str_stri(ini_t1.string[ini_n1], "[") == 1) {
			if (ini_bSect) {
				return(0);
			}
			str_cpy(ini_s1, ini_t1.string[ini_n1]);
			str_clip(ini_s1, 1);
			str_trunc(ini_s1, 1);
			if (str_cmpi(_sSection, ini_s1)) {
				ini_bSect = 1;
			}
		} else {
			if (!ini_bSect) { goto(next1); }
			ini_n2 = str_stri(ini_t1.string[ini_n1], "=");
			if (ini_n2 == 0) { goto(next1); } 
			str_cpy(ini_s2, ini_t1.string[ini_n1]);
			str_cpy(ini_s3, ini_s2);
			str_trunc(ini_s2, (str_len(ini_s2) - ini_n2) + 1);
			if (str_cmpi(_sKey, ini_s2)) {
				str_clip(ini_s3, ini_n2);
				str_cpy(ini_sValue, ini_s3);
				return(1);
			}
		}
		next1:
		ini_n1 += 1;
	}
	return(0);
}

function inif_load(_sFile) {
	ini_nLinesC = txt_load(ini_t1, _sFile);
	return(ini_nLinesC);
}

//...
inif_load("questions.ini");
inif_get("topic2", "subject");
// do something with ini_sValue


Re: Reading from dat, or ini [Re: testDummy] #229283
09/26/08 04:45
09/26/08 04:45
Joined: Sep 2008
Posts: 29
L
log2 Offline OP
Newbie
log2  Offline OP
Newbie
L

Joined: Sep 2008
Posts: 29
Great, thanks testDummy, I'm gonna try that out right away, again thanks a lot very much appreciated

EDIT: Just getting back, seems to be working perfectly, gonna do some more testing with it, but right now it seems to be working perfectly, than you so much testDummy laugh

Last edited by log2; 09/26/08 04:56.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1