GMS 2 [SOLVED] How to store variable in local variable in script

Discussion in 'Programming' started by Aleksi Laine, Jan 16, 2020.

  1. Aleksi Laine

    Aleksi Laine Member

    Joined:
    Dec 25, 2019
    Posts:
    12
    Hi,
    My problem is how to use two local variables together. See b.i.

    Code:
    ///@arg0  what_grid
    ///@arg1  what_path
    ///@arg2  what_circuit
    ///@arg3  what_stuff
    var n = 1,
    i = argument3,
    v = 0,
    b = 0;
    repeat(instance_number(object_index))
    {
        var priq = ds_priority_create();
        with(object_index) ds_priority_add(priq,id,distance_to_point(other.x,other.y));
        repeat(n) b = ds_priority_delete_min(priq);
        ds_priority_destroy(priq);
    
        if(!mp_grid_path(argument0,argument1,x,y,b.x,b.y,1))
        {
            if(n <instance_number(object_index)) n++;
            else n = 1;
        }
        else
        {
            if(argument2[? b] == 1)
            {
                v+=b.i; // Here be the problem matey!
            }
            if(n <instance_number(object_index)) n++;
            else n = 1;
        }
    }
    return v;
     
    JaimitoEs likes this.
  2. Aleksi Laine

    Aleksi Laine Member

    Joined:
    Dec 25, 2019
    Posts:
    12
    Solved it. I'm an idiot. I used with statement. Sorry for bothering you.
    Code:
    //old
    if(argument2[? b] == 1)
            {
                v+=b.i;
            }
            if(n <instance_number(object_index)) n++;
            else n = 1;
    //new
    if(argument2[? b] == 1)
            {
                with(b)i= argument3;
                v+=i;
            }
            if(n <instance_number(object_index)) n++;
            else n = 1;
     
    JaimitoEs likes this.

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