Small variables problem

I’m working on this small project, a simple scratch card, and I want to make it so that when they scratch 80% of the area (or 60 squares or whatever), it goes to a “you win” section.

here’s what I have so far:

simple scratch card

can I assign variables to buttons?
can i tell it that if 60 or more buttons are rolled over then go to section “you win”?

sorry I’m pretty new at this so please bear with me.

Well assign a variable in on a frame in the timeline.

Lets call it “i” (common variable letter, as is “j”).

so on the frame you will have i = 0

Now on the buttons you will have

on (rollOver){
_root.i++;
}

This is saying that when you rollOver your button _root.i will be have 1 added (_root.i++ is like saying _root.i = _root.i+1)

Ok now also on your buttons to add to the rollover with an if statement to check on how high the variable i is, so your code will now look like this…

on (rollOver) {
_root.i++;
if (_root.i >= 60) {
//gotoCode Here
}

But you wouldn’t want to write all that out on every button, so underneath the i variable on the time line we make a function

i = 0
function checkScratches() {
if (_root.i >= 60) {
//gotoCode Here
}

So now on your buttons your code will look like this…

on (rollOver){
_root.i++;
_root.checkScratches();
}

This will add 1 to the i variable and then run the function checkScratches to see if the variable is over 60 yet.

Did that make ANY sense at all?..lol. I confuse myself a lot.

Brilliant lostinbeta!

works like a charm
=)

Awesome :slight_smile: