Hi all,
I apologize for my ignorance if this has been discussed before but I can't seem to find anything that strictly addresses this.
I think I get the gist of file i/o but what I'm wondering is is there any way to write/read a custom type to a file? Say, for example, I want to store the state of the items stored within an item inventory every time the player saves his game. An item being defined as:
Type Item itemName as String itemFunction as String itemFunctionPoints as Integer itemDescription as String itemQuantity as Integer itemCost as Integer EndType
I know I could just do:
DIM items() as Item
REM items() is filled with Items
open to write 1,"save.dat"
for i=0 to ArrayCount(items())
write string 1,item(i).itemName
write string 1,item(i).itemFunction
write float 1,item(i).itemFunctionPoints
write string 1,item(i).itemDescription
write float 1,item(i).itemQuantity
write float 1,item(i).itemCost
Next
close file 1
The above is fine in that it stores all the relevant data to any specific Item within items(). But say I have an Item called FragGrenade:
FragGrenade as Item : FragGrenade.itemName="Fragmentation Grenade" : FragGrenade.itemFunction="Damage" : FragGrenade.itemDescription="Hand-thrown explosives designed to emit a forceful explosion accompanied by a wave of metal shrapnel." : FragGrenade.itemQuantity=5 : FragGrenade.itemCost=150
If I was to read the data stored to save.dat it would give me all the fields but not the FragGrenade pointer (
FragGrenade.whatever).
How, then, can I reload the data from items() and still have a Item be the same type as it was stored? Or, better yet, is there a way to directly store a custom type?