• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Best solution for data management?

Nixxi

Member
I'm playing around with a script that generates 100 items based on a pair of nested loops and switches that fill a 2D array with strings for item names, and writing those names along with data to define the characteristics of those items to an INI file - just to see if I can generate a list of gear similar to how Diablo 3 creates loot with a combination of random stats and expected rules. Each item in the INI file looks something like this when it's output:

[ITEM_VARIANT0 ITEM_NAME0]
StatN0 = 1.5
StatV1 = 2.6
[ITEM_VARIANT1 ITEM_NAME0]
StatN0 = 0.4
StatV1 = 4.5
[ITEM_VARIANT2 ITEM_NAME0]
StatN0 = 3.3
StatV1 = 3.0
[ITEM_VARIANT0 ITEM_NAME1]
StatN0 = 1.0
StatV1 = 0.9
[ITEM_VARIANT1 ITEM_NAME1]
StatN0 = 2.5
StatV1 = 2.3
[ITEM_VARIANT2 ITEM_NAME1]
StatN0 = 1.1
StatV1 = 1.8
...

I'm sure the more advanced users can already see where I'm going with this. The "ITEM_VARIANT0" is the index for the 2D array and is the "Firey/Icy/Weak/Powerful/Normal/Enchanted/Whatever" variant of an item (including a signature stat that accompanies the variant name), and every 10th listing in the index is the start of a new item type like "Belt/Boots/Hat/Sword/Fruit/Etc." with a base stat that is expected for the item type. The level requirements and stat values are augmented by multipliers based on the player's level when he/she earns them, and quality of the item is a random chance to receive anything from "poor" to "legendary".

This is of course going to be very unwieldy and difficult to manage over time as the list gets bigger and changes need to be made for balance. It's not very flexible or scalable, and I'm wondering if there is a much better solution for managing data-driven content. I really don't want an INI file (regardless of whether or not it's incripted) to be the go-to source for the game to look up and apply values for items to player loadouts. Is there a better way to manage this data beyond 2D/3D arrays and data structures like ds_grid? Anything that gets me closer to generating loot similar to Diablo 3 or Destiny would be fantastic.
 
P

PandaPenguin

Guest
I think a combination of JSON (for external saving) and ds_map (for internal use) would be a good way to go for you
 
I would be using a ds_grid, then write it to your ini file with this:

ini_write_string("MySave","Inventory",ds_grid_write(item_grid));

You can additionally nest lists and other data structures inside the grid, just be sure to write them each separately - the grid will save the 'address' of the data structure if nested, and not the actual contents.

So for example, if you used an embedded ds_list for each (x,0) position on the grid, you could do it like this:
Code:
for(var i = 0; i < ds_grid_width(item_grid); i++){
   ini_write_string("MySave","List"+string( i ),ds_list_write(item_grid[# i, 0]);  // taking our ds_list from position ( i , 0 )
   }
 

rIKmAN

Member
I would be using a ds_grid, then write it to your ini file with this:
ini_write_string("MySave","Inventory",ds_grid_write(item_grid));
He specifically said he doesn't want to use .ini files...
I really don't want an INI file (regardless of whether or not it's incripted) to be the go-to source for the game to look up and apply values for items to player loadouts.
 

Nixxi

Member
Well, what I mean is I don't believe an INI file would be secure enough to prevent people from decrypting it and cheat values of items. I know nothing is "tamper proof", but it's a concern none the less. I went to the JSON foundation site and given my level of programming experience I don't think it's a good fit for me. I'm still trying to learn GML after all. :)

I also took a peek at the GMSDB link and it looks promising. I'll probably download the demo this weekend and check it out over the holiday to evaluate. Thanks everyone for the suggestions!
 
P

PandaPenguin

Guest
Well, what I mean is I don't believe an INI file would be secure enough to prevent people from decrypting it and cheat values of items. I know nothing is "tamper proof", but it's a concern none the less. I went to the JSON foundation site and given my level of programming experience I don't think it's a good fit for me. I'm still trying to learn GML after all. :)

I also took a peek at the GMSDB link and it looks promising. I'll probably download the demo this weekend and check it out over the holiday to evaluate. Thanks everyone for the suggestions!
well you could always skip the JSON/INI completely and save the ds_map directly with ds_map_secure_save() in its native encrypted form so it is harder for the player to mess around with the values stored in it
 
Last edited by a moderator:
Well, what I mean is I don't believe an INI file would be secure enough to prevent people from decrypting it and cheat values of items. I know nothing is "tamper proof", but it's a concern none the less. I went to the JSON foundation site and given my level of programming experience I don't think it's a good fit for me. I'm still trying to learn GML after all. :)

I also took a peek at the GMSDB link and it looks promising. I'll probably download the demo this weekend and check it out over the holiday to evaluate. Thanks everyone for the suggestions!
If you are just worried about someone changing money=10 to money=100000, then you wouldn't really need to worry.

This is part of an .ini that I'm using with ds_list_write():
[Data]
Group:1="2E01000002000000000000000000000000000840000000000000000000000040"
Group:0="2E0100000200000000000000000000000000000000000000000000000000F03F"
Group="5A0200000300000003000000000000000000000000002640010000000900000054776F204C616E64730000000000000000000010400000000000000000000028400100000012000000506F70756C6174696F6E2043656E74657273000000000000000000001040000000000000000000000000000000000000000000000000000000000000000000000000"
If you are still concerned, just do an MD5 check (md5_file()) and save that value to a separate file. Easy verification! You can help obscure the MD5 it by filling the rest of the MD5 file with random values and keys. Just be sure to recreate the whole file each time, or they will see that only the MD5 is changing, ;)

Also note that you can save files as any file extension you like, (ie, ".info", ".gamesave", ".temp"). All that matters is you know what to open it as. ini_open("data.gamesave") for example.

(I tend to use .ini's in my examples, as the functions are embedded into my mind. I use them constantly, but you could use any file format you like)
 

Nixxi

Member
Yes, that makes sense. I still have a lot of multi-dimensional data to wrangle though, so part of my problem is managing it all in a way that minimizes code jockeying while still being scaleable for the amount of content I add to it. Having the item table + saving what the player has equipped + what the player also has in their inventory is one thing, but setting it up so that if/when I update the item table with added/removed entries the equipped/inventoried items don't become something else because their key values have changed (like an item that was a sword in the equipped slot doesn't become a potion because the sword's key changed). You can tell I'm a n00b at this. :)

I'm going to give the GMSDB demo a try and see if it meets all of my needs. Then hopefully I can get back to coding the really fun stuff.
 
Top