• 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!

Legacy GM Skill trees and datastructures/arrays

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:
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;
    }
}
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).
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;
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?
 

Fabseven

Member
Hello,
I understand you want to store values on grid and such but i donot know if you will like it in the end.

Let me explain,
I did something like this recently : It's a magic tree with 4 ways (still in dev so there are only a few spells atm)


1) Each properties of each spells are readed from a json file and then stored and a ds grid.
2) Only got one objet in the room : obj_magicshop_controler.
In the create event i load the spells like a said at 1
Looping on each spell creating an obj_magicshop_cell with spell properties ( position x/y , name, cost, etc etc etc , you just have to create each var in the create event of the obj to use them after instance_create)

3) the obj_magicshop_cell is like a hybrid of class and object, it draw itself , it check for click itself etc (using gml events + code)
On hover : global.selected = self.id => the obj_controler draw the gui bottom with informations about the spell if global.selected != noone

In the end if would create a script to do something i could use the WITH function of gml,
Code:
///script do_something
with(argument0)
{
    level += 1
}
btw spells level are stored in a INI file using GML function to read/write them. (easy to use)
 
Top