Scripts / Collectable picture puzzle (store variables between levels)

Author
Message
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 20th Jan 2020 21:49
I would like to implement a collectable into my game; a picture that can gradually be assembled by collecting all 16 pieces throughout the game. As the player collects a new piece, they are rewarded by a glimpse of the picture so far with their most recent piece added to it. Some players may only collect one or two of the pieces, some persistent ones will work hard to collect all 16 littered throughout the game.

I've made a quick mockup using After Effects of what the effect should look like...


As this mechanic would span multiple levels of the game, I need a way to track which of the pieces has been collected, and then tie that to some sprite commands to show only the pieces collected so far when a new piece is collected. I figure I will need to use commands like io.open and read and write the information to the table of variables, but that's beyond my level of LUA expertise. I even hypothesise that table/txt file/whatever it is that stores the information will look something like this:



...where the first number is the number of the piece and the second is either 1 or 0 based on if the player has collected it or not.

As a started for ten, I have written a basic script to govern the actual picking up of the pieces (demonstrated in the video above).



I'm now at the stage where I need to start adding to it but my first steps into using io.open have not proven fruitful. Basically I'm way out of my depth here, can someone here help me achieve this?

AE
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 21st Jan 2020 11:01
I have called the images 000.png up to 015.png, it is much easier to load the images through a loop.

I started from a 1024x1024 image and divided it into 16 equal pieces (256x256). Help to place the puzzle pieces on the screen.

The numbers (ids) of my objects range from 1 to 16, consecutive ids help to work with them in a loop.
Otherwise you must rewrite the script.

I suppose you want to place all 16 objects in different places in the game, but I don't know how many levels your game will have, and how many objects you want to place per level.

I have not tried the map as standalone yet.
A drawback that could be experienced could be the global variables not retaining their value between levels. In addition you should add the prefix (g_) to the global variables.

If this is the case we will try to solve it, in case it is not possible, then we will resort to generating a text file as you mentioned before.

Anyway this is a good starting point.





Attach script to each object you has to collect in order to get corresponding puzzle pieces on screen.

I ignore whether you want to show the whole image once, or whenever the player want to.
You should keep in mind that when you hide an object it is still active, and therefore continues to execute the attached script. When the object is destroyed, the attached script stops executing.

If you convert the object to "AlwaysActive = 1" then the player will be able to access the full image whenever he wants, otherwise he will only be able to access when the player is within his range of action. This may be relevant if, for example, you intend to use the complete image as a clue to find something, for example a hidden key.
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
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Jan 2020 18:24
a loop for the placement would have been much quicker
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 21st Jan 2020 22:09
@3Com, thanks for trying but that script made my head explode like a little lemming Think I need more tutoring in the ways of LUA. In any case, a script that only runs on one level is no good to me, I need to be able to track which specific pieces have been collected. Your version also assumes the player collects them all in order, which they might not.

I've struggled again tonight, trying different combination of commands. This is how far I've got...



I then have a barrel running this little script to test reading variables.



This at least reads the globals I created, though I'm not convinced it's actually reading them from "variables.txt" and not just the other script. In any case, popping these in a 2 level standalone isn't working; on loading level 2, I get an error about trying concatenate g_map02, and the value of g_map01 returns to zero. I think this might be because in the init, I ask it to write to "variables.txt".

Staring into this murky water continues...

AE
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 21st Jan 2020 23:03
When you write to the file you need to write the state of all pieces, ditto when reading.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Jan 2020 00:06 Edited at: 22nd Jan 2020 00:06
Quote: "Your version also assumes the player collects them all in order"

it shouldn't, it has a check for if the piece is collected or not and sets a value to 1 if so, if the piece is collected it is shown, if not it is skipped.

this bit should probably not be in quotations in your mappiece_init(e)
mapfile:write("g_map01 \n")
mapfile:write("g_map02 \n")
but yes for the loading of the map you don't want to be writing to the file, only reading from it... you write to it when the game is exited

if you want to check the 2nd script is prompting the file values change the variables there
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 22nd Jan 2020 01:06
Quote: "thanks for trying"

