Strange sporadic slider behaviour

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

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Strange sporadic slider behaviour

Post by Chibling » Sat Oct 31, 2009 12:35 am

Hello Run Rev Gurus,

I am having a strange phenomenon occur with a slider during a psychology experiment I am conducting. (I am a masters student)

I use a slider to change an image field, and most of the time it works properly all the way through (there are 144 trials).

Today, however, I had the slider go buggy on me and it appears to be an interface problem - possibly with windows XP. (Using Run Rev 2.9).

What happens is that the slider no longer responds properly - you can click on it but it only moves incredibly slow to the left. It is no longer draggable, you can only click it and hold down the mouse as it barely moves to the left. This behaviour continues until the rest of the trials are over. Strangely it happened at trial 93 the one time and 133 the other time.

I am a newb when it comes to programming... if it was a problem with my code shouldn't it always occur? Or is it a problem with the interface of XP and run rev? I should note that this did happen on my XP lap top once and I tried to correct for it by disabling the bar and re-enabling it when it is the participant's time to change the picture.

The code on the bar itself is:

Code: Select all

on scrollbardrag
put the thumbpos of scrollbar "Slider2" into x
set the itemdelimiter to tab
set the fielname of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp"
end scrollbardrag
the rest of my code on the experiment card (note there is lots of copied code and there is a 'demo' at the beginning of each trial):

Code: Select all

global thepath, photopath, datapath, imagelist, Data, voicelist, response, soundpath, listened, responseTime, fName, stimlist, trialnum, responseVal

local maxTrial, maxTrial2

on preopenCard
  hide image "Photo"
  hide player "Voices"
  hide scrollbar "Slider"
  hide scrollbar "Slider2"
  hide button "Next"
  hide button "Replay"
  hide image "fixation"
  hide fld "EndofTime"
  hide fld "EndofExperiment"
  hide fld "Break"
  hide fld "Break2"
  hide button "Resume"
  end preopencard
  
  
  on opencard
  put 72 into maxTrial
  put 144 into maxTrial2
  put 1 into trialnum
  
   beginExperiment
  
end openCard

on beginExperiment

   
   get flushevents("all")
  put 0 into response
  put 0 into listened
   
  if trialnum <= maxTrial then
    show image "fixation"
    wait 1 second
    hide image "fixation"
     
    set the itemdelimiter to tab
    set the filename of player "Voices" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices2" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices3" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices4" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices5" to soundpath&item 7 of line trialnum of stimlist&".wav"
    
    
    set the filename of image "Photo" to empty
     
    show image "photo"
    show scrollbar "Slider"
    
put random (2) into donkey

if donkey = 1 then
start player "Voices2"
disable scrollbar "Slider2" 
disable scrollbar "Slider"
disable button "Next"
disable button "Replay"
put 0 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25+x&".bmp"
  set the thumbposition of scrollbar "slider" to 25+x
  wait 8 milliseconds
  add 1 to x
end repeat
 
put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&50-x&".bmp"
  set the thumbposition of scrollbar "slider" to 50-x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices3"


put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp"
  set the thumbposition of scrollbar "slider" to 25-x
  wait 8 milliseconds
  add 1 to x
end repeat
 
put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp"
  set the thumbposition of scrollbar "slider" to x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices4"
end if

if donkey = 2 then
 start player "Voices2"
 disable scrollbar "Slider2"
 disable button "Next"
 disable button "Replay"
put 0 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp"
  set the thumbposition of scrollbar "slider" to 25-x
  wait 8 milliseconds
  add 1 to x
end repeat

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp"
  set the thumbposition of scrollbar "slider" to x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices3"

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25+x&".bmp"
  set the thumbposition of scrollbar "slider" to 25+x
  wait 8 milliseconds
  add 1 to x
end repeat

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&50-x&".bmp"
  set the thumbposition of scrollbar "slider" to 50-x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices4"

end if
 
 set the itemdelimiter to tab
 put donkey into item 20 of line trialnum of stimlist 
 
show button "Next"
show button "Replay"
 
hide scrollbar "slider"
set the thumbpos of scrollbar "slider2" to 25
enable scrollbar "slider2"
show scrollbar "slider2"
enable button "Next"
 enable button "Replay"

 
put the milliseconds into t1
 
 send "timeout" to me in 15 seconds 

wait until response = 1 with messages
 
if response = 1 then
  put the milliseconds into t2
  put t2 - t1 into responseTime
end if

set itemdelimiter to ","
put item 1 of the pendingMessages into iD
cancel iD
 
set the itemdelimiter to tab 
 
saveData responseTime
 
saveChoice
 
