1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

(SOLVED)Object Self Referencing for Data Structures

Discussion in 'Programming' started by Starburst383, Oct 13, 2016.

  1. Starburst383

    Starburst383 Guest

    I created a global stack, and now every time an event is triggered. i want to store the object the event was triggered in, to the stack. This object then has to be edited by a command block. for example.

    //THIS_OBJECT
    ds_stack_push(gemSwap, "THIS_OBJECT");
    ///i want to store the reference to the object or anything that will let me edit it in command block


    //Command block
    var obj = ds_stack_pop(gemSwap);
    obj.x = 100;

    gem swap is the stack my object is in, and i want the data location to be loaded and then the x variable of that data location to be edited. i already wrote code to do all the editing, however..... there seems to be no good way to reference the object from it's self. i tried instance_id, but it's a read only? and it seems to affect all my objects in the room which stem from the same parent.

    side note, i'm making a match 3 prototype, so most objects i'm dealing with all have the same parent and code, and multiple instances of each child. i want to be able to affect only 1 instance at a time.
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,684
  3. Starburst383

    Starburst383 Guest

    This is my current situation ......

    current code :

    //////object1
    ds_stack_push(gemSwap, id);

    //////object2
    ds_stack_push(gemSwap, id);

    ////////////command block
    //store first gems data
    var xtemp = (ds_stack_top(gemSwap)).x;
    var ytemp = (ds_stack_top(gemSwap)).y;
    //save fist gem
    var obj = (ds_stack_pop(gemSwap));
    //give first gem second gems data
    obj.x = (ds_stack_top(gemSwap)).x;
    obj.y = (ds_stack_top(gemSwap)).y;
    //overwrite with second gem
    obj = (ds_stack_pop(gemSwap));
    //give second gem first gems data
    obj.x = xtemp;
    obj.y = ytemp;


    and then all the objects in the game room which are gems (all share the same parent) are moved to the position i'm swapping with instead of just the gem i want to be moved. they all seem to have the same id?
     

    Attached Files:

  4. Starburst383

    Starburst383 Guest

    UPDATE, i got it working a slightly different way, in case any one is curious. i swapped the sprites instead of the objects them self. hopefully this doesn't mess me up in the long run.

    //obj1
    ds_stack_push(gemSwap, id);

    //obj2
    ds_stack_push(gemSwap, id);


    //command block
    {

    //store first gems data
    var temp = (ds_stack_top(gemSwap)).sprite_index;

    //save fist gem
    var obj = (ds_stack_pop(gemSwap));

    //give first gem second gems data
    obj.sprite_index = (ds_stack_top(gemSwap)).sprite_index;

    //overwrite with second gem
    obj = (ds_stack_pop(gemSwap));
    //give second gem first gems data

    obj.sprite_index = temp;

    }
     

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