You are welcome.
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
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 22nd Jan 2020 23:04
Minor progress.
I have now successfully been able to write a single variable to a txt file in LUA. Yes, we really are at that level. For future archaeologists reading this thread, wondering how LUA works, the files you create and call using file IO commands are created in the "Files" folder, not "scriptbank" as I was expecting.

The following script half works. It successfully writes two numbers into "mappuzzle.txt" and stores them so they can be read in the next level. The problem is, while it updates the first number when I pick up map01, it doesn't do anything when I pick up map02. It doesn't seem to recognise anything to do with map02, let alone change the variable associated with it.



In that example, I used mapfile:write(g_map01.."\n"..g_map02.."\n") to give me a file that looks like this:



But I could just as easily have put mapfile:write(g_map01..","..g_map02.."\n") to get a file that reads:


The barrel meanwhile is running this, as I experiment with reading individual lines:



Brain hurts now...

AE
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 23rd Jan 2020 19:03 Edited at: 23rd Jan 2020 19:07
Quote: "the files you create and call using file IO commands are created in the "Files" folder, not "scriptbank" as I was expecting."

yes, same as when you load an image etc you normally see the path as "scriptbank\\images\\...." because the default root is from "files"

script looks ok, are you sure you named the object in GG's property panel map02?
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 23rd Jan 2020 19:42
yep

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 23rd Jan 2020 20:03 Edited at: 23rd Jan 2020 20:04
could be the file is being accessed too often? you currently having it in the loop which means it'll be opened every frame, you really want it to only write when the value is changed
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: 23rd Jan 2020 20:30 Edited at: 23rd Jan 2020 20:31
This might help.

*** not a working script btw, just showing a way of doing it ***
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 23rd Jan 2020 22:21 Edited at: 23rd Jan 2020 22:23
More minor progress.
Lots of trial and error later, this seems to be working better, but still not perfectly. Ended up stripping out the write function in init and that seems to have helped. Tried moving the g_map01 == nil etc. to init but that caused errors. I've made a simple 2-level test game; map01 and map02 are collectable in level 1, map03 is in level 2. The script successfully stores the values of map01 and map02 into level 2, but when I pick up map03, it resets map01 and map02 to zero for some reason. I thought it might be that the file needs to be read during init every time a new level loads to bring the values across, but it doesn't seem to matter.

Here's a video showing what I mean:



And here's the script:



It occurs to me as I write this that I probably need to specify g_map01 as a value that can be read from "mappuzzle.txt" but how do I specify which line/string pertains to which variable? A command that basically says:
g_map01 = mapfile:read(line 1)
g_map02 = mapfile:read(line 2)

Similarly, a command that says mapfile:write (line 3) would be most helpful.

Don't even go there with reading these variables back, that's a whole other can of worms I've kicked down the road for tonight...

AE
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 23rd Jan 2020 23:58 Edited at: 24th Jan 2020 00:00
because your second map doesn't have the script to read the file from level 1 to grab those value so they are nil and thus reset to 0 when saving the next variable.

