02-15-2023, 06:35 PM
(02-15-2023, 02:48 PM)40wattstudio Wrote:Quote:In my opinion a game would need to be designed from the onset with saved game states in mind.
Totally agree! That's why I'm asking about this way ahead of time. I couldn't imagine trying to integrate a save system into a game after the fact. That would be a nightmare for sure.
Using a global User Defined Type would definitely work and would even be efficient if there were no more than a couple hundred variables . . . but a future project I have in mind is a "persistent world" game with potentially hundreds of NPC's, each with possibly dozens of variables being tracked. Not to mention location information, quest information, etc, etc. I would expect the variable count to be easily in the thousands.
So far my only experience with saving data in QB64 is with using commands like OPEN, CLOSE, WRITE, FOR BINARY, etc.
That still would be fairly manageable. Your NPCs could be held in an array with a common UDT:
TYPE NPC
variable...
variable...
etc..
END TYPE
REDIM NPC(0) as NPC ' increase size as needed when adding NPCs
If would then be a simple matter of saving the state of each NPC:
Handle = 0
DO
SaveNPCStates NPC(Handle) ' save the state of NPC to drive
Handle = Handle + 1
LOOP UNTIL Handle > UBOUND(NPC)
SavePlayerState Player ' save the state of the player
SaveGameState GameState ' save the game's global variables
Just an idea off the top of my head.