need to generate 3 fields with in a set location

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

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Fri Mar 09, 2012 1:31 pm

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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: need to generate 3 fields with in a set location

Post by Klaus » Fri Mar 09, 2012 2:08 pm

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 8)

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

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Fri Mar 09, 2012 3:55 pm

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?

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: need to generate 3 fields with in a set location

Post by Klaus » Fri Mar 09, 2012 3:59 pm

Hi,

hmm, define "random"! :D
I mean what fields should be swapped and how randomly?

This is surely doable!


Best

Klaus (with an U 8) )

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Fri Mar 09, 2012 4:10 pm

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?

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Fri Mar 09, 2012 4:27 pm

thanks

Klaus

(note the u )

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: need to generate 3 fields with in a set location

Post by Klaus » Fri Mar 09, 2012 4:34 pm

HI d.m.holdawayGA2553,

yes, that makes sense :D

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

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Fri Mar 09, 2012 6:10 pm

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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: need to generate 3 fields with in a set location

Post by Klaus » Fri Mar 09, 2012 6:22 pm

Hi dm,

glad I could help!

Did you check these stacks:
http://www.runrev.com/developers/lesson ... nferences/

"Controls" is by me :D


Best

Klaus

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Sun Mar 11, 2012 1:41 am

Controls was fantastic btw..

really helpful.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: need to generate 3 fields with in a set location

Post by Klaus » Sun Mar 11, 2012 1:06 pm

Thank you! :D

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Mon Mar 12, 2012 1:01 pm

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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: need to generate 3 fields with in a set location

Post by Klaus » Mon Mar 12, 2012 1:07 pm

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

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: need to generate 3 fields with in a set location

Post by d.m.holdawayGA2553 » Mon Mar 12, 2012 1:48 pm

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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: need to generate 3 fields with in a set location

Post by Klaus » Mon Mar 12, 2012 2:04 pm

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?

Post Reply