# Sorry for this code stuff

**URL:** <https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944>\
**Category:** flash\
**Created:** [March 30, 2003, 3:13pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944 "2003-03-30T15:13:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![luster](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@luster](https://forum.kirupa.com/u/luster)\
**Post date:** [March 30, 2003, 3:13pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/1 "2003-03-30T15:13:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2003, 3:33pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/2 "2003-03-30T15:33:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 1:30pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/3 "2003-03-31T13:30:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 1:47pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/4 "2003-03-31T13:47:48Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 1:57pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/5 "2003-03-31T13:57:51Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 2:35pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/6 "2003-03-31T14:35:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 3:49pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/7 "2003-03-31T15:49:30Z")

</div>

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

so your code should be

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

```

😉 =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 6:37pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/8 "2003-03-31T18:37:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 6:38pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/9 "2003-03-31T18:38:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 31, 2003, 6:50pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/10 "2003-03-31T18:50:59Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 1, 2003, 10:07am UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/11 "2003-04-01T10:07:25Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 1, 2003, 5:27pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/12 "2003-04-01T17:27:27Z")

</div>

> _Originally posted by Lunar\_4u_  
> **If you post ur fla file we can take a look at it and see the problem :cowboy:**

😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 1, 2003, 6:21pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/13 "2003-04-01T18:21:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 2, 2003, 5:24pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/14 "2003-04-02T17:24:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 2, 2003, 5:37pm UTC](https://forum.kirupa.com/t/sorry-for-this-code-stuff/16944/15 "2003-04-02T17:37:23Z")

</div>

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