Code doesnt work as expected.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Code doesnt work as expected.

Post by Da_Elf » Thu Jan 08, 2015 10:59 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Code doesnt work as expected.

Post by dunbarx » Thu Jan 08, 2015 11:50 pm

Hi.

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

Craig

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Code doesnt work as expected.

Post by Da_Elf » Fri Jan 09, 2015 12:09 am

maybe i just need to update livecode

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Code doesnt work as expected.

Post by Da_Elf » Fri Jan 09, 2015 3:44 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Code doesnt work as expected.

Post by dunbarx » Fri Jan 09, 2015 6:22 am

I was testing in the IDE. It would be very strange if it worked as a standalone but not in LC proper.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Code doesnt work as expected.

Post by jacque » Fri Jan 09, 2015 4:21 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Code doesnt work as expected.

Post by dunbarx » Fri Jan 09, 2015 9:50 pm

Or include a "wait 0 with messages"

Craig

Post Reply