Scrollbardrag path problem

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Scrollbardrag path problem

Post by Chibling » Wed Sep 02, 2009 11:31 pm

Hello all,

I am trying to get my scroll bar to 'on the fly' change an image field, I am using the following code on the scrollbar:

global stimlist, photopath, trialnum

Code: Select all

on scrollbardrag
  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 scrollbardrag
The problem is that the image is not obtaining the proper information in that it does not include "item 6 of line trialnum of stimlist" but simply has the "-" and the thumbposition (eg. -50). However, when I directly input a 1 or 2 (image names) then the scrollbar and images update as desired.

How do I get the scrollbardrag to understand the stimlist variable that I have compiled? Strangely, when I used very similar code:

Code: Select all

put 0 into x
    repeat until x>50
      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 10 milliseconds
      add 1 to x
    end repeat
in the actual card, not the scrollbar, it does what it is supposed to. It is as if the scrollbar does not understand my stimlist container yet the actual card does.

After deleting all the code from my "experiment" card it appears that the scrollbardrag then 'understands' what 'item 6 of line 1 of stimlist' means (not trialnum because this is specified in the experimental card). It appears as if there are some conflicts in my code... Any suggestions would be helpful, is it possible to use the "on scrollbardrag" message in my card code? Should I use 2 separate cards to avoid conflicts?

Any suggestions would be helpful

-Brandon

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Sep 03, 2009 12:09 am

Hi Chibling,
on scrollbardrag
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 scrollbardrag
I dont see in your code of the scrollbar how this handler is to know what your variables are. Are they globals? Did you declare them on top of the handler of the scrollbar? That might be the problem.
Also watch out, the scrollbar often gives you a floating point value, although it looks like an integer on the scrollbar. You might use trunc(x) to get at the integer part of the value.
On scrollbardrag has a parameter that is the thumbposition. You could write:

Code: Select all

global photopath, trialnum, stimlist

on scrollbardrag x
  put trunc(x) 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 scrollbardrag 
You would have to declare these same globals also at the point where you introduce them. You could also put these values into fields and then read from the fields in your scrollbar handler, but that is slower and not really good practice, but has the advantage that you and your handler know where the information is. You might want to look up global in the dictionary, and in the user guide pdf, it is pretty well explained.
Regards
Bernd

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

Post by Chibling » Thu Sep 03, 2009 12:34 am

Thank you Bernd for the fast reply,

I did find the problem... a novice mistake... "trialnum" was indeed a local variable - once it was switched to a global variable the scrollbar could then "understand" what I was telling it. Sometimes the simplest mistakes can be deceiving. I was hoping that I could reply to my forum post before anyone wasted their time on me!

Thank you again,

Brandon

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Sep 03, 2009 10:55 am

Chibling,
glad you found it.
There is no problem with asking puzzling questions in this forum, may they be 'novice' or 'oldice', what helps is to post the pertaining parts of the script, not just the part where the error occurs (which I concede is difficult at times since the error can start in a whole different handler).

This is just to say please feel welcome to ask.

BTW it looks like you are doing psychological research with runrev. It seems it lends itself to that. There are some people on this forum that use it for that.
see this thread for instance:
http://forums.runrev.com/phpBB2/viewtop ... psychology

regards
Bernd

Post Reply