if you keep the lines in sequence with the map piece you can for loop to the correct spot (if you need more than 9 pieces just increase the for loop counts



so to use the functions you do say
g_map03 = read_from_line(3)
or
write_to_line(2,g_map02)
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: 24th Jan 2020 13:11 Edited at: 24th Jan 2020 14:45


This is a better method!

May need a few tweaks but should be enough to work with for now.

I've checked it works with save/load but not between levels although it should work in principle.
The fe_collect script is simply there to test it works and it uses the 'strength' parameter to denote the 'piece' number, i.e. in this case 1 to 10.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 24th Jan 2020 19:23
Once again, Amen, you had proven to be my savour! Can't say I fully understand everything your scripts are doing but I appreciate the elegance of them all the same. Time to start modifying them to my needs!

Quote: "I've checked it works with save/load but not between levels although it should work in principle."


Yes I noticed that too. Made a 3-level demo, saved on level 2 having collected 1,3,5 and 6, went to level 3 and collected 7 and 8, then loaded my save and 1,3,5,6 were correctly counted, then advanced to level 3 again and it reset the count to zero.

AE
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jan 2020 20:18 Edited at: 24th Jan 2020 20:21


Here it is with sprite handling added.

It is using LMB to display the image but that's something that is easy enough to change.

Put the sprites in a list with x, y, xsize, and ysize specified on an individual basis so it can be used with odd shaped images as well, just change the values to suit the images.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jan 2020 20:24 Edited at: 24th Jan 2020 21:44
You may need to write over the file when loading a save or delete the file on a new game.

Just realised this isn't as easy as I make it sound, you can't do it in a script attached to an entity because they get loaded after all the menu stuff is done so it will require some small changes to the titlesbank scripts. Or I suppose the changes could go in global.lua. Let me know if you need help with this.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jan 2020 21:13
I've just realised that I've never made a multi level game or demo in GG, not sure I even know how to!
Been there, done that, got all the T-Shirts!
PM
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 24th Jan 2020 21:49 Edited at: 24th Jan 2020 21:52
Quote: "I've just realised that I've never made a multi level game or demo in GG, not sure I even know how to!"


Every day is a school day, as I am constantly reminded every time we talk!

Plop down a winzone, left-click > properties > in the IfUsed field, write the name of the fpm you want to load next (you don't need to write .fpm on the end, just "mysecondawesomelevel" will do).

AE
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 24th Jan 2020 23:02 Edited at: 24th Jan 2020 23:03
Quote: "You may need to write over the file when loading a save or delete the file on a new game.

Just realised this isn't as easy as I make it sound, you can't do it in a script attached to an entity because they get loaded after all the menu stuff is done so it will require some small changes to the titlesbank scripts. Or I suppose the changes could go in global.lua. Let me know if you need help with this."

yes i think the best way is to have some value saved as an index when you start a new game that appends to the file name so you know which file to save to / load from when swapping levels (this index and the other values will automatically get read on save / load so the right file should always be used)
i'm not sure if there is an easy way to get such an index, perhaps the current time and date (i believe lua can return that?) or simply storing another file with an ever increasing value each time new game is pressed.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 24th Jan 2020 23:40
Mildly tweaked the script to get the 16 images I was after, see attached, and made a little zip of 16 test images, see also attached.



Again, thank you both for helping me - I owe you each a drink!

AE

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Jan 2020 08:06
Btw, I notice you've used -1 in the sprite sizes, this will probably mean that at other screen resolutions you will have gaps in the image or overlapping pieces.
Been there, done that, got all the T-Shirts!
PM
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 25th Jan 2020 09:50


Good spot. I thought I was being clever, but as usual...

Quote: "it will require some small changes to the titlesbank scripts. Or I suppose the changes could go in global.lua. Let me know if you need help with this."


Yes I will need help with that, please.

AE

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Jan 2020 10:53
I'm working on it right now. Sure is tricky trying to work out where to put the code to detect when it's a new game as opposed to just returning to the first level though!
Been there, done that, got all the T-Shirts!
PM
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 25th Jan 2020 10:59
Re. the overlapping: what about a 'screen width modifier'?

swm = (screen width / screen height) / 1.78
swm = (1920 / 1080 = 1.78) / 1.78 = 1
swm = (1650 / 1050 = 1.57) / 1.78 = 0.88

Then in the positioning for each sprite, you say for example x = 20*swm

which at 1920 x 1080 will = 20, or at 1650 x 1050 will = 17.6

This would allow me to continue to keep those pieces square.

AE
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Jan 2020 11:53 Edited at: 25th Jan 2020 11:54
The image will then take up more of the screen on some modes than in others, if that isn't a problem then go for it.

I've cracked the levels/loading/new game issue.

Put title.lua in the titlesbank/default (assuming you haven't got a custom one).

Oh, and you'll have to redo your changes.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Jan 2020 20:52
Slight tweaks in this version, if you leave the image displayed and then pick up another piece the image will be updated.

Other than that I've added comments to the bit that detects the level change and tidied a few other bits.

You can delete the Prompt parts when it is all working for you.

The file still contains the level btw but it is no longer used, thought I'd leave that bit in for an aid to debugging so you can see which level the file was last saved from if anything goes wrong.

This same method could be used for any collectables in a game btw, in fact it could be easily extended to be a named list of collectables each with its own g_<name>Values list written to the file.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 25th Jan 2020 23:32
Quote: "This same method could be used for any collectables in a game btw, in fact it could be easily extended to be a named list of collectables each with its own g_<name>Values list written to the file."

nice job, this would be well worth studying for those that want multi-level inventory's or basically any multi-level dependent scripts
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: 26th Jan 2020 00:15
I learned quite a lot about GG from this, for example I hadn't realised until now that a level change results in a completely fresh Lua environment, i.e. even things like global.lua are loaded from a fresh start.

They aren't really 'levels' as such but completely separate games.

Also I learned that the 'name it g_ and it will get saved' rule only applies to simple variables, i.e. strings and numbers. Lists will not be saved!

What we could really do with is a separate Lua environment that is retained between levels, in which would be stored things like player health and weapon stats, would make stuff a lot easier to implement and would also improve performance as GG wouldn't need to keep reloading the same scripts over and over again (i.e. the 'persistent' environment would be where the libraries would reside, there must be quite some overhead in reloading utillib or physlib when switching levels!).
Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 26th Jan 2020 01:38
https://github.com/TheGameCreators/GameGuruRepo/issues/613
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
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 26th Jan 2020 04:17
Great work people. Will indeed be useful info. I thought I heard this
refreshing of each level was quite recently-- if not in fact back in December?

Also... Plus 1+ or 2+ or 3+ up on that one AmenMoses @ contain and retain--!
Been wondering why the g_thingamajig was pronounced as so important??
Don't name your global variables g_ and they won't get saved?! What?

I have dozens of large scripts, particularly recently have I been messing
around (but for a serious project) with a combination of local and global
variables. Would be a hassle if I had to go back through each one and find
all the global to replace with g_ g_ g_ goobers!!

Seems also that lately GG lua environment has been very very picky when
getting global to local assigned and accepted past nil by the test engine...
hate to see what happens come stand- alone!!!!!!! Ergh.
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 26th Jan 2020 04:25
@ 3com -- good job! Nice work. Very helpful.
64 bit, 64 bit, 64 bit, let's go! Would I imagine
make most of the headaches easier to rectify.
Space to breath... open skies...

BTW, I'd call it a BUG, not an enhancement for sure!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 26th Jan 2020 06:07
It is important that global variables retain their value between levels, especially when it comes to standalone game, without the need to resort to shortcuts such as a text file to be able to read from it later. And this should be implemented in the game engine.

@ GubbyBlips
Ty mate.

Quote: " Would be a hassle if I had to go back through each one and find
all the global to replace with g_ g_ g_ goobers!!"
[quote=][/quote]

In a script written with a certain discipline, respecting the rules, it contains in its header all the declared global ones, such as:
var = 0
var1 = 10
local var3 = 12

All that word preceded by the sign "=" and a value below is a variable, and every variable not preceded by the word "local" is global.
Which would make it easy to open all the scripts you want to use in your game, read the global variables and add the prefix "g_".
g_var = 0
g_var1 = 10

The variables would be everything written between the beginning of the script and the word "function", obviously this would not always be the case for the scripts customized, but the vast majority of stock ones meet this standard. I think that creating a backup of these scripts and testing would be a good start.

This is not exactly about this, but it could help: https://forum.game-guru.com/thread/221038

Important: This thread is not exactly about this, so I prefer not to go deeper into this matter.

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
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 26th Jan 2020 15:16
No it has always been that way, only since save and load was updated did anything change as far as lua variables are concerned... Though I'm pretty sure there was a user submission to fix the lists not being included, did Lee accidentally remove it? I very rarely do anything involving standalones so not sure.

For simplicity I think it's better to destroy everything unless told otherwise in the script or just having the same system as the save and load between levels would be fine.. or just implement amen's code (or a version of it that combines both) in the core.
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: 26th Jan 2020 15:25 Edited at: 26th Jan 2020 16:23
It may save simple array style lists, I haven't tested that. I doubt it would handle anything complex though.

*** Edited to add: Yep, as I thought, only saves really simple lists, i.e. contiguous lists of numbers or strings.

Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 26th Jan 2020 17:29

"This thread isn't about this..." Uhh? kindof right mate. But it seems like
it needs to be discussed somewhere, and it's bending toward that already.
It's essentially about saving globals specifically because of the constraints
that compile to standalone does not compile as necessary (not always).
And as discovered, new levels are a full memory reset it seems-- so certainly
more critical now isn't it?

"there was a user submission to fix the lists not being included,"
list of variables? GG had this once?

I (we) would like the hear from a developer about their knowledge and opinion
regarding this concern. All good suggestions @ above.

Imagine....
It would be nice if as AmenMoses proposes, there is the global.lua
then in some other folder (user) for example there is user_globals.lua
that you can supply --- and is read per compile @engine specific meaning
that the engine reads that file, and you don't have to worry about it the compile
glossing over your custom script globals (or any variable) because of some
certain hard to detect hick-up...

Speaking of niceties, it would be even more kind and gracious if GG "gathered"
all the globals in all the scripts that a user has linked to their levels, and created
this list file on it's own!! Wow, that would be sweet!
I don't see why this is difficult test runs do it-- not sure about multi level test runs.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 26th Jan 2020 18:42
Um, that is not what I proposed at all!

I'm suggesting a separate persistant Lua environment that would not be reset on a level change, it would certainly not be for users to muck around with!

Been there, done that, got all the T-Shirts!
PM
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 26th Jan 2020 20:34
I have no issue with the discussion evolving into a broader one about LUA environments and globals, it benefits us all at the end of the day. Like Amen said, stuff like this would be vital for inventory systems etc.. Whilst that's not something I'm too worried about for my current game, I know plenty of users want to implement systems like this in their games.

In other news, my minor modifications to the script now mean the sprites stay in the right position regardless of aspect ratio. Took a while to wrap my (admittedly hungover) brain around the maths, but at least it was a problem I could solve whilst sat down



I also made some adjustments so the sprites automatically show when the player picks up a scroll, rather than relying on a mouseclick (I need that input for other stuff).

Now I'm going to be a pain. Amen, is there a way you can delay the showing of the most recently picked-up piece/sprite? I want to try and get something as close to the video in my original post as possible. This means that collected pieces should fade in, then the newly collected piece should fade in separately, maybe even resize like in my mock-up video. I've done sprites fading in and out before, I'm just not entirely sure where to put the code. Plus I need your expertise to differentiate already collected sprites from newly collected ones.

Tweaked script attached.

AE

Attachments

Login to view attachments
JC LEON
13
Years of Service
User Offline
Joined: 22nd Apr 2010
Location:
Posted: 26th Jan 2020 20:58
Quote: "nice job, this would be well worth studying for those that want multi-level inventory's or basically any multi-level dependent scripts "


SO some possiblities for a new revamp of the inventory system that work between levels?
PC 2 Specs:
AMD RYZEN 2600 SIX CORE @3,70, 64GB RAM DDR4 2400, M/B GIGABYTE AX370
SVGA NVDIA 1660GTX 6GB , SSD M.2 TRANSCEND S110 1TB, 1X HDD SEAGATE BARRACUDA 4TB, 1X HDD TOSHIBA 2TB


PC 2 Specs:
AMD QUADCORE 880K @4.5GHZ, 32GB RAM DDR3 1600, M/B ASUS A88XM-PLUS
SVGA RADEON R9 380 4GB , SSD KINGSTON A400 1TB, 2X HHD SEAGATE BARRACUDA 4TB
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 26th Jan 2020 23:01 Edited at: 26th Jan 2020 23:05


Something like that you mean?

Looks like the math needs a bit more work btw, not sure why the sprites are being displayed the right size when scaling up in the first place but then smaller on redisplay after switching levels, I'm using a 2K display.

Aha, figured out why.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 26th Jan 2020 23:16
Give this a go.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 26th Jan 2020 23:41
@ AmenMoses-- Remarkable! cha-ching!

The suggestion would be that there is a user global file that is customized just
for the user, and the main global is not touched, so we keep them separate,
but GG engine reads both of them, and even better still creates a file of the user
globals-- ALL *user* variables that is referenced anytime, anywhere something
like that. Functions kinda like the script you are working on in this thread.
Of course a persistent Lua environment would probably be faster than a file?

Developers?
PM
Ratall
15
Years of Service
User Offline
Joined: 29th Jun 2008
Location: Not Here
Posted: 27th Jan 2020 01:06
This may not be the appropriate thread to cover this but I think it is relevant.

If you are looking the save complex structures you need to walk the structure. That requires using recursive routine. If you look in gamedata.lua under titlesbank you will see an example of this in the save function.



Essentially the code walks through the structure assembling the name (path if you will ) that points to the underlying data. The name and the data must be then saved to a file so the data can be recreated in the correct place when loaded.
When the routine reaches an actual piece of simple data the name(path in the structure), type of data (numeric or string) and of course the data its self as a string are save to the file. The routine then collapses up the structure and continues checking that level for more underlying structure or data this process is repeated until the whole structure is saved.
The easiest way to understand this routine is to dry run it on a whiteboard(doing it on paper ends up with a lot of crossing out and general confusion)

One of the biggest problems with using the g_ prefix is there are a number of variables with that prefix within GG that should not included with in a save game let alone between levels most of the code in gamedata.lua is filtering out that which should not be saved.


I would suggest using a structure under something like g_savebetweenlevels the g_ prefix will ensure the data is included in the savegames. the rest makes it possible to simply save the data between levels by saving the structure under g_savebetweenlevels using a version of the save function above.

The advantages of that approach is
1) your data is automatically included in the save games in the levels.
2) once you have set up the save and restore routines you do not have to touch them if you add more data under g_savebetweenlevels
3) if you wish get rid of your inter-level data just delete the g_savebetweenlevels structure.

