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

GML [SOLVED] how to send variables to the unique instance that the object creates?

jobjorgos

Member
I want for each obj_train_cart object to create an obj_inv_block at it own x and y, and that keeps on the x and y also every step after it has been created.
But now I get errors that say: variable obj not set when reading it in the step event.
What can I do?

OBJ_TRAIN_CART
Create Event:

obj = instance_create(x,y,obj_inv_block);
obj_self = self;

Step Event:
with obj
{
obj.x = obj_self.x;
obj.y = obj_self.y;
}
 

Cpaz

Member
When using "with" your changing the scope of the following block.

So essentially, you'd want to reference "obj" s x and y coords directly instead of referring to the variable obj.

Like so:
Code:
 with obj {
    x = other.x;
    y = other.y;
}
Or something like that.
 

kupo15

Member
Yep exactly. The obj_self part works but its completely unnecessary as "other" is better to use here. Its throwing an error because "obj" variable was not established in the inv_block object. Simply doing the above code block will work for you
 

jobjorgos

Member
very nicely!

with obj {
x = other.x;
y = other.y;
}

it works perfect, thanks!!
I though 'other' did only work with collisions event but now I read in the manual it also does with the 'with' function, good to know that
 
Top