Product Chat / Just a tip for people that use save/load in their game

Author
Message
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 6th Dec 2020 09:30 Edited at: 6th Dec 2020 09:37
Just a tip for people that use save/load in their game:

If you want to save variables, don't make them local. If you do this, gameguru will not save them even if you put the g_.

So as an example: local g_player_money = 0

if you do this. when the player save/loads. Player money will not be saved. Remove the local from any variables you want to save.

If you have 6 scripts that kinda do the same thing and used locals to save time. You might want to make sure that those locals are not something you want saved.

For me, I used locals to hold when player places/builds objects in my game. Had to go back to each object script and remove the locals and make their own variables. g_object_spawned_1 = 0, g_object_spawned_2 = 0 etc
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 12th Dec 2020 05:33
Makes sense -- but not a happy sense.

g_ stands for global... but (if 100% true), this is some disheartening
information. Probably 70-80% of a good development technique
game's scripted variables will be local.
It needs a whole new and improved do over.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Dec 2020 09:14
Quote: "Makes sense -- but not a happy sense.

g_ stands for global... but (if 100% true), this is some disheartening
information. Probably 70-80% of a good development technique
game's scripted variables will be local.
It needs a whole new and improved do over."

nah it makes sense, you can't have locals cos what happens if you have 2 with the same name? how will it know which script's value to restore?
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Dec 2020 13:06
The whole point of local variables is that they can't be accessed from outside the script they are in. It means that you can write your script and be sure you are not unwittingly overwriting a variable in another script.

If you really need to save values then create a unique global variable name, g_<script name>_<variable name> for example, and copy your local variable to it at appropriate points (like when it changes). GG will then save and load it for you.

As part of your scripts _init processing simply look to see if the global variable already exists and if it does initialise your local variable from it.

Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 12th Dec 2020 16:45
Yes. Sounds like a good point and good technique to save them--
But maybe locals aren't typically as often saved as the globals anyhow?
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 26th Dec 2020 12:44
Typically global is an array/table indexed with the entity id, so each entity just can access its value.
Global is a necessarily bad thing.
Local has no issue naming the same, anyway adding the script name as suffix as Amen pointed above, is a good practice.
In fact, I think the engine should do it internally to know which var belongs to which script.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM

Login to post a reply

Server time is: 2024-04-24 12:51:14
Your offset time is: 2024-04-24 12:51:14