hide image "Photo"
hide player "voices"
hide scrollbar "Slider"
hide scrollbar "slider2"
hide button "Next"
hide button "Replay"
hide image "fixation"
hide fld "EndofTime"
hide fld "EndofExperiment"
 
set the itemdelimiter to tab
put trialnum into item 1 of line trialnum of stimlist
 
add 1 to trialnum
 
beginExperiment
 
else
hide scrollbar "Slider"
hide scrollbar "Slider2"
hide button "Next"
hide button "Replay"
show field "Break"
wait 60 seconds
hide field "Break"
show field "Break2"
show button "Resume"

   
end if
end beginExperiment

on timeout

hide image "Photo"
  hide player "voices"
  hide scrollbar "Slider"
  hide scrollbar "Slider2"
  hide button "Next"
  hide button "Replay"
  show field "EndofTime"
  wait 3 seconds 
  hide field "EndofTime"
  
  set the itemdelimiter to tab
  put trialnum into item 1 of line trialnum of stimlist
  put listened into item 15 of line trialnum of stimlist
  put "T-O" into item 16 of line trialnum of stimlist
put "T-O" into item 17 of line trialnum of stimlist
put "T-O" into item 18 of line trialnum of stimlist
put "T-O" into item 19 of line trialnum of stimlist
  
  add 1 to trialnum
  beginExperiment
  
end timeout

on timeout2

hide image "Photo"
  hide player "voices"
  hide scrollbar "Slider"
  hide scrollbar "Slider2"
  hide button "Next"
  hide button "Replay"
  show field "EndofTime"
  wait 3 seconds 
  hide field "EndofTime"
  
  set the itemdelimiter to tab
  put trialnum into item 1 of line trialnum of stimlist
  put listened into item 15 of line trialnum of stimlist
  put "T-O" into item 16 of line trialnum of stimlist
put "T-O" into item 17 of line trialnum of stimlist
put "T-O" into item 18 of line trialnum of stimlist
put "T-O" into item 19 of line trialnum of stimlist
  
  add 1 to trialnum
  beginExperiment2
  
end timeout2


on saveChoice
  set the itemdelimiter to tab
  if response = 1 then
    put the thumbpos of scrollbar "slider2" into item 17 of line trialnum of stimlist
    put the thumbpos of scrollbar "slider2" into ResponseVal
put listened into item 15 of line trialnum of stimlist
put ResponseVal-25 into item 19 of line trialnum of stimlist
if ResponseVal=25 then
  put "M" into item 18 of line trialnum of stimlist
  end if
if ResponseVal>25 then 
put "R" into item 18 of line trialnum of stimlist
  end if
  if ResponseVal<25 then 
  put "J" into item 18 of line trialnum of stimlist
  end if
end if  
end saveChoice

on saveData x
  set the itemdelimiter to tab
  put x into item 16 of line trialnum of stimlist
end saveData x

On beginExperiment2

get flushevents("all")
  put 0 into response
  put 0 into listened
   
   hide fld "Break"
   hide fld "Break2"
   hide button "Resume"
   hide image "Photo"
  hide player "Voices"
  hide scrollbar "Slider"
  hide scrollbar "Slider2"
  hide button "Next"
  hide button "Replay"
  hide image "fixation"
  hide fld "EndofTime"
  hide fld "EndofExperiment"

   
  if trialnum <= maxTrial2 then
    show image "fixation"
    wait 1 second
    hide image "fixation"
     
    set the itemdelimiter to tab
    set the filename of player "Voices" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices2" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices3" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices4" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices5" to soundpath&item 7 of line trialnum of stimlist&".wav"
    
    
    set the filename of image "Photo" to empty
     
    show image "photo"
    show scrollbar "Slider"
    
put random (2) into donkey

if donkey = 1 then
start player "Voices2"
disable scrollbar "Slider"
disable scrollbar "Slider2" 
disable button "Next"
disable button "Replay"
put 0 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25+x&".bmp"
  set the thumbposition of scrollbar "slider" to 25+x
  wait 8 milliseconds
  add 1 to x
end repeat
 
put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&50-x&".bmp"
  set the thumbposition of scrollbar "slider" to 50-x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices3"


put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp"
  set the thumbposition of scrollbar "slider" to 25-x
  wait 8 milliseconds
  add 1 to x
end repeat
 
put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp"
  set the thumbposition of scrollbar "slider" to x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices4"
end if

if donkey = 2 then
 start player "Voices2"
 disable scrollbar "Slider2"
 disable button "Next"
 disable button "Replay"
put 0 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp"
  set the thumbposition of scrollbar "slider" to 25-x
  wait 8 milliseconds
  add 1 to x
