Loading From File
Blitz3D Forums/Blitz3D Beginners Area/Loading From File
| ||
Hi, This is my Saving Function
Function FNT_Save()
SaveFile = WriteFile("Level.txt")
For Level.LevelAssets = Each LevelAssets
Level\xpos = EntityX(Level\BlockHandle)
Level\zpos = EntityZ(Level\BlockHandle)
Level\Rotation = EntityRoll(Level\BlockHandle)
WriteInt( SaveFile, Level\xpos )
WriteInt( SaveFile, Level\zpos )
WriteInt( SaveFile, Level\Rotation)
Next
CloseFile(SaveFile)
End Function
And seems to work (well it generates a file) What would be the loading equivalent of this? how could I load the Type information back into an empty Type collection, and how does blitz know how many types are in the type collection? |
| ||
| Blitz keeps track of 'how many' instances there are behind the scenes so you don't have to worry. Every time NEW is called, another is created. To Load in I would suggest 'something similar to' |
| ||
| Hi Folks, Before saving count how many instances of the type you have and write that in as a leading value, so something like:
Function FNT_Save()
count = 0
for level.levelassets = each levelassets
count = count + 1
next
SaveFile = WriteFile("Level.txt")
WriteInt(Savefile, count)
For Level.LevelAssets = Each LevelAssets
Level\xpos = EntityX(Level\BlockHandle)
Level\zpos = EntityZ(Level\BlockHandle)
Level\Rotation = EntityRoll(Level\BlockHandle)
WriteInt( SaveFile, Level\xpos )
WriteInt( SaveFile, Level\zpos )
WriteInt( SaveFile, Level\Rotation)
Next
CloseFile(SaveFile)
End Function
This will make reading it back in again nice and simple, so something like: ( pseudo code alert ;0) )
Function LoadLevel()
levelfile = openfile("level.txt")
count = readint(levelfile)
for assets = 0 to count
level.levelasset = new levelasset
level\x = readint()
...
etc
next
closefile
end function
Hope that makes some sense. Later, Jes |
| ||
Here ya go:
Function FNT_Load()
LoadFile = ReadFile("Level.txt")
While not eof(LoadFile)
Level.LevelAssets = new LevelAssets
Level\xpos = ReadInt(LoadFile)
Level\zpos = ReadInt(LoadFile)
Level\Rotation = ReadInt(LoadFile)
Wend
CloseFile(LoadFile)
End Function Edit: LOL, it's sure flooding help here. |
| ||
| Hi Folks, ...or you could do like Malice suggested ;0) Later, Jes |
| ||
| lol thanks all, i put malice's in and got a massive memory drain (900 meg of ram in 3 seconds, more memory loss than a night out with £50 in the back pocket and some fake id) turns out i needed While Not Eof(loadFile) as retrobooster said :) that little loadfile at the end saved the moment. thanks dudes yay, it works. |
| ||
ok snag number 2
Function FNT_LoadFile()
FNT_Clear()
LoadFile = ReadFile("Level.txt")
While Not Eof(loadfile)
Level.LevelAssets = New LevelAssets
Level\AssetType$=ReadString$( loadfile ) ; loads back Type of Mesh
Level\xpos = ReadInt(loadfile) ;Loads back xpos data
Level\zpos = ReadInt(loadfile) ;Loads back zpos data
Level\Rotation = ReadInt(loadfile) ;loads back Rotational Data
Level\BlockHandle = CopyMesh (Level\AssetType$) ;Inserts Mesh <---doesn't work
EntityPickMode Level\BlockHandle,2 ; Changed pickmode to polygon
PositionEntity Level\BlockHandle,Level\xpos,0,Level\zpos ;Applys position data
RotateEntity Level\BlockHandle,0,0,Level\Rotation ;applys rotation data
Wend
CloseFile(LoadFile) ;Closes file
End Function
it will not copy the mesh into the level\blockandle based on the ifno in the level\assettype$ string. I have traced the string and it has the correct string in it, and if i put a mesh name in directy it works. i think its trying to copy a mesh in the actual string rather than using the name in the string to find the mesh. the mesh handles are global. any ideas? |
| ||
| Level\AssetType$=ReadString$( loadfile ) ; loads back Type of Mesh ... Level\BlockHandle = CopyMesh (Level\AssetType$) ;Inserts Mesh <---doesn't work I think you're confusing handle names with string$ here. Handles are really just numerical integer variables, like in the following b$ has absolutely no connection with the variable 'apple' You could try having a field that contains a string related to the mesh you need, but will need another lot of code to actually copy the mesh. i.e. [codebox] Select True Case Level\Meshtype$="Chair" Level\BlockHandle=CopyMesh(Chair) ...etc [/code] Whilst it would be nice to just have Level\BlockHandle=CopyMesh(Mesh) regardless of the mesh type, but handles' values will change depending on memory resources etc. I dunno if the undocumented commands of Handle and Object are any good with this, but I don't recommend their use. |