PDA

View Full Version : make the script to remember last entered values



waelkf
01-09-2010, 12:52 AM
hi all

i know it an easy question to you all.

how can i make my script remember the last entered values, so the next time i run the script it will remember the last ones.

thanks and regards

wael

walfridson
01-09-2010, 03:44 AM
The globalstore() function works the same as the store() command, however it functions across different scripts of the same architecture.

globalstore(“heading”, 23);

The globalrecall() function works the same as the recall() command, however it functions across different scripts.

heading = globalrecall(“heading”, 8);

You can also save a settings file beside the script or in temp dir..

evenflcw
01-09-2010, 06:25 AM
Personally I would refrain from using globalstore(). It's dirty! On Windows it stores the values in the Windows registry. And there is no way to clean them out of there from lscript. The user has to know about it and clean the registry himself. You definitely shouldn't use this if you want save alot of values.

If I need to store values (especially alot of them) across sessions, I save the custom setting file, as also suggested by Johan.

If I don't need values saved across sessions, I might use the regular store()/recall(). I don't know where they are stored, likely in LWs own temporary memory footprint. But most of the time I just use the custom setting file as it enables everything and gives you full control.

waelkf
01-09-2010, 10:10 AM
thank you guys, this realy helped alot.
but how can store and read a data to/from file.

thanks and regards
wael

waelkf
01-09-2010, 12:18 PM
what i realy looking for is, how to read a sequence of values from a file and feed it to array,


thanks in advance
wael

evenflcw
01-09-2010, 03:40 PM
Download the lscript manuals from the Lightwave3d.com developer sections and you should find what you seek and more. In particular you'll want to checkout the sections about the File Object Agent. Basically you simply tell it what file to read, then ask it to send you the contents one row at a time (as text). You'll have to make sense of these lines, trim them down and convert them to whatever format you want them stored as in your array. If I tell you in any more detail, I'll end up writing the script for you.

Matt
01-09-2010, 06:29 PM
what i realy looking for is, how to read a sequence of values from a file and feed it to array,

thanks in advance
wael

Off the top of my head, something like this ...



// To read a file to an array

// Declare array variable
my_array;

// Open file
file_to_read = File( PATH_TO_FILE,"r");

// Check file was opened
if(file_to_read)
{
// Loop through file until end
while( !file_to_read.eof() )
{
// Add line from file into array ...
my_array += file_to_read.read();
}
}

// Close file
file_to_read.close();



// To write to a file from an array

// Open file
file_to_write = File( PATH_TO_FILE,"w");

// Check file was opened
if(file_to_write)
{
// Loop through array
for( loop = 1; loop < sizeof( my_array ) + 1; loop++ )
{
// Add line to file from array ...
file_to_write.writeln( my_array[ loop ] );
}
}

// Close file
file_to_write.close();

Bookmark this site, it kicks the Official LScript documentation into next week
http://www.mikegreen.name/Lscript/Lscript%20Index.html

waelkf
01-10-2010, 12:07 AM
gus, you are realy great.
thanks alot for the help.