end repeat

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp"
  set the thumbposition of scrollbar "slider" to x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices3"

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25+x&".bmp"
  set the thumbposition of scrollbar "slider" to 25+x
  wait 8 milliseconds
  add 1 to x
end repeat

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&50-x&".bmp"
  set the thumbposition of scrollbar "slider" to 50-x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices4"
end if

set the itemdelimiter to tab
 put donkey into item 20 of line trialnum of stimlist 
 
show button "Next"
show button "Replay"
 
hide scrollbar "slider"
set the thumbpos of scrollbar "slider2" to 25
enable scrollbar "slider2"
show scrollbar "slider2"
enable button "Next"
 enable button "Replay"

put the milliseconds into t1
 
 send "timeout2" to me in 15 seconds 

wait until response = 1 with messages
 
if response = 1 then
  put the milliseconds into t2
  put t2 - t1 into responseTime
end if

set itemdelimiter to ","
put item 1 of the pendingMessages into iD
cancel iD

set the itemdelimiter to tab
saveData responseTime

saveChoice

hide image"Photo"
hide scrollbar "Slider"
hide scrollbar "Slider2"
hide button "Next"
hide button "Replay"
hide image "fixation"

put trialnum into item 1 of line trialnum of stimlist

add 1 to trialnum


beginExperiment2

else
  show field "EndofExperiment"
  wait 5 seconds
  put stimlist into field "Data" of cd "data"
  put stimlist into data
  go to card "data"
  
  put the internet date into y
  put return&"Trialnum"&tab&"Condition"&tab&"Age"&tab&"Language"&tab&"Sex"&tab&"ImageName"&tab&"WordName"&tab&"Con1"&tab&"Vow1"&tab&"Con2"&tab&"Vow2"&tab&"Wordtype"&tab&"1stcontype"&tab&"RealWord?"&tab&"#Replays"&tab&"RT"&tab&"ResponseValue"&tab&"ResponseType"&tab&"Magnitude"&tab&"MvDirection" after y
  put "file:"&DataPath&"D"&the ticks into fName
  put y&return&Data into URL fName

end if
end beginExperiment2
Is there any way I can avoid the buggy slider problem?

Thanks in advance

-Brandon :oops:

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Sat Oct 31, 2009 12:10 pm

Brandon,
that is a tough question. I just give it a try maybe someone else has more to say.
From what I gather from your code you have an experiment running and, here I am not shure, while the experiment is running someone slides the slider. This changes the image displayed in "photo".

The lock-up/slow-down of rev can happen, if Rev does not have time enough to do housekeeping in long handlers. I just suppose this happens. To avoid this you could append your wait statements with a "with messages". This should give Rev more room to breathe. Sometimes you do a wait with messages but mostly you dont. It is worth a try.

I noticed that you set the slider2 from within the long script and the slider sets itself a photo like in this line

Code: Select all

set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp" 
set the thumbPosition of scrollbar "slider" to 25-x 
it seems that you do twice the same. If that is correct you could say

Code: Select all

set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp" 
lock messages
set the thumbPosition of scrollbar "slider" to 25-x
unlock messages 
this sets the thumbposition but does not trigger the scrollbardrag message.

If wait with messages does not prevent the slow-down then you would have to tell us a little more about the user interaction during the test.
You might want to have a look at the difference between blocking handlers and non-blocking handlers in the Revolution Resource Center under the help menu in the Sample Scripts part -> Applications. "Displaying a count down (blocking)" and Displaying a count-down (non-blocking).

regards
Bernd

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Post by Chibling » Mon Nov 02, 2009 3:28 am

Hello Bernd,

I am not sure I understand what you are suggesting I do.

I changed

Code: Select all

hide scrollbar "slider" 
set the thumbpos of scrollbar "slider2" to 25
to

Code: Select all

hide scrollbar "slider" 
lock messages
set the thumbpos of scrollbar "slider2" to 25
unlock messages


I did this twice for "experiment" and "experiment2" (it is divided in half around a 1 minute break)

However, I tested it out tonight and the slider2 was still bugged... it is very strange, I don't think it is a slow down in processing because it does not allow you to shift it the slider button - only to click it and watch it move to the left very slowly. Why to the left? I have no idea.

It seems to happen after a "timeout" or "timeout2" but I cannot be sure...

Thank you for the response,

Any other ideas would be helpful,

-Brandon

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Post by Chibling » Mon Nov 02, 2009 4:31 am

I just appended "with messages" to the waits and it still seems to get bogged down. I suppose the program gets bogged down/ slowed down and then messes up, that is why it seems to have no pattern? This is frustrating, perhaps I need to program it more efficiently to reduce strain...

