Product Chat / @Lee, Idea for saving user tables in Save&Load

Author
Message
PartTimeCoder
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 16th Apr 2016 11:48
Lee, me again, dont worry not moaning about error checking lol, You mentioned in a recent Twitch video that if anyone had any ideas about saving table data then speak up.... well, a rather simple solution was staring me in the face all along but it didn't come to me till just now, I don't know if you have seen the database snippet I posted here, well, your already saving user variables with a prefix of 'g_', so how about having the save routine look for a single table 'g_UserData' and us script writers can use this global table to have our named table data saved with the save game mechanism using the json module to save out the table

it would need some way of keeping track of table name strings, I thought maybe pre/post fix the json strings with a stub "##JSON##START##tablename" and "##JSON##END##" then when reading the information back assign the tablename back to g_UserData[tablename] to reconstruct the users table........

g_UserData={} -- defined in global.lua
g_UserData["mytablename"]={}-- defined in user script

as far as ideas go its about all I got, but I'm pretty sure it can work without adding *much* overhead, depends on the overall size of g_UserData I guess

What do you think?
PM
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 18th Apr 2016 10:49
Yes, that would definitely work, and would enable third party scripters to choose to use g_UserData with the knowledge their arrays are being preserved. I was hoping for some clever LUA trick which could 'grab' an existing array and dump it out, but I guess they had to draw the line somewhere. I'll let this concept evolve in the forums a while, and at some point we can add it to the voting board with some clarity and see if users vote for it.
PC SPECS: Windows 8.1 Pro 64-bit, Intel Core i7-5930K (PASSMARK:13645), NVIDIA Geforce GTX 980 GPU (PASSMARK:9762) , 32GB RAM

cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 18th Apr 2016 11:21
I've got the tables out and back now as part of custom changes to the new save/load. Can ping it over if it helps.

Cheers.
PartTimeCoder
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 18th Apr 2016 15:11
did you use the json method?, if not I'd be curious to see how you went about it

Lee, yea for all Lua's punch saving table data is something that seemed to get bypassed, guess thats why there's so many other methods, the clever Lua trick here is to save it as json lol, you could recurse the entire _G table and grab table data, but thats going to mean a heafty nested for-do loop is needed and still needs json,I can see that creating a bottle neck and all it would really achieve is dropping the requirement for the use of g_UserData, but at quite a cost

I have also implemented this locally using my exact idea above but one or 2 things I'm not happy with and the code is a mess so I'm not ready to share it yet but it seems this will be taken care of by the community anyway so maybe no need for the voting board, just send it to the beta testers lol
PM
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 18th Apr 2016 17:01
I did think about adding a 'custom save/load script' which normally lies empty, but would allow a user to add their own save lines to the save process, thus specifying exactly what it is they want to save, including the nested array data as required. Problem is that most users might not know what to add there, as it is entirely dependent on scripts they may not have initially written. It's a sticky point and pulls one into the horribly icky world of coding, which is one of the reasons GameGuru was created, to avoid going into this messy stuff
PC SPECS: Windows 8.1 Pro 64-bit, Intel Core i7-5930K (PASSMARK:13645), NVIDIA Geforce GTX 980 GPU (PASSMARK:9762) , 32GB RAM

cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 18th Apr 2016 18:35
There are some 'simple' methods for lua table serialisation and reload. Had no need for json format for these purposes and it handles table nesting ok for the size of tables would likely get in GG. Seems fine, could even populate the g_entity tables if needed. The one aspect that needs careful handling is sprites. I've had to write wrapped functions to manage sprites so that they can be refreshed and positioned where they need to be on reload. The other aspect which can cause issues is if collision mode is changed from starting position by script (eg doors) as entity collision mode isn't saved/reloaded so starting collision mode is reapplied after reload. Anyway back to tables, the code could easily be restricted to just saving and reloading a g_user table if needed. I just let it do all tables but can see how that might cause support issues. Cheers.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 18th Apr 2016 21:56
Load images just in "init" section as mandatory is not so friendly, would be nice being able to load image>create spritte when needed, I meant in the section of code you want, and not just in "init" part.

I've to create some workaround to load non-existing images in "init", since those images will be create in game, so how to load them in "Init", if them does not existe yet. (working in inventory).

arrays, tables, in fact are the same in LUA, and later or sooner will becames handy for work with save/load, I think there should be the "easy save/game" and the option to play with code.

3com
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

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Apr 2016 23:06
you can load and create sprites/images any when just be sure to check they dont already exist (or are only created once) as otherwise you will end up with a crash.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-11-25 03:56:40
Your offset time is: 2024-11-25 03:56:40