Page 1 of 2
need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 1:31 pm
by d.m.holdawayGA2553
hello,
i am trying to create 3 fields within a set location
i am using templatefield to define the field.
Code: Select all
reset the templateField
set the style of the templateField to "transparent"
set the borderwidth of the templateField to "1"
set the showname of the templateField to "false"
set the width of the templateField to "106"
set the icon of templateField to "1001"
set the height of the templateField to "40"
set the visible of the templateField to "true"
set the autohilite of the templateField to "false"
set the sharedhilite of the templateField to "false"
set the traversalon of the templateField to "false"
set the threed of the templateField to "false"
set the hiliteborder of the templateField to "false"
and then to generate the fields i am using
Code: Select all
put any item of "A,B,C" into pShape
if pShape = "A" then createShapeA
if pShape = "B" then createShapeB
if pShape = "C" then createShapeC
then using
Code: Select all
on createShapeA
set templateField to loc 54,40
set the label of the templatefield to "fieldA"
set the icon of the templatefield to "1102"
set the name of the templatebutton to "fieldA"
create field ("field" & pShape) in group "shape"
end createShapeA
i think i am really close with this, the issue / issues i have is
i want to keep generating and replacing fields the issue i have is that i might need field A to move into where field b is and vis versa
so is there a way i can just just move them along kinda like a conveyor belt or can i just randomly rename them with out moving them?
any advice is well come at this stage.
thanks
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 2:08 pm
by Klaus
Hi d.m.....................
first: fields do not have an ICON properrty!
Setting this for the templatefield does give an error but does not make sense
For "moving" your fields you could simply "swap" the RECT of the two fields you want to "relocate":
Code: Select all
command Swap_Field_Rects tField1, tField2
put the rect of fld tField1 into tRect1
put the rect of fld tField2 into tRect2
lock screen
set the rect of fld tField1 to tRect2
set the rect of fld tField2 to tRect1
end Swap_Field_Rects
Then use it like this in your handlers:
Code: Select all
...
## Simply pass the NAMES of the fields you want to swap
Swap_Field_Rects "Field A","Field B"
...
Get the picture?
I hope I understood your problem correctly
Best
Klaus
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 3:55 pm
by d.m.holdawayGA2553
Klas,
that is really good your understanding of my problem was excellent, thanks for taking the time to help.
is there a way of making the swap more random?
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 3:59 pm
by Klaus
Hi,
hmm, define "random"!
I mean what fields should be swapped and how randomly?
This is surely doable!
Best
Klaus (with an U

)
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 4:10 pm
by d.m.holdawayGA2553
well you have 3 fields
and they need to appare in random order
so it might be
fieldA - fieldB - fieldC
then after 2 seconds they swap round so it might be
fieldC - fieldB - fieldA
and so on
does that make sense?
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 4:27 pm
by d.m.holdawayGA2553
thanks
Klaus
(note the u )
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 4:34 pm
by Klaus
HI d.m.holdawayGA2553,
yes, that makes sense
OK, I would do it this way:
1. get the rects of all 3 buttons
2. randomize the rects -> sort... by random(YYYY)
3. Apply the rects back to the fields
4. Do this every 2 seconds on this card until the user closes/leaves the card.
Is that what you need?
Please check "send" and "sort" in the dictionary!
OK, put this into the CARD script:
Code: Select all
## We are going to use "send ... in ..." so we need to store the ID
## of this message in order to CANCEL it when the card closes!
local tRandomizeFieldsMessageID
on opencard
## Your opencard stuff here...
## ...
## ME is the card here and we will "fire" this message every 2 seconds
send "RandomizeFields" to me in 2 secs
put the result into tRandomizeFieldsMessageID
end opencard
## We need to CANCEL the message here:
on closecard
cancel tRandomizeFieldsMessageID
end closecard
command RandomizeFields
## We buold a CR delimited list of the rects:
put the rect of fld "FieldA" into tRects
put CR & the rect of fld "FieldB" after tRects
put CR & the rect of fld "FieldC" after tRect
## Now we sort this list randomly
sort lines of tRects by random(123456789)
## Apply them back to the fields:
lock screen
set the rect of fld "FieldA" to line 1 of tRects
set the rect of fld "FieldB" to line 2 of tRects
set the rect of fld "FieldC" to line 3 of tRects
unlock screen
## let it happen again in 2 seconds
send "RandomizeFields" to me in 2 secs
put the result into tRandomizeFieldsMessageID
end RandomizeFields
Not tested but should work
Best
Klaus
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 6:10 pm
by d.m.holdawayGA2553
Klaus,
i want to thank you so much for the excellent example, its taken me off in a whole different way of thinking and problem solving.
so thanks
Re: need to generate 3 fields with in a set location
Posted: Fri Mar 09, 2012 6:22 pm
by Klaus
Hi dm,
glad I could help!
Did you check these stacks:
http://www.runrev.com/developers/lesson ... nferences/
"Controls" is by me
Best
Klaus
Re: need to generate 3 fields with in a set location
Posted: Sun Mar 11, 2012 1:41 am
by d.m.holdawayGA2553
Controls was fantastic btw..
really helpful.
Re: need to generate 3 fields with in a set location
Posted: Sun Mar 11, 2012 1:06 pm
by Klaus
Thank you!

Re: need to generate 3 fields with in a set location
Posted: Mon Mar 12, 2012 1:01 pm
by d.m.holdawayGA2553
Klaus,
do you know how i can load a default value into the scrollbar ?
i followed your " controls " example but could no work it out.
could i set a local Variable sDefaultvalue
Code: Select all
local sDefaultvalue
put "30" into sDefaultvalue
set startvalue of scrollbar "name of scrollbar" to sDefaultvalue
on scrollbardrag
set startvalue to sDefaultvalue
put the thumbpos of me into sUsertimer
end scrollbardrag
Re: need to generate 3 fields with in a set location
Posted: Mon Mar 12, 2012 1:07 pm
by Klaus
d.m.holdawayGA2553 wrote:...do you know how i can load a default value into the scrollbar ?
??? Set startvalue resp. endvalue?
Code: Select all
local sDefaultvalue
put "30" into sDefaultvalue
set startvalue of scrollbar "name of scrollbar" to sDefaultvalue
on scrollbardrag
set startvalue to sDefaultvalue
put the thumbpos of me into sUsertimer
end scrollbardrag
The code seems correct, but this is never triggered, because it is outside of and handler!
You could use "mouseenter" in the SCROLLBAR to set the initial values:
Code: Select all
on mouseenter
set the startvalue of me to 30
end mouseenter
on scrollbardrag
put the thumbpos of me into sUsertimer
end scrollbardrag
Is that what you are looking for?
Best
Klaus
Re: need to generate 3 fields with in a set location
Posted: Mon Mar 12, 2012 1:48 pm
by d.m.holdawayGA2553
Code: Select all
global sDefaultvalue
on scrollbardrag
put "30" into sDefaultvalue
set startvalue of scrollbar "name of scrollbar" to sDefaultvalue
set startvalue to sDefaultvalue
put the thumbpos of me into sUsertimer
end scrollbardrag
Re: need to generate 3 fields with in a set location
Posted: Mon Mar 12, 2012 2:04 pm
by Klaus
d.m.holdawayGA2553 wrote:
Code: Select all
global sDefaultvalue
on scrollbardrag
put "30" into sDefaultvalue
set startvalue of scrollbar "name of scrollbar" to sDefaultvalue
## set startvalue to sDefaultvalue
put the thumbpos of me into sUsertimer
end scrollbardrag
??? Does this work for you?