GM:S 1.4 Skill trees and datastructures/arrays

Discussion in 'Programming' started by PWL, Aug 18, 2017.

  1. PWL

    PWL Member

    Jun 21, 2016
    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:
    enum SkillProp{
    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).
    /// 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?
  2. Fabseven

    Fabseven Member

    Oct 7, 2016
    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 = => 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,
    ///script do_something
        level += 1
    btw spells level are stored in a INI file using GML function to read/write them. (easy to use)

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice