hello, Is there a way in liveCode to set 'a switch' , so if something happens then set "switch" to true and if "switch" true then do something else..??
Also, whilst the "switch" is true, is there then a way to count the number of times that the 'on mouseup' has happened..? Then when the count = 5 then do something else.?
Thanks
Switch and Count?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Switch and Count?
Hi MAxMax,
If i understand what you want, this script should be useful
Best regards
Jean-Marc
If i understand what you want, this script should be useful
Code: Select all
-- cd script
local sNbClic
on opencard
put 0 into sNbClic
end opencard
on debMybtn
add 1 to sNbClic
put "You have clicked me" && sNbClic && "times" into Mes
put mes into fld "fComment"
end debMybtn
-- btn script
on mouseup
debMybtn
end mouseup
Jean-Marc
https://alternatic.ch
Re: Switch and Count?
Hi jmburnod, thanks for that, I'm guessing the switch is like a flag, that can be thrown when certain criteria are met.?
I have done this so far, but this does place the next button hit into the field "set2"
if field "fld1" = field "fld2"then
switch now
put label of the target into field "set2"
end switch
end if
Thanks
I have done this so far, but this does place the next button hit into the field "set2"
if field "fld1" = field "fld2"then
switch now
put label of the target into field "set2"
end switch
end if
Thanks
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: Switch and Count?
Hi,
the command 'switch' is like a bunch of 'if' statements based on a value.
That gets very messy when there are a lot of potential values for the 'var1' variable. The switch command neatens that to this:
The way you are trying to use it in your example is not really correct - it might work this time, but it's probably only a side-effect. Try to understand it properly before using it again, else you will end up getting very confused as to why it doesn't work the way you expect. Always use the dictionary to get a guide instead of guesswork.
I think the term 'switch' you are looking at is simply a flag variable (as jm shows) - but you can easily use a simple 'if' if you are only interested in a single value.
I hope that helps a bit,
Dave
the command 'switch' is like a bunch of 'if' statements based on a value.
Code: Select all
if var1 = 100 then
// do stuff
else
if var1 = 200 then
// do other stuff
else
// do yet more stuff
end if
end if
Code: Select all
switch var1
case 100
// do stuff
break
case 200
// do other stuff
break
default
// do yet more stuff
end switch
I think the term 'switch' you are looking at is simply a flag variable (as jm shows) - but you can easily use a simple 'if' if you are only interested in a single value.
I hope that helps a bit,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: Switch and Count?
This is a perfect time to use a custom property to, exactly as you described, set a flag. Have you ever used these before?
In order to count "mouseUp' messages, you would have to pass that message in every script it appears, and accumulate that count, likely in another custom property. You can then test that property at any time, or, more likely perhaps, every "mouseUp", to see if it has reached five.
Do you know how to do this? Very simple and basic, but I do not know how familiar you are with LiveCode. For example, do you know why you have to pass "mouseUp" in every place and every time it is used? Write back if you need more help.
Craig Newman
In order to count "mouseUp' messages, you would have to pass that message in every script it appears, and accumulate that count, likely in another custom property. You can then test that property at any time, or, more likely perhaps, every "mouseUp", to see if it has reached five.
Do you know how to do this? Very simple and basic, but I do not know how familiar you are with LiveCode. For example, do you know why you have to pass "mouseUp" in every place and every time it is used? Write back if you need more help.
Craig Newman