-Brandon

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Mon Nov 02, 2009 11:23 am

Brandon,
if you dont need to scroll through all the images with the scrollbar then you could try this:
put a mouseUp handler into the scrollbar instead of the scrollbardrag. The handler would look like this

Code: Select all

-- initialise any globals you need here
-- photopath, trialnum stimlist 
on mouseUp 
put the thumbpos of scrollbar "Slider2" into x 
set the itemdelimiter to tab 
set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp" 
end mouseUp
This way the handler only fires once when the user has made his choice and not many times as with the scrollbardrag (every little move of the scrollbar triggers the loading of an image, even if it is the same image).
From what I see you could eliminate the whole scrollbardrag handler without problem, just the mouseUp
tell us if that helps.
regards
Bernd

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Post by Chibling » Mon Nov 02, 2009 9:56 pm

I tried switching from the scrollbardrag to "onmouseup", however, the bugged slide bar still occurred after a few trials and time-outs (testing it out myself). I think it has something to do with the 'timeout' code because after it has timed out a few that is when it seems to occurs... but i'm not sure.

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Post by Chibling » Mon Nov 02, 2009 11:11 pm

I have a "demo" card that basically demonstrates what a trial is like, however, that scrollbar and the one on the experiment card act very differently. The scrollbar on the democard requires that you click the actual button and move it - while the scrollbar on the experiment card moves no matter where you click on the scrollbar. (I would prefer the way the demo card behaves over that of the experiment card)

I am not sure what would change but they use almost the exact same code...

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Post by Chibling » Mon Nov 02, 2009 11:25 pm

When the scrollbar is moved by clicking on the bar (not the button that moves) one of the messages sent is "ScrollbarPageDec" I will look into this, but does anyone know what that means?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Tue Nov 03, 2009 12:09 am

Chibling,
in the property inspector you can set the amount of pageincrement of the scrollbar that a click produces. Any scrollbar should react to a click, just the pageincrement can be different.
regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Tue Nov 03, 2009 12:46 am

Chibling,
I am looking at your code and try to find out what is going on. Just from the code without a working stack I find it hard to figure it out but here is another guess:
add 1 to trialnum
beginExperiment2

end timeout2
in this piece of code you call your handler beginExperiment2 but the timeout2 handler will not finish before beginExperiment2 is finished. On the other hand beginExperiment2 sends a message to timeout2. This could be a problem, not shure. In any case you could just say

Code: Select all

  add 1 to trialnum 
   send beginExperiment2 to me in 2 milliseconds
end timeout2 
this would effectively free up the timeout2 handler and you restart your experiment. The same goes for the timeout handler.
It is worth a try and will not change the functionality of your stack.
set itemDelimiter to ","
put item 1 of the pendingMessages into ID
cancel ID
here you try to delete the timeout message, I am not shure, you always delete the timeout message, because if any other message is there at the first line of the pendingmessages you would delete that instead of the timeout message. You might want to code something like this

Code: Select all

set itemDelimiter to ","
 repeat for each line l in the pendingMessages
    if item 3 of l is "timeout" then
      cancel item 1 of l
      end if
  end repeat
which will eliminate any pending timeout message, not any other. The same goes for timeout2

As I said, just a couple of thoughts, you might try this and see if it helps.

regards
Bernd[/code]

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am
Location: Australia

Post by Regulae » Tue Nov 03, 2009 5:23 am

Hi Brandon,

It’s clear from your code that the project is well advanced, with the actual experimental design resolved such that it can be run repeatedly. It is at this point that an unanticipated and intermittent performance problem has emerged.

It is especially possible in projects that are highly “cyclicâ€
Necessaria est methodus ad rerum veritatem investigandam

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am
Location: Australia

Post by Regulae » Tue Nov 03, 2009 6:45 am

I have spotted one oversight already- beginExperiment loads the variable t1, which is used by ValidResponse. I neglected to declare it as global.

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am
Location: Australia

Post by Regulae » Tue Nov 03, 2009 3:37 pm

I'm afraid I missed another one. The line:
put item 6 of line trialNum of stimList into imageName
... in beginExperiment. imageName is needed by CycleImagesUp and
CycleImagesDown, and thus should be global as well, to be available to
these handlers.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Tue Nov 03, 2009 3:54 pm

@regulae
IV
Necessaria est methodus ad rerum veritatem investigandam
is it you, René?
regards
Bernd

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am
Location: Australia

Post by Regulae » Tue Nov 03, 2009 5:04 pm

I fear that I have rather let the illustrious Frenchman down- had I employed more "method" in checking my scripts, I should not have had to post so many corrections. I hope we can get to the bottom of the scrollbar mystery.

Regards,

Michael

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”