# Simple kids game - need a little help with variables

**URL:** <https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899>\
**Category:** Uncategorized\
**Created:** [July 22, 2004, 11:24am UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899 "2004-07-22T11:24:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaz](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jaz](https://forum.kirupa.com/u/jaz)\
**Post date:** [July 22, 2004, 11:24am UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/1 "2004-07-22T11:24:20Z")

</div>

Hi fellow Kirupians,

I’m trying to build a simple game:

You have 3 objects in a room and a “submit” button, lets say the objects are lightbulbs - you can (toggle) switch each lightbulb on or off, by clicking on them. (As many times as you like, and in any order you like).

When you hit the “submit” button, if all the lights are ON - you win, but if ANY of the lights are OFF - you lose.

Simple huh?

At the moment I am failing to get my head round how to do this! - I’m setting a variable for each light, either on or off:

lightOne = “on”

but I can’t make the code on the “submit” button react to what the variables are:

on (release) {  
if (lightOne == “on”) {  
gotoAndStop(“win”);  
} else {  
gotoAndStop(“lose”);  
}  
}

Of course, this is only for one lightbulb, I also need to put in the code that will allow you to switch on more than one, and in no particular order.

Perhaps string variables is the wrong approach, maybe I should be using booleans…

A little help please?

jaz :h:

---

<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:** [July 22, 2004, 11:46am UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/2 "2004-07-22T11:46:53Z")

</div>

```auto

// Functions
function switch_light(bulb) {
 if(bulbstatus[bulb-1]){
  bulbstatus[bulb-1] = false;
  this["bulb_"+bulb].gotoAndStop(1);
 } else {
  bulbstatus[bulb-1] = true;
  this["bulb_"+bulb].gotoAndStop(2);
 }
}
function checkstatus() {
 if (bulbstatus[0] and bulbstatus[1] and bulbstatus[2]) {
  trace("GOOD JOB!");
 } else {
  trace("TRY AGAIN!");
 }
}
// Array to hold bulbstatus
var bulbstatus = new Array(false,false,false);
// Buttons
this.submit.onRelease = checkstatus;
this.bulb_1.onRelease = function(){ switch_light(1); }
this.bulb_2.onRelease = function(){ switch_light(2); }
this.bulb_3.onRelease = function(){ switch_light(3); }

```

---

<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:** [July 22, 2004, 12:09pm UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/3 "2004-07-22T12:09:07Z")

</div>

Hey thanks Matias.

Functions and arrays! Thank-you for the code, I’ll have a crack at implementing it in my game now…

Cheers

Jaz

---

<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:** [July 22, 2004, 12:47pm UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/4 "2004-07-22T12:47:35Z")

</div>

No problems …

---

<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:** [July 22, 2004, 2:16pm UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/5 "2004-07-22T14:16:34Z")

</div>

Hi Mattias,

I still need a little help to understand your code.

I have created a new .fla, inside is Movie Clip of the lightbulb, it has two frames - each with a stop action, and I have placed 3 of these on the stage and named the instances bulb\_1 bulb\_2 and bulb\_3

Also I have put in the submit button, and named the instance: submit

I’m puzzled by where is the right place to put the function  
switch\_light(bulb) }  
and  
function checkstatus() {  
and the  
Array to hold bulbstatus

Also When I try to add the actions for the buttons, Flash asks me to put them in an event handler - Is this because I’m using MX?

Cheers

Jaz

---

<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:** [July 22, 2004, 7:00pm UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/6 "2004-07-22T19:00:47Z")

</div>

The script (all) goes in the first (whatever) 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:** [July 22, 2004, 10:58pm UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/7 "2004-07-22T22:58:26Z")

</div>

Mattias, you’re a genius. Thank-you!

Jaz

---

<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:** [July 23, 2004, 1:54am UTC](https://forum.kirupa.com/t/simple-kids-game-need-a-little-help-with-variables/116899/8 "2004-07-23T01:54:49Z")

</div>

wow, yea that is some nice programming! clever.

nice games at your site too.
