Examples please if poss

Blitz3D Forums/Blitz3D Programming/Examples please if poss

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Level saves are pretty straightforward. Assuming you have enverything positioned per levle in you game, you can save it to file with a function
Function save_to_file(indx%)
	; Outputs object data
	; opens files for indx% level
	f$="level"+indx%+".dat"
	file=WriteFile(f$)

	; output all 100 actors
	For Every Object
		; Output details
		WriteInt (file,Object type)
		WriteFloat (file,Object's X position)
		WriteFloat (file,Object's Y position)
		WriteFloat (file,Object's Z position)
		WriteFloat (file,Object's X rotation)
		WriteFloat (file,Object's Y rotation)
		WriteFloat (file,Object's Z rotation)
		Write Any other Pertinent Details such as Camera position, rotation
	CloseFile(file)
End Function

Then you create a read function that reads in the data in the same order you saved it...
Function load_from_file(indx%)
	;loads data into the setup arrays
	;reads files for level n%
	f$="actors"+indx+".dat"
	file=ReadFile(f$)

	; input all 100 objects
	For Every Object
		; Input details
		n=ReadInt (file)
		Object Type = n
		n=ReadFloat (file)
		Object X position = n
		n=ReadFloat (file)
		Object Y position = n
		n=ReadFloat (file)
		Object Z position = n
		...etc...
		...etc
	CloseFile(file)
End Function

In your game when you want to swtich levels, delete all the old objects, load in the details of the new objects and create tham as you did to begin with. In my case I have an array to store object details and object creation functions. I load the data from file into the array, and then go through the array creating objects. When I close a level I go through the array and delete all the objects, load the next lot of data, and create the new scene.

If you want dynamically altered scenes you can do the same, just keeping a copy of the original level data in one place and a copy with any modifications in the player's save directory.