Scripts / Transfering Value of A Global Variable Accross Levels

Author
Message
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 20th Aug 2019 20:20 Edited at: 20th Aug 2019 20:46
Hi all,

I am taking Wolf's advice and dipping my toe into the land of Lua. I think I need to create some global variables.

I managed to create g_seen_ghost and when the player gets close to a barrel and presses 'E' the value of the variable is displayed. Attached to another barrel is a script that adds 1 to g_seen_ghost if the player approaches and presses 'E'.

I tested it and the value did change as planned. In standalone the variable retained the updated value after save game/load game. However, if the game has a second level this number is not carried over to the next level. Is there a way to do this?

Barrel1 script:



And barrel2:



Using a different game engine and its visual scripting system I managed to create quite a nice little RPG by using binary switches and variables. That's what I intend to do here but I want multiple levels.
Julian - increasingly disillusioned and jaded
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 21st Aug 2019 09:51
OK, so I found another thread about this issue and edited my scripts thus:



And:



To my utter amazement (given my inept scripting) they somehow seem to work! My question now is, will this system work OK for carrying over all my global variables? Can anyone foresee any issues or see how to improve my scripts?

Many thanks.
Julian - increasingly disillusioned and jaded
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 21st Aug 2019 10:07
I just found an issue. Upon launching the standalone, the updated variable gets loaded straight away so it's as if the player has loaded a save point. How can I detect the game is being played from the start and not load the variables?

Also, could someone please tell me what n and w mean and what variables.txt is? It may look like I know what I'm doing but I just copy/pasted the save/load lines from Belidos' scripts.
Julian - increasingly disillusioned and jaded
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 21st Aug 2019 10:11
How about using the init part of the player marker script to reset all the variables? Or is that a bad idea?
Julian - increasingly disillusioned and jaded
PM
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 21st Aug 2019 10:28
The best way to handle it would be to create an auto-save function to save the game before loading the new level loads, then load it when the new level loads

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.
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 21st Aug 2019 11:02
Cool. Thanks, Belidos.

Now I have a new problem. The Winzone just reloads the first level instead of level2. In GG it clearly says it would jump to level 2. Most odd.
Julian - increasingly disillusioned and jaded
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 21st Aug 2019 11:14
I tried deleting the .dat files of both levels but the winzone still just reloads level1. Any ideas, please?
Julian - increasingly disillusioned and jaded
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Aug 2019 18:28
you don't need anything to be loaded in level 1 as it's always going to be a new start.
as the save and load feature will already take care of any loading you just need the checks (i.e. your manual reading of the file) to happen only at start of each new map so you can save the info at the end of the previous level as belidos suggests

variables.txt is just the name of the file, it can be anything but do try to keep the extension away from anything that might conflict with other programs and you will need to remember the name for later uses of course.

the different operations for lua file handling can be found here
but basically *n and *l are just how the file should be read - in this case a number followed by any text then move to the next line (though as there isn't any text it just moves to the next line).

if GG isn't loading the next level i can only guess it can't find the next level in your standalone files, make sure you load and save the maps in reverse before making your standalone
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 21st Aug 2019 19:08
Cool. Thanks, smallg. I think that also answers my next question: can I store all variables in one .txt file? From what you've said about moving down a line it seems I can. Please correct me if I misunderstood.
Julian - increasingly disillusioned and jaded
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Aug 2019 19:36
yep just remember the order you put them into the file will be the order you get them back out
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 22nd Aug 2019 09:17
OK. Thanks.
Julian - increasingly disillusioned and jaded
PM

Login to post a reply

Server time is: 2024-12-22 08:55:55
Your offset time is: 2024-12-22 08:55:55