• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

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