Item Naming System

M

Mattress

Guest
I am creating a blacksmithing game, and I would like to know a good way to name the weapons and stuff that you create, put that is a variable (or something like that), and be able to look back on the weapon and it's special traits. Any help would be appreciated. If this is too confusing, I can reword it too.
 
M

Mattress

Guest
ds_maps
Code:
item = ds_map_create();
item[?"name"] = "sword";
item[?"value"] = 40;
How would this work exactly? Each time a sword is created, assign it a name and a value? That way, I could put each weapon in order for a showcase at the end of the game.
 
S

Snail Man

Guest
You could also use invisible objects to represent items; that way you can load it with as much information as you want, as well as making it perform operations if need be

Code:
var item = instance_create(0,0,obj_item);
item.price = 20;
item.sprite = spr_sword;
item.special = etc...
 
P

Paolo Mazzon

Guest
You could also use invisible objects to represent items; that way you can load it with as much information as you want, as well as making it perform operations if need be
If you want plenty of excess variables doing absolutely nothing and CPU overhead for having the object simply exist on top of managing their positions in the room should you choose to use instance_activate/deactivate, then yes, use objects instead.
 
W

whale_cancer

Guest
Each item would require a different identifier that way (but there are ways to avoid that too). A better option would be to use a 2D array IMO.

Code:
item[0, 0] = "Sword";
item[0, 1] = 40;
item[1, 0] = "Potion";
item[1, 1] = 20;
Read more about arrays here:

http://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/401_06_arrays.html
Really? You would have to keep track of what each column in the 3d array refers to then. That seems inelegant. ds_maps were built for this.

While data structures take a bit to wrap your head around to start, they are infinitely more flexible.

I would use a ds_list that stores all your weapons, with each entry in that list a ds_map. With each entry being a ds_map, you could have as many attributes as you want for each weapon (without having to remember which columns relate to which attribute).

You could use an array in place of the ds_list, but I would suggest it is better to just bite the bullet and come to understand both lists and maps. You can go on to use ds_grids if you want to sort the list, but that is a bit more complex.
 
M

Mattress

Guest
Thanks guys! I guess I will learn to use the data structures. I've been putting that off anyway, mostly because it confuses me.
 
L

L0v3

Guest
Personally I would use an object. These require more resources, but I just find it way more organized and less confusing to use them. I usally always have an eng_data object I use to store data. All you need then is a content item controller or container somewhere to perform CRUD operations on the items. Create some simple scripts like item_create_weapon(name, damage, etc...), then use these to load all items during game start.

Example:
Code:
///Item Container - Create Event
global.items = ds_list_create();
item_create_weapon("Sword", 10);
item_create_weapon("Axe", 5);
Code:
///item_create_weapon(name, damage);

// blahblah comments...

var obj = instance_create(x, y, eng_data);

with (obj)
{
    name = argument0;
    damage = argument1;
}

ds_list_add(global.items, obj);
I can see an argument for efficency in using data structures instead of objects, but for me it's not been a problem. The container and script approach though should be used as this gives much cleaner readability. You would also have scripts to remove, search and update items.
 
Top