0
\$\begingroup\$

At first I tried to make the progress bar update using only one object that would command everything (obj_Control), linking to the global left released event a script containing the draw_rectangle function, but I got no results.

The Game Maker did not acknowledge any errors, but the progress bar did not update when I clicked on the created rectangles.

obj_Control (already without the draw_rectangle event):

enter image description here

Because of this I decided to create 3 new objects (obj_Vida, obj_Fome, obj_Energia), each containing a sprite and when each was clicked it would perform the action to update the progress bar:

enter image description here

obj_Vida:

scpt 1 => obj_Control.vida+=10; (applies to self)

scpt 2 => draw_healthbar(120,100,240,120,vida,c_black,c_red,c_green,0,true,true); (applies to obj_Control)

obj_Fome:

script 1 => obj_Control.fome+=10; (applies to self)

script 2 => draw_healthbar(120,150,240,170,fome,c_black,c_red,c_green,0,true,true); (applies to obj_Control)

obj_Energia:

script 1 => obj_Control.energia+=10; (applies to self)

script 2 => draw_healthbar(120,200,240,220,energia,c_black,c_red,c_green,0,true,true); (applies to obj_Control)

Room:

enter image description here

Room size => 360x640

Translate => vida/life, fome/hungry, energia/energy

What happens is that even dying of clicking on objects (obj_Vida, obj_Fome, obj_Energia) nothing happens to the progress bar. I discovered that it is because of the event, it would have to be a draw event. I added one below the left released event, but it did not work.

I apologize for any typing errors. I am not an English speaker and I had to translate everything. If something was not clear, please signal.

Thanks for everything.

\$\endgroup\$
1
\$\begingroup\$

draw_ functions works only in Draw event (to be precise, it works anywhere, but all what you drew will be erased before Draw event). See Draw Event in the documentation.

So, you need separate it like this:

obj_Vida, Left Mouse Button Pressed event:

obj_Control.vida+=10;

obj_Fome, Left Mouse Button Pressed event:

obj_Control.fome+=10;

obj_Energia, Left Mouse Button Pressed event:

obj_Control.energia+=10;

obj_control, Draw event:

draw_healthbar(120,100,240,120,vida,c_black,c_red,c_green,0,true,true);
draw_healthbar(120,150,240,170,fome,c_black,c_red,c_green,0,true,true);
draw_healthbar(120,200,240,220,energia,c_black,c_red,c_green,0,true,true);
\$\endgroup\$
  • \$\begingroup\$ Thanks, but with me only worked after I preferred to use draw_sprite instead of draw_healthbar. I deleted the 3 objects and I preferred to draw the sprites by the own obj_Control plus the global event left released \$\endgroup\$ – Boneco Sinforoso May 21 '17 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.