Simple kids game - need a little help with variables

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”) {
} else {

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:

// Functions
function switch_light(bulb) {
  bulbstatus[bulb-1] = false;
 } else {
  bulbstatus[bulb-1] = true;
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); }

Hey thanks Matias.

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



No problems …

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) }
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?



The script (all) goes in the first (whatever) frame.

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


wow, yea that is some nice programming! clever.

nice games at your site too.