Search code examples
game-makergml

Accessing custom instance variable from other instance object


I basically have this:

Obj1 Create event:

health_total = 50;
health_current = health_total;
health_text = instance_create(x,y-10,obj_health); // Object to show health of an instance object

health_text.origin = self; // Assign an 'origin' variable so I can access it later?

obj_health Draw event:

show_debug_message(origin.x); // <-- This works just great!
show_debug_message(origin.health_current); // <-- This throws error :(

I assume that the variable might be local but then, how do I make it public? GML is a bit new to me, though, I'm not new to programming. This makes my mind hurt.


Solution

  • Use id, not self:

    health_text.origin = id;