PDA

View Full Version : Saving/Loading array info into text file


Hobbs
04-24-2007, 04:19 PM
I have a feeling that this is in the help file, but as our current production time line is very tight, i don't have time to dig through MaxScript resource right now.

I have 2 arrays that are basically acting as a hash table right now...one holds my string, and the other my struct info. I need to write these files to a text file, and then be able to easiy read it in to the rollout...kind of like a save and load.

my index array is objIndex -- strings for file name
my field array is objArray -- struct info

my struct is Obj_Library (File, type, objects)

this will probably be run through a menu, i just haven't had time to write it in yet...any help in getting started or a point in the right direction would be helpful.

Pjanssen
04-24-2007, 04:32 PM
Perhaps something like this could be useful to you?
These are two functions I wrote to save and load data from an INI file, based on an object structure:


/* SAVE SETTINGS FUNCTION */
function saveINISettings iniFile section sourceObject = (
local properties = (getPropNames sourceObject);
for i in properties do (
attribute = (i as string);
local value = ((getProperty sourceObject i) as string);
if not (value == "undefined") then (
setINISetting iniFile section attribute value;
)
)
)



/* LOAD SETTINGS FUNCTION */
function loadINISettings iniFile section targetObject = (
local iniSettings = (getINISetting iniFile section);

for i in iniSettings do (
iniAttribute = (i as string);
iniValue = (getINISetting iniFile section iniAttribute);
if iniValue != "" then (
setProperty targetObject i (convertString iniValue);
)
)
)

/* CONVERT STRING FUNCTION */
/* */
/* Converts a string to a more suitable variable type. */
/* */
/* stringVar:<string> */
/* String that will be converted. */
/* */
function convertString stringVar = (
local newVar;
if stringVar != "" then (
if (stringVar as integer) != undefined then (
newVar = stringVar as integer;
) else (
try (
if (execute stringVar) == undefined then (
newVar = stringVar;
) else (
newVar = execute stringVar;
)
) catch(
newVar = stringVar;
)
)
)
return newVar;
)

CGTalk Moderation
04-24-2007, 04:32 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.