Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing custom instance variable from other instance object

Tags:

gml

game-maker

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.

like image 440
Andrius Avatar asked Dec 05 '25 04:12

Andrius


1 Answers

Use id, not self:

health_text.origin = id;
like image 143
Dmi7ry Avatar answered Dec 07 '25 15:12

Dmi7ry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!