P
PWL
Guest
I'm creating a skill tree, and if I could I would create a class for a skill, have some properties on that class and have a grid of those objects. But since GML doesn't do classes I've done it like this so far:
But say now that I want to increase a skill by 1. Then I got this script, which seems to have an extra unnecessary step (The tmp-variable).
I can't access the skill's properties (like points) without first getting the skill itself and putting it into a variable like I've done here with tmp. Is there a better way of structuring this in GML, as it doesn't have the kind of OOP I'm seeking?
Code:
enum SkillProp{
NAME,
POINTS
}
global.skilltree = ds_grid_create(3, 6);
// Fill with debug data
for(var xx = 0; xx < 3; xx++){
for(var yy = 0; yy < 6; yy++){
var skill = 0;
skill[SkillProp.NAME] = "Skill" + string(xx) + string(yy);
skill[SkillProp.POINTS] = 0;
global.skilltree[# xx, yy] = skill;
}
}
Code:
/// skilltree_add_point(x, y);
var xx = argument0;
var yy = argument1;
var tmp = global.skilltree[# xx, yy];
tmp[SkillProp.POINTS] += 1;
global.skilltree[# xx, yy] = skill;