What are the ways to make grids more easily recognizable?

flyinian

Member
I'm using a lot of grids in my code and was wondering if their is an easier way to know what a grid item does instead of looking at numbers.

I've just been referencing back to the create event for the key.

I've also tried using local and instance variables and that just seems to break everything.
 

Simon Gust

Member
You can implement enums to define grid locations. These enums will be visible as words in your code, but convert to numbers when you run the game.

An enum can be defined somewhere and doesn't even need to be run to exist.
GML:
enum stats
{
    name = 0,
    tooltip = 1,
    damage = 2,
    attack_speed = 3
}

weapon_stat[0, stats.name] = "longsword";
weapon_stat[0, stats.tooltip] = "a normal sword";
weapon_stat[0, stats.damage] = 14;
weapon_stat[0, stats.attack_speed] = 5.60;

weapon_stat[1, stats.name] = "katana";
weapon_stat[1, stats.tooltip] = "a fast sword";
weapon_stat[1, stats.damage] = 9;
weapon_stat[1, stats.attack_speed] = 9.50;
and so on...

You can also implement an enum for the item ids too.
GML:
enum weapons
{
    longsword = 0,
    katana = 1
}
and write that instead of the number
GML:
weapon_stat[weapons.longsword, stats.name] = "longsword";
weapon_stat[weapons.longsword, stats.tooltip] = "a normal sword";
weapon_stat[weapons.longsword, stats.damage] = 14;
weapon_stat[weapons.longsword, stats.attack_speed] = 5.60;

weapon_stat[weapons.katana, stats.name] = "katana";
weapon_stat[weapons.katana, stats.tooltip] = "a fast sword";
weapon_stat[weapons.katana, stats.damage] = 9;
weapon_stat[weapons.katana, stats.attack_speed] = 9.50;
 

flyinian

Member
You can implement enums to define grid locations. These enums will be visible as words in your code, but convert to numbers when you run the game.

An enum can be defined somewhere and doesn't even need to be run to exist.
GML:
enum stats
{
    name = 0,
    tooltip = 1,
    damage = 2,
    attack_speed = 3
}

weapon_stat[0, stats.name] = "longsword";
weapon_stat[0, stats.tooltip] = "a normal sword";
weapon_stat[0, stats.damage] = 14;
weapon_stat[0, stats.attack_speed] = 5.60;

weapon_stat[1, stats.name] = "katana";
weapon_stat[1, stats.tooltip] = "a fast sword";
weapon_stat[1, stats.damage] = 9;
weapon_stat[1, stats.attack_speed] = 9.50;
and so on...

You can also implement an enum for the item ids too.
GML:
enum weapons
{
    longsword = 0,
    katana = 1
}
and write that instead of the number
GML:
weapon_stat[weapons.longsword, stats.name] = "longsword";
weapon_stat[weapons.longsword, stats.tooltip] = "a normal sword";
weapon_stat[weapons.longsword, stats.damage] = 14;
weapon_stat[weapons.longsword, stats.attack_speed] = 5.60;

weapon_stat[weapons.katana, stats.name] = "katana";
weapon_stat[weapons.katana, stats.tooltip] = "a fast sword";
weapon_stat[weapons.katana, stats.damage] = 9;
weapon_stat[weapons.katana, stats.attack_speed] = 9.50;

This should make things a lot easier, thank you.
 

flyinian

Member
You can implement enums to define grid locations. These enums will be visible as words in your code, but convert to numbers when you run the game.

An enum can be defined somewhere and doesn't even need to be run to exist.
GML:
enum stats
{
    name = 0,
    tooltip = 1,
    damage = 2,
    attack_speed = 3
}

weapon_stat[0, stats.name] = "longsword";
weapon_stat[0, stats.tooltip] = "a normal sword";
weapon_stat[0, stats.damage] = 14;
weapon_stat[0, stats.attack_speed] = 5.60;

weapon_stat[1, stats.name] = "katana";
weapon_stat[1, stats.tooltip] = "a fast sword";
weapon_stat[1, stats.damage] = 9;
weapon_stat[1, stats.attack_speed] = 9.50;
and so on...

You can also implement an enum for the item ids too.
GML:
enum weapons
{
    longsword = 0,
    katana = 1
}
and write that instead of the number
GML:
weapon_stat[weapons.longsword, stats.name] = "longsword";
weapon_stat[weapons.longsword, stats.tooltip] = "a normal sword";
weapon_stat[weapons.longsword, stats.damage] = 14;
weapon_stat[weapons.longsword, stats.attack_speed] = 5.60;

weapon_stat[weapons.katana, stats.name] = "katana";
weapon_stat[weapons.katana, stats.tooltip] = "a fast sword";
weapon_stat[weapons.katana, stats.damage] = 9;
weapon_stat[weapons.katana, stats.attack_speed] = 9.50;
Do I have to create the grid normally without the enums and then create the grid with enums?
 

Simon Gust

Member
One last thing,....

What did you do to your code to make it look like this? In other words, how did you get rid of the "ds_grid_add"
and still have your code work?
GML:
weapon_stat[weapons.katana, stats.name] = "katana";
I used an array. But when using ds_grids you can do something similar
GML:
weapon_stat[# weapons.katana, stats.name] = "katana";
would be the equivalent of
GML:
ds_grid_add(weapon_stat, weapons.katana, stats.name, "katana");
These symbols are called accessors and are there to shorten code.
# is for ds grids
@ for refrenced arrays
| for ds lists
? for ds maps
All enclosed in these [ ] brackets.
 

flyinian

Member
I used an array. But when using ds_grids you can do something similar
GML:
weapon_stat[# weapons.katana, stats.name] = "katana";
would be the equivalent of
GML:
ds_grid_add(weapon_stat, weapons.katana, stats.name, "katana");
These symbols are called accessors and are there to shorten code.
# is for ds grids
@ for refrenced arrays
| for ds lists
? for ds maps
All enclosed in these [ ] brackets.
I used an array. But when using ds_grids you can do something similar
GML:
weapon_stat[# weapons.katana, stats.name] = "katana";
would be the equivalent of
GML:
ds_grid_add(weapon_stat, weapons.katana, stats.name, "katana");
These symbols are called accessors and are there to shorten code.
# is for ds grids
@ for refrenced arrays
| for ds lists
? for ds maps
All enclosed in these [ ] brackets.
ah, okay. Thank You.
 
Top