|
Post by F1Andre on Feb 22, 2015 16:47:50 GMT
Hi, so I've been wondering. How do you read a certain line from a .txt via the iFileRead() function (as well as the iFileWrite() ). Example: if I have the numbers 2, 3,5,67,3,2323,6 in a .txt file and each value is on a separate line. How can I ask for the line 3 value (wich in this case is '5') to use that value in a script.
--Andre
|
|
|
Post by Power Supersport on Feb 22, 2015 17:03:10 GMT
Using iFileValueRead() two times without giving them value, then call it again with your wanted value...
iFileValueRead(); (in your case 2) iFileValueRead(); (in your case 3) iFileValueRead() = wanted value; (in your case 5)
Give it a try!
|
|
|
Post by F1Andre on Feb 22, 2015 17:21:27 GMT
Thanks. I haven't tried or worked with File Functions(I have just read the script references). So if I understand you correctly I should call on each value till I get the specific line I want, or just call all the values and declare them and assign a variable to it like this:
int numLine1 = iFileValueRead(iFileReadOpen(".\\the file name.txt")); int numLine2 = iFileValueRead(iFileReadOpen(".\\the file name.txt")); int numLine3 = iFileValueRead(iFileReadOpen(".\\the file name.txt")); // So numLine3 is now line 3 value in .txt file
|
|
|
Post by Power Supersport on Feb 22, 2015 17:30:50 GMT
Absolutley Right!
|
|
|
Post by F1Andre on Feb 22, 2015 17:46:29 GMT
Shot, I won't be testing it till about 2 weeks time for I'm still busy with perfecting my AI F1 Car. But just another question. If I were only to use numbers with decimal values in the script would it be better to read and write it as a iFileValueRead||Write() or force changing it to a string like this: int number = 12.435; and changing it to String newnumber = static_cast<string>(number); and saving and reading it as a iFileStringRead||Write(). I worry that some values won't be read or write when I use iFileValueRead() cause it is a non compatible(viable) number/value.
|
|
|
Post by NicusorN5 on Feb 22, 2015 17:48:37 GMT
hmmm,you're using IFileRead for a script variable or a counter?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 22, 2015 17:50:51 GMT
Funny news nicusor I just read every line
|
|
|
Post by F1Andre on Feb 22, 2015 17:55:14 GMT
It would be script variable.
|
|
|
Post by Power Supersport on Feb 22, 2015 18:05:37 GMT
There is no difference will the values be decimal or integer... The script will read them correct!
|
|
|
Post by mikehense on Feb 22, 2015 18:10:58 GMT
yeah... like said above, text file io is usually sequential... so best to read everything in and assign them to variables in script, then use only the ones you want...
best to keep things simple...
i use only strings... everything is changed to strings before saving... converted to numbers where necessary after they are read back and need to be used in script... otherwise they stay as string variables...
|
|
|
Post by F1Andre on Feb 22, 2015 18:30:31 GMT
Thanks this was very helpful. I will keep this in mind in the weeks to come.
-- Andrรฉ
|
|
|
Post by NicusorN5 on Feb 22, 2015 18:38:28 GMT
Now,i can close this topic?
|
|
|
Post by Power Supersport on Feb 22, 2015 18:50:12 GMT
Nicusor, I think that you don't need to close the topic...
|
|
|
Post by mikehense on Feb 22, 2015 18:55:54 GMT
yeah... there may be additional insights, comments, questions...
|
|
|
Post by NicusorN5 on Feb 22, 2015 18:58:31 GMT
oh.lol somebody noticed forum colour ? yay
|
|
|
Post by F1Andre on Mar 23, 2015 15:45:47 GMT
yeah... like said above, text file io is usually sequential... so best to read everything in and assign them to variables in script, then use only the ones you want... best to keep things simple... i use only strings... everything is changed to strings before saving... converted to numbers where necessary after they are read back and need to be used in script... otherwise they stay as string variables... How do I convert lets say a int to a string, I did the following but said it can't be converted. Int car = 1;
string newcar = cast<string>(car);
|
|
|
Post by Power Supersport on Mar 23, 2015 16:00:57 GMT
Did you tried:
string newcar = car;
Edit: Just tried it... it works!
|
|
|
Post by F1Andre on Mar 23, 2015 17:00:00 GMT
Did you tried: string newcar = car; Edit: Just tried it... it works!What the hell, no other language would even allow it. Oh well thank you. The angel script documentation say that you need to use cast. Weird stuff.
|
|
|
Post by Power Supersport on Mar 23, 2015 17:27:23 GMT
No problem...
|
|