PDA

View Full Version : if (Dynamic text =___)


tim710
12-03-2008, 04:28 AM
I'm trying to make a health bar for a game I'm making here (http://school.timswildwackyemporium.com/gametest/stick.html).
I want to make it so that if the dynamic text box is between 100 and 80, the bar goes to the next frame.

Unfortunatly, I cannot figure out the code for it. Heres what it should be

if (health = 100) {
this.gotoAndPlay(2);
}
if ((health < 100) and (health > 80)) {
this.gotoAndPlay(3);
}
and so on...

(health is the name and Var of the textbox)

sureshdavid
12-03-2008, 05:17 AM
hi trim,
Try this.

if (health == 100) {
this.gotoAndPlay(2);
}
if ((health < 100) && (health > 80)) {
this.gotoAndPlay(3);
}

Cheers

Bod720
12-03-2008, 11:19 AM
What I think is a better way, is to mask the inside on the bar, then use:

maskingBar._width=(health*maxHealth)/widthOfMask

I'm assuming that max health is 100, but I'm not sure, so I just put maxHealth in.

I you don't understand that, or don't know exactly how to do it, and want me to do it, zip then upload your .fla, and I'll sort it out.

Also, what you were doing:
if (health = 100) {...
Was using '=' instead of '=='

= tells Flash that something equals something, and == asks Flash if something equals something (returning a Boolean value - true or false - which is what the if function checks).

And finally, you could use 'else if' for the next line so:

if (health == 100) {
this.gotoAndPlay(2);
} else if ((health < 100) && (health > 80)) {
this.gotoAndPlay(3);
}

But I would personally use the first way that I said.

Bod720
12-03-2008, 11:19 AM
hi trim,

It's tim ;)

tim710
12-03-2008, 12:28 PM
Your methods don't seem to be working for me. I uploaded the zipped file here (http://school.timswildwackyemporium.com/gametest/stick.fla.zip), on flash 8 (on a mac if it makes a difference).

Bod720
12-03-2008, 04:46 PM
Cool, I'll take a look.

Also, I might've got the division the wrong way 'round, but I'll get back to you soon.

fitz
12-03-2008, 06:21 PM
if (health == 100) this.gotoAndPlay(2); else
if (health > 80) this.gotoAndPlay(3); else
if (health > 60) this.gotoAndPlay(4); else
if (health > 40) this.gotoAndPlay(5); else
if (health > 20) this.gotoAndPlay(6); else
if (health > 0) this.gotoAndPlay(7);

would probably work

Bod720
12-03-2008, 07:13 PM
I've made it work and you can find it at: www.bod720.co.nr/stick/
I saved it as a Flash 8 file, but if it doesn't open, then just say.

Also, I realised that you would've needed to use onEnterFrame, so I've done that too.

And Fitz, for your's to work, you need to put {}s and onEnterFrame in, which would change it to this:
onEnterFrame = function () {
if (health == 100) {
this.gotoAndPlay(2);
} else if (health > 80) this.gotoAndPlay(3); else
if (health > 60) {
this.gotoAndPlay(4);
} else if (health > 40) {
this.gotoAndPlay(5);
} else if (health > 20) {
this.gotoAndPlay(6);
} else if (health > 0) {
this.gotoAndPlay(7);
}
}

Both ways would work (mine and theirs), but my way is a lot more accurate.

fitz
12-03-2008, 07:52 PM
Yea I don't do AS2 (AS3 only), so was just approximating what would be required. Of course a resizing approach is more accurate, but I don't know if that's what he was going for -- it wasn't what he was asking about that's for sure.

tim710
12-03-2008, 08:58 PM
Bods way worked perfectly.

All you had to do is this

onEnterFrame = function () {
barMask._width = (health/100)*144;
};

and add a mask right?

I'm still not entirely sure how that works, though, could you explain to me what that is saying?

EDIT:

Nevermind, your first post explains it.
Thanks

Bod720
12-03-2008, 09:45 PM
Cool. If there are any other problems, feel free to PM me a link to your thread.