1 registered members (AndrewAMD),
684
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Reading from dat, or ini
#228737
09/22/08 02:28
09/22/08 02:28
|
Joined: Sep 2008
Posts: 29
log2
OP
Newbie
|
OP
Newbie
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: [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
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
The following is probably not helpful at all: A6.60 http://testdummy93.tripod.com/3DGS/3DGS_index.htmltDe.zip -> tDe.dll + tDe.wdl
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: log2]
#228746
09/22/08 05:47
09/22/08 05:47
|
mercuryus
Unregistered
|
mercuryus
Unregistered
|
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
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
|
|
|
Re: Reading from dat, or ini
[Re: MrGuest]
#229177
09/25/08 05:23
09/25/08 05:23
|
Joined: Sep 2008
Posts: 29
log2
OP
Newbie
|
OP
Newbie
Joined: Sep 2008
Posts: 29
|
hmmm can't really tie that to an answer 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 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
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
// 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
log2
OP
Newbie
|
OP
Newbie
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
Last edited by log2; 09/26/08 04:56.
|
|
|
|