Moving Numbers..?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Moving Numbers..?
Hi
I'm really not sure how to do this, so again help would really be appricated:
What I have is a table of 40 push buttons each with their our seperate number, and four output field for the numbers to be displayed as they are entered,
the user clicks on a number which fills the first output field, the user clicks on another number and that fills the second output field, same with the third and same with the fouth...
Now there are four numbers displayed in four boxes. Once there are four numbers enetered when the fifth number is clicked from the push button table, I need all the numbers to shift one to the left allowing the last numbers entered to be in the fourth field box, the first number will have replaced. Basically all the numbers will keep shifting one to the left towards the first number, pushing that one out for as long the user keeps clicking on any button in the table..?
I have an idea this would be done using an array but not sure how...
Thanks in advance
I'm really not sure how to do this, so again help would really be appricated:
What I have is a table of 40 push buttons each with their our seperate number, and four output field for the numbers to be displayed as they are entered,
the user clicks on a number which fills the first output field, the user clicks on another number and that fills the second output field, same with the third and same with the fouth...
Now there are four numbers displayed in four boxes. Once there are four numbers enetered when the fifth number is clicked from the push button table, I need all the numbers to shift one to the left allowing the last numbers entered to be in the fourth field box, the first number will have replaced. Basically all the numbers will keep shifting one to the left towards the first number, pushing that one out for as long the user keeps clicking on any button in the table..?
I have an idea this would be done using an array but not sure how...
Thanks in advance
Re: Moving Numbers..?
TopCat,
try this:
on a teststack you create 4 fields. One ore more buttons that have the above script. This does what I understand what you want, no array necessary. Of course since I dont know what numbers you want to put into the fields I just took the counter of clicks. Since it is now in a custom property of the card you would have to reset the cMouseClicks by putting 0 into it on initialization.
try this:
Code: Select all
on mouseUp
put the cMouseClicks of this card into tClicks
add 1 to tClicks
set the cMouseClicks of this card to tClicks
put tClicks mod 4 into tWhatField
if tWhatField = 0 then
put 4 into tWhatField
end if
-- first round
if (field 4 is "" )then
-- here would be your real number for this button instead of tClicks
put tClicks into field tWhatField
-- subsequent rounds
else
lock screen
repeat with i = 2 to 4
put field i into field (i-1)
end repeat
-- here would be your real number for this button instead of tClicks
put tClicks into field 4
end if
end mouseUp
Code: Select all
put 0 into the cMouseClicks of this card
Re: Moving Numbers..?
bn's script looks like it should work fine. But since you only have four output fields, try putting this into the card script. On a new card, I made four fields, and a bunch of buttons that were named "B1", "B2", B3"...
Brute force, but with only four fields it doesn't need much elegance. The buttons need have no scripts in them as the card catches all mouseUp messages. Of course you can name or number your objects as you see fit, but this short script should do fine. You may want to make a button that clears the fields, and make sure it does not pass "mouseUp" to the card.
Craig Newman
Code: Select all
on mouseup
if the target contains "button" then
put fld 3 into fld 4
put fld 2 into fld 3
put fld 1 into fld 2
put char 2 of the short name of the target into fld 1
end if
end mouseup
Craig Newman
Re: Moving Numbers..?
Topcat,
Craigs wonderfull idea to put all the code into the card script makes it a lot easier to maintain 40 buttons. I dont know what the numbers look like that you want the buttons to put into the fields. If the same button always puts the same number then you could take any button without script and set its label to the number you want. This number will be shown on the button. then you could put this code into the card script:
You still have to initialize the fields and the custom property but a button with this script would do: since this initialization button does not pass mouseUp (it handles it himself without passing) your card script will not get the mouseUp message. All other mouseUp messages from e.g. clicking into a card or an image will be filtered out by the card script by making shure that the target is a button.
regards
Bernd
@Craig: the script is a bit convoluted since topcat wanted the fields to be filled from left to right for the first four clicks and subsequent clicks should push the numbers from right to left, I didn't find an easier way to take this into account.
Craigs wonderfull idea to put all the code into the card script makes it a lot easier to maintain 40 buttons. I dont know what the numbers look like that you want the buttons to put into the fields. If the same button always puts the same number then you could take any button without script and set its label to the number you want. This number will be shown on the button. then you could put this code into the card script:
Code: Select all
on mouseUp
if the target contains "button" then
put the cMouseClicks of this card into tClicks
add 1 to tClicks
set the cMouseClicks of this card to tClicks
-- this assumes that the buttons have a label set to the number they should represent
put the label of the target into tTargetLabelNumber
-- first round
if (field 4 is "" )then
put tClicks mod 4 into tWhatField
if tWhatField = 0 then
put 4 into tWhatField
end if
-- here would be your real number for this button instead of tClicks
put tTargetLabelNumber into field tWhatField
-- subsequent rounds
else
lock screen
repeat with i = 2 to 4
put field i into field (i-1)
end repeat
-- here would be your real number for this button instead of tClicks
put tTargetLabelNumber into field 4
end if
end if
end mouseUp
Code: Select all
on mouseUp
repeat with i = 1 to 4
put "" into field i
end repeat
set the cMouseClicks of this card to 0
end mouseUp
regards
Bernd
@Craig: the script is a bit convoluted since topcat wanted the fields to be filled from left to right for the first four clicks and subsequent clicks should push the numbers from right to left, I didn't find an easier way to take this into account.
Re: Moving Numbers..?
Hi All,
Thank you for all the replies. I did try Craig's first as it was the simplist and apart from having to add the "field" infront of the"fld1" other wise they would not load from the right hand side ( I needed them to shift one step to the left when moving) that worked well.
The next thing I need to do is create a filter to catorgoise the answer into Low, Med or High and place L,M or H into the fld's not the actual number...
So I need to say something like:
if label of target is within range 1-12 then put "L" into field "fld1"
if label of target is within range 13-24 then put "M" into field "fld1"
if label of target is within range 25-36 then put "H" into field "fld1"
thanks
Thank you for all the replies. I did try Craig's first as it was the simplist and apart from having to add the "field" infront of the"fld1" other wise they would not load from the right hand side ( I needed them to shift one step to the left when moving) that worked well.
The next thing I need to do is create a filter to catorgoise the answer into Low, Med or High and place L,M or H into the fld's not the actual number...
So I need to say something like:
if label of target is within range 1-12 then put "L" into field "fld1"
if label of target is within range 13-24 then put "M" into field "fld1"
if label of target is within range 25-36 then put "H" into field "fld1"
thanks
Re: Moving Numbers..?
topcat,
try
regards
Bernd
try
Code: Select all
if the target contains "button" then
put the label of the target into tLabel
if tLabel > 0 and tLabel < 13 then put "low" into field 1
if tLabel > 12 and tLabel < 25 then put "medium" into field 1
if tLabel > 24 and tLabel < 37 then put "high" into field 1
end if
Bernd
Re: Moving Numbers..?
Great thanks...
If I have said this:
After a hit, but whilst there is no match, how do I get "fldOut" to show nothing (to clear)..? I have tried adding:
but that doesn't work..?
Thanks
If I have said this:
Code: Select all
if field "fld4" = "L" and field "fld1" = "L" then put "L" into field "fldOut"
if field "fld4" = "M" and field "fld1" = "M" then put "M" into field "fldOut"
if field "fld4" = "H" and field "fld1" = "H" then put "H" into field "fldOut"
Code: Select all
else
clear field "fldOut"
end if
Thanks
Re: Moving Numbers..?
topcat,
the easiest would be :
that way you clear field "fldOut" first and only if any of the conditions are true you get any text in field "fldOut"
regards
Bernd
the easiest would be :
Code: Select all
put empty into field "fldOut"
if field "fld4" = "L" and field "fld1" = "L" then put "L" into field "fldOut"
if field "fld4" = "M" and field "fld1" = "M" then put "M" into field "fldOut"
if field "fld4" = "H" and field "fld1" = "H" then put "H" into field "fldOut"
regards
Bernd
Re: Moving Numbers..?
It so simple when you know.! Thanks :~)