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

This forum is dedicated to everything about MemBrain Scripting. All Questions or other contributions with respect to scripting should be placed here.
Especially, if you have an interesting script that you might want to share with other MemBrain users, please post it within a new topic in this forum. Try to choose a title for your topic that allows other users to quickly identify the basic purpose of your script.
Post Reply
MrCreosote
Posts: 55
Joined: Wed 21. Jul 2010, 18:43

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

Post 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
User avatar
Admin
Site Admin
Posts: 438
Joined: Sun 16. Nov 2008, 18:21

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

Post 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
Attachments
StringToInt.zip
Module that can be included in a MemBrain Script to provide the function 'StringToInt'
(1.42 KiB) Downloaded 932 times
Thomas Jetter
User avatar
Admin
Site Admin
Posts: 438
Joined: Sun 16. Nov 2008, 18:21

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

Post 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
Attachments
ConfigFile.zip
A script class to be included in your own scripts in order to use a config file.
(1.73 KiB) Downloaded 899 times
Thomas Jetter
Post Reply