SOLVED: Resize image heath bar width by int

Started by Slasher, Tue 11/09/2012 07:33:28

Previous topic - Next topic

Slasher

EDIT: I should have realised:

Code: AGS
 Health = (Health-10);
 bHealthbar.Width = Health;


-------------------------------------------------------

I have added a 'Health Bar' and have ran into a snag.

Basically it works except that I want the button (bHealthbar) to re size (width) by events using an Int for width.

The below code fails to increment down (or up) by events as expected to.

Ideally bHealthbar button (has a long bar image) will lose width each time an event happens (or gain by an event).

I have a global int 'Health' and have ClipImage = true;

I can not seem to find the solution although I can resize buttons manually but this is not what is desired.

Code: AGS
function region4_WalksOnto()
{
 object[8].SetView(8);
 object[8].Animate(0, 4, eRepeat, eNoBlock);
 cELF.Say("I best keep my distance from that deadly assassin spider!!");
 Health = -10; // This bit should lose 10 from the bars width (starts at 200 width size)
 bHealthbar.Width = Health;
}


Would someone please assist?


monkey0506

Quote from: slasher on Tue 11/09/2012 07:33:28EDIT: I should have realised:

Code: AGS
 Health = (Health-10);


-------------------------------------------------------

Code: AGS
 Health = -10; // This bit should lose 10 from the bars width (starts at 200 width size)

Just to help clear up what the issue was, in your original code snippet you were directly setting the value of the variable Health to -10. In your revised code, you're of course reducing its value by 10. You could also write this as:

Code: AGS
 Health -= 10;


The -= operator means you're going to reduce the value of the variable on the left by the amount on the right. If that causes any confusion then feel free to steer clear of -= for now, but if you're going to code a lot it will save you having to type the variable name twice (If you're wanting to reduce only by 1, you could also even use the -- operator, such as Health--; which makes it that much shorter if only changing by 1).

Also, you have posted this as being in the region4_WalksOnto event, which is fine, but I see you're referencing your objects via the global object array. If you want to make your room scripts a bit more readable then you can use the object's name directly (set in the room editor) just like you do with characters. Outside of the room script (GlobalScript, etc.) you would still have to use the object array, but inside of room scripts you could do:

Code: ags
  oSpider.SetView(8);
  oSpider.Animate(0, 4, eRepeat, eNoBlock);


Assuming that object 8 in the room is named oSpider (just guessing from the Elf's response.).

And welcome to the forums by the way. :)

Slasher

Thank you deadmonkey_05_06

That's cleared a few things up.

cheers

SMF spam blocked by CleanTalk