Using "backgroundColor" to count....
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Using "backgroundColor" to count....
I want to keep track of buttons which
have been clicked. As the "backgroundColor"
changes when clicked I've tried to use that
to count the number of buttons clicked but
not been able to get a result so far.
repeat with i = 1 to 30
put "btn" & i into btnTarget
if backgroundColor of button btnTarget not "200,255,255" then
add 1 to cTot
end if
end repeat
put cTot into field lblColorCount
Suggestions appreciated.
have been clicked. As the "backgroundColor"
changes when clicked I've tried to use that
to count the number of buttons clicked but
not been able to get a result so far.
repeat with i = 1 to 30
put "btn" & i into btnTarget
if backgroundColor of button btnTarget not "200,255,255" then
add 1 to cTot
end if
end repeat
put cTot into field lblColorCount
Suggestions appreciated.
Life is just a bowl of cherries.
-
- Livecode Staff Member
- Posts: 53
- Joined: Tue Jun 03, 2008 10:31 am
Visited Property
Hi
You can use the 'visited' property of the button. When a button is clicked, the visited property will be true.
put the visisted of button 'x'
If you are trying to be a little more advanced and track items over a longer period I would use a custom property which I set to 'true' or a count everytime the button is clicked. You can then iterate of the controls of your stack and check your own custom property.
I hope that helps.
Ben
You can use the 'visited' property of the button. When a button is clicked, the visited property will be true.
put the visisted of button 'x'
If you are trying to be a little more advanced and track items over a longer period I would use a custom property which I set to 'true' or a count everytime the button is clicked. You can then iterate of the controls of your stack and check your own custom property.
I hope that helps.
Ben
Ben Beaumont | Runtime Revolution
bjb,
What you are trying to do might be possible, but I wouldn't recommend your approach.
You can use the visited property, but often this doesn't give me sufficient control. For example, navigating through cards automatically resets the visited property, which is not always desired.
You should save the status of a button in a custom property (there are other acceptable solutions, of course). Try this:
Now you can get the number of buttons the were clicked on by the user:
You also need a way to reset the custom properties.
Best,
Mark
What you are trying to do might be possible, but I wouldn't recommend your approach.
You can use the visited property, but often this doesn't give me sufficient control. For example, navigating through cards automatically resets the visited property, which is not always desired.
You should save the status of a button in a custom property (there are other acceptable solutions, of course). Try this:
Code: Select all
on mouseUp
set theButtonClicked of the target to true
-- rest of your script here
end mouseUp
Code: Select all
function buttonsClicked
put 0 into myCounter
repeat with x = 1 to number of buttons
if the theButtonClicked of btn x is true then
add 1 to myCounter
end if
end repeat
return myCounter -- myCounter buttons have been clicked
end buttonsClicked
Code: Select all
on preOpenStack
repeat with x = 1 to number of buttons
set theButtonClicked of btn x to false
end repeat
pass preOpenStack
end preOpenStack
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Using "backgroundColor" to count....
This line gives me an error!bjb007 wrote:...
if backgroundColor of button btnTarget not "200,255,255" then
..
One of these lines does not:
Code: Select all
...
if backgroundColor of button btnTarget IS NOT "200,255,255" then
...
if backgroundColor of button btnTarget <> "200,255,255" then
...
Using "backgroundColor" to count....
Thanks to you all.
Problem with trying the various alternatives
was that some of them gave an error saying
that the "then" was missing from the "if"
statement when it wasn't, so couldn't test
all possibilities because when this
message appeared and I saved and ran
an error came up for the "on mouseup"
button code.
Very strange.
Problem with trying the various alternatives
was that some of them gave an error saying
that the "then" was missing from the "if"
statement when it wasn't, so couldn't test
all possibilities because when this
message appeared and I saved and ran
an error came up for the "on mouseup"
button code.
Very strange.
Life is just a bowl of cherries.
Hi bjb007
I've had this prob big time a couple of weeks ago and it took me hours to work out what was going on (including pairing down my if...then statement to one line). At a guess, if your stack includes a substack, your prob might be from similar cause:
Put a blank preOpenStack, OpenStack and/or CloseStack handler in your subStack script (depending what you've put in your main stack script); then possibly put your script in an onOpenCard handler.
Hope that sorts it for you...

PS Why it jumps at watertight, good ol' if...then statements as an error, Ive no idea...
I've had this prob big time a couple of weeks ago and it took me hours to work out what was going on (including pairing down my if...then statement to one line). At a guess, if your stack includes a substack, your prob might be from similar cause:
Put a blank preOpenStack, OpenStack and/or CloseStack handler in your subStack script (depending what you've put in your main stack script); then possibly put your script in an onOpenCard handler.
Hope that sorts it for you...

PS Why it jumps at watertight, good ol' if...then statements as an error, Ive no idea...
Using "backgroundColor" to count....
gyroscope
In my case the problem definitely was
something to do with the "if" statement
because when I commented it out
both errors disappeared.
Must be one of the "Magnificent 400"
bugs in 2.8.1!
In my case the problem definitely was
something to do with the "if" statement
because when I commented it out
both errors disappeared.
Must be one of the "Magnificent 400"
bugs in 2.8.1!
Last edited by bjb007 on Fri Jun 06, 2008 7:57 am, edited 1 time in total.
Life is just a bowl of cherries.
I tested your exact script with the CORRECT syntax (see my first post) and it worked without any problems:
Why are you asking for help here if you do not try out our proposals?
There is nothing wrong with the "if...then..." as you stated, if you use the correct syntax for your comparison like "<>" or "IS not".
Code: Select all
...
put 0 into cTot
repeat with i = 1 to 30
put "btn" & i into btnTarget
if backgroundColor of button btnTarget <> "200,255,255" then
add 1 to cTot
end if
end repeat
...
There is nothing wrong with the "if...then..." as you stated, if you use the correct syntax for your comparison like "<>" or "IS not".
Using "backgroundColor" to count....
Klaus
I did indeed use your suggestion of "<>"
which works.
My comments since your original post about
problems I had refer to my attemps to get
the code to work before I asked the question.
Long and short of it -- I try a lot of alternatives
before I post here and when I get an answer I
use it.
I did indeed use your suggestion of "<>"
which works.
My comments since your original post about
problems I had refer to my attemps to get
the code to work before I asked the question.
Long and short of it -- I try a lot of alternatives
before I post here and when I get an answer I
use it.
Life is just a bowl of cherries.