View Full Version : Button Sequence Game
captainghost
06-20-2007, 06:32 PM
Im making a game where you have to push certain buttons in the correct order so it moves you to the next stage...
I have everything ready to go, graphics, buttons, etc...but I dont know what code I would enter so that when I play buttons A, C, D it moves to a new page.
my buttons are:
btnA
btnB
btnC
btnD
Im assuming that the function for each button should check the correct order in an array where ive stored them...but I dont know what kind of code you would use...can anyone help me??
Thanks!!
drexle
06-20-2007, 07:02 PM
Is it the comparisson you're having problems with, or the loading of a new "page?" Are you planning on having each "page" be a separate HTML page with its own swf file embedded, or are you planning on having all the "pages" stored in one swf file?
If it's the former you're stuck on, the array idea is a good one. Just store the instance names of the buttons you want to test in the array and declare a counter set to 0 that increments if array[counter]==button._name. Then if it increments you check the value of your counter against the array.length and if the counter is larger then you have clicked all necessary buttons and it is time to go on to the next "page." If the user clicks the wrong button, you should set your counter back to 0 so that the user has to start over again. Also, Once you go to the next page, remember to reset your counter to 0.
Is that helpful?
captainghost
06-20-2007, 07:12 PM
kind of...I understand the theory behind it, im just not sure how to apply it. The other screens it will be going to are on the same timeline.
I dont know the proper application of the code to fit the theory.
I dont know how to store the instances in an array
Hi,
Rather than store the instances, you can store a letter that represents the instances.
So the first button can add letter "A" to the array when it's clicked on, second button can add letter "B", etc.
This array can be something like
var current_btn_seq:Array = new Array();
So if the first button is clicked on, it can add a letter to the array with
_root.current_btn_seq.push("A");//for button A
You can write a function that compares this current button sequence with a desired button sequence via for loop.
If that didn't make much sense, here is an fla file for one possible approach to do the problem.(It's for a sequence of 3, but it shouldn't be too hard to extend to 4.)
captainghost
06-21-2007, 01:52 PM
thanks so much! ill give it a try!
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.