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
Arbitrary File Access: Type Text: R/W int, float, etc.
-
- Posts: 55
- Joined: Wed 21. Jul 2010, 18:43
Re: Arbitrary File Access: Type Text: R/W int, float, etc.
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.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.
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.
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?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 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
- Attachments
-
- StringToInt.zip
- Module that can be included in a MemBrain Script to provide the function 'StringToInt'
- (1.42 KiB) Downloaded 1164 times
Thomas Jetter
Re: Arbitrary File Access: Type Text: R/W int, float, etc.
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
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
- Attachments
-
- ConfigFile.zip
- A script class to be included in your own scripts in order to use a config file.
- (1.73 KiB) Downloaded 1108 times
Thomas Jetter