Page 1 of 1

Code doesnt work as expected.

Posted: Thu Jan 08, 2015 10:59 pm
by Da_Elf
Sorry, i didnt know how else to title this.
Setup: This is for a quiz where there are 8 questions selected at random and knock out each number from the choice each spin
Elements. 8 fields with short name 1aa - 8aa , a button marked new and a button marked spin
First i setup an array of possible numbers 1 - 8 and reset all fld backgroundColors with the "new" button

New Button Code

Code: Select all

global ourArray
global ourArrayMax
on mouseUp
   put 8 into ourArrayMax
   put 1 into advan
   put empty into ourArray
   repeat for ourArrayMax times
      put advan&return after ourArray
      put advan&"aa"into nameofIt
      set the backgroundColor of fld nameofIt to 255,255,255
      add 1 to advan
   end repeat
end mouseUp
when you click spin it will quickly flash the fld green randomly 10 times until the last random color goes red and that number is locked out of future selections. My problem is it doesnt flash green. The code looks fine to me. Did i miss anything?

Spin Button Code

Code: Select all

global ourArray
global ourArrayMax
on mouseUp
   if the number of lines of ourArray <> 0 then
      repeat for 10 times
         put random(ourArrayMax) into theRandomNumber
         answer theRandomNumber
         put line theRandomNumber of ourArray into RandomSelection
         put RandomSelection&"aa" into nameofIt
         answer nameofIt
         set the backgroundColor of fld nameofIt of grp "Quiz 1" to 0,200,0
         wait 200 milliseconds
         set the backgroundColor of fld nameofIt of grp "Quiz 1" to 255,255,255
      end repeat
      put RandomSelection&"aa" into nameofIt
      set the backgroundColor of fld nameofIt of grp "Quiz 1" to 200,0,0
      delete line theRandomNumber of ourArray
      subtract 1 from ourArrayMax
   end if
end mouseUp
Its answering the correct fld names but not changing their color to green within the repeat loop

Re: Code doesnt work as expected.

Posted: Thu Jan 08, 2015 11:50 pm
by dunbarx
Hi.

It works fine for me. OS10.9, LC v. 6.7

Craig

Re: Code doesnt work as expected.

Posted: Fri Jan 09, 2015 12:09 am
by Da_Elf
maybe i just need to update livecode

Re: Code doesnt work as expected.

Posted: Fri Jan 09, 2015 3:44 am
by Da_Elf
ok updated to 6.7.1 and it still didnt work. then realised my problem. I was testing it within livecode interface. When i compiled the program to an exe it worked perfectly

Re: Code doesnt work as expected.

Posted: Fri Jan 09, 2015 6:22 am
by dunbarx
I was testing in the IDE. It would be very strange if it worked as a standalone but not in LC proper.

Craig

Re: Code doesnt work as expected.

Posted: Fri Jan 09, 2015 4:21 pm
by jacque
Livecode won't always redraw the screen inside a tight repeat loop. Try locking and unlocking the screen around the places where you change the color. Unlocking forces a redraw.

Re: Code doesnt work as expected.

Posted: Fri Jan 09, 2015 9:50 pm
by dunbarx
Or include a "wait 0 with messages"

Craig