Scripts / Simple Database

Author
Message
PartTimeCoder
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 27th Mar 2016 13:22 Edited at: 7th Apr 2016 17:33
I found myself in need of a mini database to store structured ingame session data so I came up with this

the beauty of Lua, these seemingly simple 4 functions, nothing more than table wrappers, actually offer a pretty powerful database system, Lua tables rock, I had almost forgotten how much I love working with this language

Edit: 7/4/2016

I have revised this script and included the ability to save a database to disk and reload it using json, so your games can now have persistent data, I have also created a function table for the script, its just how I like to format groups of functions in Lua scripts

the core: database functions and JSON include


and a full example


and thats it, nothing that cant be done in script with tables anyway, this just makes it a lot more coherent and user friendly

the script and the JSON module are both attached

Attachments

Login to view attachments
PM
MChapman
8
Years of Service
User Offline
Joined: 19th May 2015
Location: USA
Posted: 30th Mar 2016 23:30
So if i'm right we can make two very helpful things with this.
1. Inventory systems
2. Stat systems - strength, defence, etc..

Markchapman10 is my Skype let's have some dev talk.
Kesstryl
8
Years of Service
User Offline
Joined: 29th Jul 2015
Playing:
Posted: 6th Apr 2016 20:17
This is incredible!
PM
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 7th Apr 2016 01:52
That looks very useful. Thanks.

With the new save load feature coming out, we dont have a way to snap shot table information yet. Just global variables that have a prefix of g_YourVarName = 0

But perhaps you may have a work around for this in mind.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

PartTimeCoder
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 7th Apr 2016 16:20 Edited at: 7th Apr 2016 16:50
Quote: "But perhaps you may have a work around for this in mind."


Yes, I'm attempting a json table dump and save it out with io.write, I got the json table written to disk with no problems but got a format error when trying to reload it, I used the first json script in the very long list of json scripts at LuaForge and have not tried again yet (Easter half term zapping my time lol), I will have another crack over the weekend as I need this myself

Edit:

Actually, I just checked it and it does work, it was creating the file locally but not writing data to it, I moved the file out to AppData and its working as it should, I guess the game runtime does not have admin privileges, I'll get the code cleaned up tonight and added to this thread, this is now actully very handy indeed!

PM
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 7th Apr 2016 17:11
Great to hear that.

No the Game runtime does not have admin privileges from default. You can give it that permission (recommended).
But I find that if you will need to write and read a file you generate, it is best to either write in the public folder were most machines have this already opened up to such operations.

Game Guru Does some Lua write in the GameGuru/Files folder. Some purchased scripts I have write and read save load data. ( moshrooms RPG scripts.

Also Lee is writing all his save load data in the savegames folder in a standalone build.

But you will never know for sure where the user will be running these from.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

PartTimeCoder
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 7th Apr 2016 17:36
I have updated the first post with new scripts, persistent game data now possible
PM
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 7th Apr 2016 18:11
Very nice.
Thank you.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

Login to post a reply

Server time is: 2024-05-03 09:29:51
Your offset time is: 2024-05-03 09:29:51