Sorry for this code stuff

I’m sorry for yet another script question, but here it comes.

I’m making a game, and i have set a dynamic textbox “life” with var “life” and it works like this.
In frame 21 of an MC(so not on the main scene) , I have this code:
_root.life -= 1;

to make that, if you reach this frame(it’s a shooter, if you shoot quick enough, you won’t reach it) your life goes -1

In Frame 1 of a layer, I have this code:
_root.life = 50;

to make that you have 50 life when you start the game
That worked well, but now I’m getting to the problem.
In frame 1 of another layer, I inserted this code:
if root.life = 0;
gotoAndPlay(frame2)

(frame2 is a “Game Over” screen)

I changed a lot of stuff to try, but it always gives errors.
What is wrong?

Please help

try this

if _root.life = 0;
gotoAndPlay(frame2)

you didnt put a underscore on the root, sometimes simple things like this mess up our code and we spend hours trying to find out whats wrong trust me it hapens to me all the time :S

Grim

Hi, I tried the code but I’m sorry, it didn’t work.

It gives this:
Line 1: ‘(’ expected
if _root.life = 0;

Please help!

I think you need to put the if condition in brackets:

if (_root.life = 0) {
gotoAndPlay(frame2);
}

Very strange…
With that new code, it doesn’t give any errors, but it doesn’t work, and I don’t start with 50 life, although there is
_root.life =50;
in another layer.
Very strange…

If you post ur fla file we can take a look at it and see the problem :cowboy:

= assign a value to the variable/property/whatever.
== tests two variables/properties/whatever for equality.

so your code should be

if (_root.life == 0) gotoAndPlay(frame#);

:wink: =)

Now I tried the last code, it (nearly) all works fine:

  1. You start with 50 life

  2. If an MC pops up and goes to frame 21(of the MC’s timeline, the main is still in frame1), your life goes -1

  3. After 50 MC’s have popped up; your life is 0 ,but instead of going to frame 2, it just goes to -1,-2,-3,…

Code used:
stop:() in layer 1 Frame 1 of main timeline

_root.life =50; in layer 2 Frame 1 of main timeline

if (_root.life == 0) in layer 3 Frame 1 of main timeline
gotoAndPlay(frame2);

_root.life -= 1; in MC’s timeline, frame 21

Sorry noticed something in the stop command code changed automatically after posting it. But that code is OK.

put the code whitin an onEnterFrame handler so it checks the statement continuosly… =)

this.onEnterFrame = function() {
if (_root.life == 0) {
gotoAndPlay(frame#);
delete this.onEnterFrame;
}
}

That code didn’t work either!
I don’t understand what does always go wrong. It doesn’t give any errors, but it just won’t go to frame 2!

Please, I really don’t know what to do!

Originally posted by Lunar_4u
If you post ur fla file we can take a look at it and see the problem :cowboy:

:wink:

The file is 150.000 bytes, 76.000 after WINZIP.
How can I put this on Kirupa?

An attachement’s max sixe is 15 000 bytes.
My movie is 150 000 bytes. After I WinZipped it, it was 76 000 bytes. If I delete a few stuff, I can get it down to 70 000 bytes.
But how can I post it on kirupa?

PS If you still now how to solve the if _root.life stuff,please teel me!

get a free hosting at brinkster/[url=http://www.tripod.lycos.co.uk/]lycos/whatever, upload it there and give us a link to the file :wink: