Page 1 of 1
Switch button
Posted: Fri May 08, 2020 3:32 pm
by cougar05
Hello
I'm a really newbie and my english is also really not good! Sry for that!
I play a little bit with LiveCode and i have a problem with a switch button.
In my script i set a normal button that should set by klicking the switch button from on to off. The button also put empty into some fields.
I have really no idea how can i fix that.
Pleas help me!
Re: Switch button
Posted: Fri May 08, 2020 3:46 pm
by Klaus
Hi cougar05,
welcome to the forum!
The "Switch button" widget behaves like a checkbox or radiobutton, so you can just:
Code: Select all
...
##Switch OFFF
set the hilite of widget "your switch here" to FALSE
...
## Switch ON
set the hilite of widget "your switch here" to TRUE
...
Please help me!
That is what this forum is made for!
Best
Klaus
Re: Switch button
Posted: Fri May 08, 2020 4:05 pm
by cougar05
Hello Klaus!
Thanks a lot for your answer!!!
It helps me a lot!
I put this code into the script of the button "reset"
on mouseUp
put empty into fld "field1"
put empty into fld "field2"
put empty into fld "field3"
set the hilite of widget "switch1" to FALSE
set the hilite of widget "switch2" to FALSE
set the hilite of widget "switch3" to FALSE
end mouseUp
It works perfectly! Thank you Klaus!
Re: Switch button
Posted: Fri May 08, 2020 4:18 pm
by cougar05
Can you help me with an oder problem in this script?
I want to write a little script for a shoppinglist.
A textfield left on right a switch. When the switch is on, then the text in the field goes strikeout.
On the button a reset button (that works)
The script in the switches is:
on hiliteChanged
if the textstyle of fld "field1" is "strikeout" then
set the textstyle of fld "field1" to "normal"
else
set the textstyle of fld "field1" to "strikeout"
end if
end hiliteChanged
But sometime when i run the programm and i write a text in the field. the text is strikeout from the beginning. Is there a bug in the sript?
Re: Switch button
Posted: Fri May 08, 2020 4:36 pm
by Klaus
Hi cougar05,
what country are you from?
The problem with your script is, there is no NORMAL textstyle in LC, you mean
PLAIN!
Code: Select all
on hiliteChanged
if the textstyle of fld "field1" is "strikeout" then
set the textstyle of fld "field1" to "plain"
else
set the textstyle of fld "field1" to "strikeout"
end if
end hiliteChanged
That should do the trick.
Hint:
After pasting your code here, select it again and click on the CODE button on top of this text entry field.
The one that reads: </>
This way the formatting will be kept intact, see my script!
To learn more about the very basics of LC, check the stacks here:
http://www.hyperactivesw.com/revscriptc ... ences.html
And keep asking!
Best
Klaus
Re: Switch button
Posted: Fri May 08, 2020 4:46 pm
by cougar05
Wie ich sehe bist du aus Deutschland. Ich bin aus Österreich!
Vielen Dank für die Info!
Die Seite ist auch sehr hilfreich.
Leider ist es beim Script noch immer so, dass das oberste Feld mit dem Switch daneben immer durchgestrichen beginnt. Erst wenn ich den Switch "einschalte" wird der Text "plain"
LG, Manuel
Re: Switch button
Posted: Fri May 08, 2020 4:56 pm
by Klaus
Hi Manuel,
we also have a german LC forum:
http://www.livecode-blog.de/forums/foru ... ode-forum/
So please continue in english!
Hm, sounds like that LAST formatting of the field is being saved with the stack.
So add this to the "on openstack" handler, so the field is set to PLAIN when the stack opens:
Code: Select all
on openstack
set the textstyle of fld "field1" of cd 1 to "plain"
## More openstack stuff here...
end openstack
Hint:
You can put this into the stackscript or the script of the first card of your stack.
Best
Klaus
Re: Switch button
Posted: Fri May 08, 2020 5:24 pm
by cougar05
Thank you for the info Klaus!
But the problem is still there.
When i save the program and open it new and write something, klick on the switch to strikeout and klick again to plain ist. And when i klick the reset button and write something in one of the fields, its strikeout. Even though the switch is off ;(
Re: Switch button
Posted: Fri May 08, 2020 5:33 pm
by Klaus
Hm, very mysterious!
But wait, what does your "reset" button do?
Please post the script of that button.
Re: Switch button
Posted: Fri May 08, 2020 7:24 pm
by cougar05
I fixed it!
Thanks for your help!
This is in the script from the reset button:
Code: Select all
on mouseUp
put empty into fld "field1"
put empty into fld "field2"
put empty into fld "field3"
put empty into fld "field4"
put empty into fld "field5"
put empty into fld "field6"
put empty into fld "field7"
put empty into fld "field8"
put empty into fld "field9"
set the hilite of widget "switch1" to FALSE
set the hilite of widget "switch2" to FALSE
set the hilite of widget "switch3" to FALSE
set the hilite of widget "switch4" to FALSE
set the hilite of widget "switch5" to FALSE
set the hilite of widget "switch6" to FALSE
set the hilite of widget "switch7" to FALSE
set the hilite of widget "switch8" to FALSE
set the hilite of widget "switch9" to FALSE
set the textstyle of fld "field1" of cd 1 to "plain"
set the textstyle of fld "field2" of cd 1 to "plain"
set the textstyle of fld "field3" of cd 1 to "plain"
set the textstyle of fld "field4" of cd 1 to "plain"
set the textstyle of fld "field5" of cd 1 to "plain"
set the textstyle of fld "field6" of cd 1 to "plain"
set the textstyle of fld "field7" of cd 1 to "plain"
set the textstyle of fld "field8" of cd 1 to "plain"
set the textstyle of fld "field9" of cd 1 to "plain"
end mouseUp
Re: Switch button
Posted: Fri May 08, 2020 7:33 pm
by Klaus
How did you fix it?
Hint:
When in the script editor, hit the TAB key from time to time, then LC will format the script with indents etc.
THEN you can copy the scipt, paste it here and format it as CODE.
Hint:
You can save some typing, this will do the same with a REPEAT Loop:
Code: Select all
on mouseUp
repeat with i = 1 to 9
set the hilite of widget ("switch" & i) to FALSE
put empty into fld ("field" & i)
set the textstyle of fld ("field" & i) to "plain"
end repeat
end mouseUp
LC will first resolve the thing in parens (Klammern) so it knows the exact name of the controls to process.
In the first loop i has the value of 1 so it resolves to:
("switch" & i) -> switch1
("field" & i) -> field1
etc.
Best
Klaus
Re: Switch button
Posted: Fri May 08, 2020 7:42 pm
by cougar05
The line "set the hilite of widget "switch1" to FALSE" you told me to put in the Stack Script. I put it in the reset button script to. Now it works

Re: Switch button
Posted: Fri May 08, 2020 8:08 pm
by Klaus
cougar05 wrote: ↑Fri May 08, 2020 7:42 pm
The line "set the hilite of widget "switch1" to FALSE" you told me to put in the Stack Script.
I never did that!
THIS was my advice, Sir:
Code: Select all
on openstack
set the textstyle of fld "field1" of cd 1 to "plain"
## More openstack stuff here...
end openstack
Re: Switch button
Posted: Fri May 08, 2020 8:36 pm
by cougar05

My bad!
In the end, your advice work at all!
Thanks a lot!!!