Page 1 of 1

Arbitrary File Access: Type Text: R/W int, float, etc.

Posted: Mon 18. Oct 2010, 20:30
by MrCreosote
OBJECTIVE: Use a "control" file containing parameter settings which is read by a script and used to automate a MemBrain run. Things like Step Size, Error Target, Export File Name, Network Name, etc. would be contained in this Control File.

PROBLEM is: I can't seem to I/O numbers from a text file.

The Read (string) works as expected but What am I missing when I try to Read or Write (int) or (float)? (It seems like the commands work OK for binary files.)

ASSUMING that numbers can be I/O'd only from Binaries and Strings can only be I/O'd from Text Files, it sounds like it is impossible to I/O from files that have both numbers and strings? Is this true?

If YES, then to handle such a file (mixed mode lets call it), one must read the line as a string and parse out the numbers?

While not too bad a job in Delphi, in AngelScript, there don't seem to be any StrToFloat or IntToStr functions which means to get the numbers into and out of the string, the numbers must be built/read one character at a time. If this is true, then its too difficult.

Thanks
Tom

Re: Arbitrary File Access: Type Text: R/W int, float, etc.

Posted: Wed 20. Oct 2010, 00:22
by Admin
MrCreosote wrote:While not too bad a job in Delphi, in AngelScript, there don't seem to be any StrToFloat or IntToStr functions which means to get the numbers into and out of the string, the numbers must be built/read one character at a time. If this is true, then its too difficult.
Attached is a small code module that can be included in your script that provides a 'StringToInt' function. I also added a small test script to the package that includes the script module and tests the function. Just execute the test script in MemBrain.

Something like a 'IntToStr' or similar is not required since the string class can automatically convert to a string: Just assign a value to a string and it will work. The test script mentioned above also contains an example for this.
MrCreosote wrote:ASSUMING that numbers can be I/O'd only from Binaries and Strings can only be I/O'd from Text Files, it sounds like it is impossible to I/O from files that have both numbers and strings? Is this true?
I think it should be possible to have both (string and binary data) written and read to/from binary files, I'll have to cross-check this myself, however. Have you tried it with binary files, too?

I don't have something like a 'StringToFloat' function at hand at the moment. I should add some built-in functions for these conversions into the next MemBrain revision.

Regards

Re: Arbitrary File Access: Type Text: R/W int, float, etc.

Posted: Wed 20. Oct 2010, 14:21
by Admin
Hi,

Below I've attached a script class that builds a config file for you. Comments on what to adapt for your needs are included in the file 'ConfigFile.as'.
There is also an example script that demonstrates how to use the script class.

With this script class you have some kind of 'Configuration Data Center' in your script that can be loaded from or saved to file. It allows both string and binary data to be intermixed, however, the created file is not human readable (or, to be more precise, you will be able to read the strings in there but not the binary data).

Hope that helps as long as there is nothing like 'StringToFloat' or comparable...

Regards,
Thomas