Author Topic: SOLVED: Resize image heath bar width by int  (Read 247 times)  Share 

slasher

  • Stare deep into the darkness of your mind...
    • I can help with AGS tutoring
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
SOLVED: Resize image heath bar width by int
« on: 11 Sep 2012, 07:33 »
EDIT: I should have realised:

Code: Adventure Game Studio
  1.  Health = (Health-10);
  2.  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: Adventure Game Studio
  1. function region4_WalksOnto()
  2. {
  3.  object[8].SetView(8);
  4.  object[8].Animate(0, 4, eRepeat, eNoBlock);
  5.  cELF.Say("I best keep my distance from that deadly assassin spider!!");
  6.  Health = -10; // This bit should lose 10 from the bars width (starts at 200 width size)
  7.  bHealthbar.Width = Health;
  8. }
  9.  

Would someone please assist?

« Last Edit: 11 Sep 2012, 07:37 by slasher »
Don't aim to be the best, just do your best ;)

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: SOLVED: Resize image heath bar width by int
« Reply #1 on: 11 Sep 2012, 07:48 »
EDIT: I should have realised:

Code: Adventure Game Studio
  1.  Health = (Health-10);

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

Code: Adventure Game Studio
  1.  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: Adventure Game Studio
  1.  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: Adventure Game Studio
  1.   oSpider.SetView(8);
  2.   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. :)
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

slasher

  • Stare deep into the darkness of your mind...
    • I can help with AGS tutoring
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Re: SOLVED: Resize image heath bar width by int
« Reply #2 on: 11 Sep 2012, 08:34 »
Thank you deadmonkey_05_06

That's cleared a few things up.

cheers
Don't aim to be the best, just do your best ;)