How to contain all the data

Smenkare

Member
My every weapon, every piece of armor has different stats and sprite animations. I dont know how it works in gm and what its the most efficent and easiest way.
My sword for example has 4 different variables.
sword.animation
sword.damage
sword.equipped
sword.clicked
And i have these weapons like 50. How can i store all the data and how can i refer to this. I mean how can i check this for example sword data and then depends what animation, damage, and if its false or true - do some "events". Im sorry for my english, i hope that you understand my problem. I just don't want to make 1000 "if" questions. Thanks for help.
 

samspade

Member
My every weapon, every piece of armor has different stats and sprite animations. I dont know how it works in gm and what its the most efficent and easiest way.
My sword for example has 4 different variables.
sword.animation
sword.damage
sword.equipped
sword.clicked
And i have these weapons like 50. How can i store all the data and how can i refer to this. I mean how can i check this for example sword data and then depends what animation, damage, and if its false or true - do some "events". Im sorry for my english, i hope that you understand my problem. I just don't want to make 1000 "if" questions. Thanks for help.
Arrays, or data structures. The advantages of arrays is that you don't need to clean them up. The disadvantage is that they don't have much advanced functionality. Data structures are the reverse. You do have to clean them up, but on the other hand they have a bunch of built in scripts like sort, shuffle, delete, add, and our much easier to save through the JSON format.

I'll use the array version as an example as it is probably the easiest to understand:

Code:
///initialize weapon array
enum weapon_type {
    sword,
    spear,
    knife,
}

enum weapon {
    animation,
    damage,
    equipped,
    clicked,
}

sword = [sword.animation, sword.damage, sword.equipped, sword.clicked];
spear = [spear.animation, spear.damage, spear.equipped, spear.clicked];
knife = [knife.animation, knife.damage, knife.equipped, knife.clicked];
weapon_array = [sword, spear, knife]

///accessing weapon array
var weapon = weapon_array[weapon_type.sword];
var is_equipped = weapon[weapon.equipped];

It would be basically the same if you used ds_lists. If you used a ds_grid it would be different and another common form would be a combination of lists and maps.

For longer explanations of a couple other ideas you might want to read this thread, especially Tsa05's posts

https://forum.yoyogames.com/index.php?threads/ds_map-string-versus-enum.57767/#post-349538

Or this thread, especially FrostyCat's posts:

https://forum.yoyogames.com/index.php?threads/nested-arrays.58290/#post-352365

If those things don't make sense it might be best to start with some basic inventory tutorials as those will generally touch on the basics of storing data and what you're asking about is simply more complex versions of that. I would recommend the inventory tutorials by Friendly Cosmonaut or Gloomytoad Studios on YouTube.
 
Top