Scripts / Save function aint saving custom counters

Author
Message
Medmatheus
Reviewed GameGuru on Steam
8
Years of Service
User Offline
Joined: 18th Oct 2015
Location:
Posted: 6th Feb 2018 10:08
Hi guys,

when I save my game in the middle or almost in the end of a level, when I load it back, some counters doesnt load as well.

For example: I collected an item that allows me to win that level, but if I save, quit and load back, that item just count as zero and I cant finish. The entity also disappear because I already looted it.

is there a solution for this?

thx
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 6th Feb 2018 12:28 Edited at: 6th Feb 2018 12:35
Hmn, load/save should save any variables you use, as long as they are declared as global, by adding g_ in front of them.

So if the variable you have used to create your win scenario is for example WingGame then it would actually need to be g_WinGame, you would have to change all instance if WinGame in all scripts to g_WinGame. It should then save when the save/load system is used.

If you want your own variables so they carry over levels however, gameguru doesn't do this by default, however I did some work on creating a system that saves all your variables to an external file, then reads them again when entering the next level, maybe you could take a look at that and adapt it to what you need, i'll try to answer any questions you have, but i can't guarantee any answers because it was a long time ago that i did it and i have long term memory issues.

https://forum.game-guru.com/thread/217844#msg2577027

Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 6th Feb 2018 18:39
Quote: "Hmn, load/save should save any variables you use, as long as they are declared as global, by adding g_ in front of them."


so that's how its done! Thanks
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
Medmatheus
Reviewed GameGuru on Steam
8
Years of Service
User Offline
Joined: 18th Oct 2015
Location:
Posted: 6th Feb 2018 20:40
Hey Belidos and Teabone, thanks for the awnsers.

I tried to place a variable with g_ before on global, but it didnt save from level to level and sometimes it bugs some of my levels. I'm trying to avoid to change default gg script files.

going to check your script later, storing variables in another file seems to be what I need, thanks
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Feb 2018 20:52 Edited at: 6th Feb 2018 20:58
You don't put the variable in global.lua just name it g_<whatever>!

Edited to add:

The best way of doing this is to create your own global table and put all your variables in it, e.g:

g_mytable = {}

g_mytable.myvar1 = 4
g_mytable.myvar2 = 'Hello World'

etc
Been there, done that, got all the T-Shirts!
PM
Medmatheus
Reviewed GameGuru on Steam
8
Years of Service
User Offline
Joined: 18th Oct 2015
Location:
Posted: 7th Feb 2018 10:33
AmenMoses,

So i need a script to store the variables and another to call?

let's say i have a "supply" variable, I have to create a i.e. global2.lua, place g_Supply there, but how do I call or load it? Can you give me a code for this example?
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 7th Feb 2018 11:27 Edited at: 7th Feb 2018 11:29
There are scripts with an explanation of how to use them in the link i gave you that do exactly that.

You don't touch or edit the global.lua script, you use g_nameofvariable in your scripts.

Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
Medmatheus
Reviewed GameGuru on Steam
8
Years of Service
User Offline
Joined: 18th Oct 2015
Location:
Posted: 7th Feb 2018 14:51
My bad Belidos, just downloaded your save/load var scripts, and guess it's clear now.

The own script creates a file named "variables.txt" during the game. the g_ variable is also created if it's nill.

Guess I can understandi it now. Going to have a try after work.

Thanks!
Medmatheus
Reviewed GameGuru on Steam
8
Years of Service
User Offline
Joined: 18th Oct 2015
Location:
Posted: 7th Feb 2018 21:10 Edited at: 7th Feb 2018 21:12
Ok, now it's working, I can save the number of supplies the player loot during his game.

Heres the code I'm using to save each supply player get, so he wont have to worry about saving:



I already set an auto-loading everytime player start a level. So, if player stops in a middle of a level, save his game, when he open it again, all his counters going to be restored:



not sure if that's the easiest way, but thats how I did. Hope it helps someone

Login to post a reply

Server time is: 2024-03-29 12:09:17
Your offset time is: 2024-03-29 12:09:17