VBfx / Tile tutorial / Step 1

Save and Load, Write and Read

I always differ between those 4 functions. So what's the difference and why do we need 4 and not just 2? Well Save and Load are only dedicated to open and close the file, checking if it exists and such. Write and Read on the other hand only handle the pure data. So what's the idea behind this? - Keep on reading!

Parent and child objects

Imagine a Object class (by objects I mean chests, swords, candles, trees and such). Now remember the chest can hold even more objects, called child objects of the chest (where the chest would be called the parent object). But the same counts for the child objects, say you put a bag into the chest and the bag holds some herbs.

Now we want to save the parent object which is the chest in our example. The call could look something like this:

'Save parent object
Objects(0).SaveData App.Path & "\Objects\chest.obj"

SaveData would try to open the file and then call the WriteData function that writes the chest object into the file. Further it would check if there's any child object and if so call the WriteData function of each child. When done the chest and all child objects would be stored into chest.obj, agree with me?

Now we go back to the start and see what happened if we didn't split up the function.

SaveData would still open the file, but also write the chest data in there. It would then call the SaveData function of each child. If the file name stayed the same all childs would overwrite the chest.obj file and only the last child would remain in this file. No good. Seems like we have to choose different file names for each child object. But oh wait, we have 1,000 child objects in our chest (well probably not in the chest, but in the world). See that this would result in 1,000 files? Still no good huh? I hope you get the idea.

Navigation