Question

So I have a quiz I'm making using Adobe director, but I'm struggling with the overall environment.

I'm adding the following Lingo script to each button with a correct answer:

  on mouseDown
    global gscore
    set gscore = gscore + 1

And on the final stage, I use the following Lingo script to check the acquired points, and display the appropriate sprite for the result.

on enterFrame
  if gscore = 0 then set the memberNum of sprite (3) to 154
end if
  if gscore = 1 then set the memberNum of sprite (3) to 155
end if
  if gscore = 2 then set the memberNum of sprite (3) to 156
end if
  if gscore = 3 then set the memberNum of sprite (3) to 157
end if
  if gscore = 4 then set the memberNum of sprite (3) to 158
end if
  if gscore = 5 then set the memberNum of sprite (3) to 159
end if
end

So my errors seem to say there is no declared variable, but it's global right? So how come it doesn't recognise it. The first script is attached to the buttons corresponding to correct answers, each button has a seperate script to send it to the next question. The final stage which is meant to display the results should display a certain custom sprite dependant on the value of gscore.

Was it helpful?

Solution 2

Figured it out, appologies.

I removed all the end if's to make it a complete if statement. Set the global variable on the first script used declaring the value as 0. Then later when incrementing it is adding to a previously defined global variable of the same name.

I believe my problem lay in global variable instances default value being void.

OTHER TIPS

Glad you figured out a solution. Another approach would have been to not use if statements at all. Your enterframe script could have read like this:

on enterframe sprite(3).memberNum = 154+gscore end

on exitframe me
   global gscore

.

if gscore = 0 
   set the memberNum of sprite (3) to 154
else  if gscore = 1 then 
    set the memberNum of sprite (3) to 155
else if gscore = 2 then 
   set the memberNum of sprite (3) to 156
else if gscore = 3 then 
    set the memberNum of sprite (3) to 157
else if gscore = 4 then 
    set the memberNum of sprite (3) to 158
else  if gscore = 5 then 
  set the memberNum of sprite (3) to 159
end if

end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top