Hey all, just getting the grip around the variables and im experimenting.
This is what i have as a variable
money = 1000;
health = 100;
Then i have the dynamic textbox that shows them.
works great, and i also have various effect that makes the two go up and down. Here's the problem, or more, how i would like to expand the concept but is stuck on.
Right now both variables can go as high and low as possible (of course).
Is there something i can add in that script that makes so the money variable can't go below 0.
Also is there something i can add so that the Health can't go ABOVE say 500 and when health reaches zero (or a negative) this triggers
// place the following after where ever you have something like this: money -= 10;
if (money<0) {
money = 0;
}
// place the following after where ever you have something like this: health += 10;
if (health>500) {
health = 500;
}
if (health<0) {
_root.gotoAndPlay("gameover");
}
hmm might as well put this question here instead of making a new thread.
I've been trying to expand the script to a moving character hitting something and getting -10 life (the character movieclip is named 'man').
This is the script i tried.
Code:
onClipEvent (load) {
if ((this.hitTest(_root.man))) {
health -= 10;
if (health>500) {
health = 500;
}
if (health<1) {
_root.gotoAndPlay("gameover");
}
}
But i keep getting a syntax error on itthough i can't figure out what it is... can anyone help out with this?
onClipEvent (enterFrame) { }
if ((this.hitTest(_root.man))) {
health -= 10;
if (health>500) {
health = 500;
}
if (health<1) {
_root.gotoAndPlay("gameover");
}
}
gets me
**Error** Scene=Scene 1, layer=Hero, frame=4:Line 2: Statement must appear within on/onClipEvent handler
if ((this.hitTest(_root.man))) {
Improper formatting causing the problems, try this...
Code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.man)) {
health -= 10;
}
if (health>500) {
health = 500;
}
if (health<1) {
_root.gotoAndPlay("gameover");
}
}
Improper formatting causing the problems, try this...
Code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.man)) {
health -= 10;
}
if (health>500) {
health = 500;
}
if (health<1) {
_root.gotoAndPlay("gameover");
}
}
hmm alright this is odd, this script works in that flash doesn't complain about the formating. But the health bar doesn't go down on hit test
I have one layer on top with
health = 500;
and then a dynamic text box in the game layer that shows the health. The buttons work, but the hit test doesn't affect it.
The posted code is only changing the value of the variable 'health'.
Do you have code in your health bar that makes it update when the value of the 'health' variable is changed?
Ah of course! I should have known that, sometimes you dont see the forest behind all the trees...
It even works as i intended with the health draining. Just for future references, is there anything i can add to that script that makes it so that that it only triggers once? IE that one you hit it you get -10 then you have to walk out and hit it again so you get -10 and so on?
Anyway, thanks alot. The problem in itself is solved