ps you don't have to call it g_savebetweenlevels that is just a suggestion anything unique under g_ will do.

Sorry the exclamation is not very good but recursive routines are harder to explain than write and are a pig to write. Unfortunately some times they are the only way. I did not cover the load as that is relatively simple.

Forgive me if I made any errors but it was back in 2016 when I wrote it and I haven't looked at closely since.
“Everything should be made as simple as possible, but not simpler.”
Albert Einstein


"Ye count your selfe wele lettred , your lernyng is starke nought."
Anon
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 27th Jan 2020 09:21
Basically a recursive routine is a routine that calls itself.
Are there another cool alternatives such as Tail Calls there is a maze game as example, at the bottom.
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
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 27th Jan 2020 21:34
Added a frame, and some fading to the newpiece. Would be nice if the frame and collected pieces faded in, then the new piece, but that's really nit-picking now. I'm happy to move on.



By all means, continue the discussion about globals though - it's an interesting read even for someone like me that doesn't 100% understand all what's being said

AE
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 30th Jan 2020 20:53
""By all means, continue the discussion about globals though -""
er, aw ighty then

The global earth is flat, or the global earth is round (?!)
If you swing the bat, and the ball goes...ka-splat -x-__..
Maybe it's a tomato that you actually found(?!)
You can use a global to make a global sound(?!)
Globals do what globals do, I want a global, how bout you(?!)

MZMZMZMZMZMZMZMZMZMMZMZMZMZMZMZMZMZMZM

I think the discussion should NOT disclude other variables.
Local variable lives matter too, not just globals.
Let's hope we can save them all!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 8th Apr 2020 14:58
Bumping this.
This is what I was looking for -- ignore the bizarre post above this one.
Who's that GuBl guy?

--- Will be wanting to discuss this further because it's probably one of the most
important aspects of a commercial game. Not being able to save your game
does not bode well with users... Pretty big undertaking for sure.
PM

Login to post a reply

Server time is: 2024-04-18 18:56:06
Your offset time is: 2024-04-18 18:56:06