strange behaviour of a Variable inside a loop

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
Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

strange behaviour of a Variable inside a loop

Post by Havanna » Wed Oct 22, 2014 4:35 pm

This command creates a bunch of Fields as buttons inside a group (for scrolling) depending on a variable number of Records in an SQLite Table passed as "SelectorList".
This variable bLeft ( at the *) initially may get 43
at ** I use this to set the Left of my Field.
Nothing else is done to the variable and when I step through the loop, bLeft never changes.
BUT:
the first Field created gets a Left of 39, all the others get the expected 43.
Where am I wrong?

command buildButtonsList SelectorList
global D, F, L, S
lock screen
put empty into S["msg"]
put the top of group "Buttons" +8 into bTop
* put the left of group "Buttons" +8 into bLeft
put (L["ButtonWidth"] - the scrollbarWidth of me) into bWidth

repeat for each element tItem in SelectorList
put "Sel" & tItem["Key"] into selectFieldName
create field selectFieldName in group "Buttons"
# set the behavior of it to the long ID of button "SelectMaster"
set the script of field selectFieldName to the script of button "SelectMaster"
set the cID of field selectFieldName to tItem["Key"]
set the backColor of field selectFieldName to L["Col_FieldBG"]
set the opaque of field selectFieldName to true
set the textSize of field selectFieldName to L["FS_Large"]
set the margins of field selectFieldName to 12
set the unicodetext of field selectFieldName to uniencode (tItem["Info"],"UTF8")

set the locktext of field selectFieldName to true
set the traversalOn of field selectFieldName to false
set the width of field selectFieldName to bWidth
set the height of field selectFieldName to the formattedheight of field selectFieldName
set the top of field selectFieldName to bTop
** set the left of field selectFieldName to bLeft
put the bottom of field selectFieldName +8 into bTop
end repeat

For Information:
this is a sequence of selections with each step producing a different set of buttons, depending on all previous selections, so I mostly have to ( clear and ) rebuild the group.
In the rare case that I want to see the same selection a second time (i. e. just removing all the Fields and building the same list again) all the fields get the correct left of 43.
Beats me!

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

Re: strange behaviour of a Variable inside a loop

Post by dunbarx » Wed Oct 22, 2014 5:14 pm

Hi.

Unlock the screen. When you step through the handler, are the proper values of bLeft and fld selectFieldName all in order? When you execute the line that sets the "left", where does it go? Where should it? Where does the next one go, and how did it get there?

Craig Newman

Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

Re: strange behaviour of a Variable inside a loop - solved

Post by Havanna » Thu Oct 23, 2014 6:47 pm

Thx Craig,

I never thought of unlocking the screen (it makes quie a difference in performance with this kind of operation).
The problem lies in the Position and size properties of a group - they obviously change, whe we add Objects above or farther left than what it previously held.
This certainly deserves some investigation, here I could solve it by creating an (invisible) empty field before looping through the buttons, that works even if I don't give it a position.

Andreas

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

Re: strange behaviour of a Variable inside a loop

Post by dunbarx » Thu Oct 23, 2014 7:10 pm

I am sure you will fix this. And yes, the overall extent of a group can easily change if you meddle with its members.

Unlocking makes the step=by-step examination of this sort of thing accessible, or at least possible.

Craig

Post Reply