Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Codes for switch

Hasina Solo
Registered User
Join date: 26 Oct 2009
Posts: 25
12-06-2009 19:26
Hi. Cn anyone help me on how the coding in the switch works. Thank You.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-06-2009 20:12
Try this
CODE
integer toggle;// simple binary switch.  Starts as false if no value given

default {
state_entry() {
// start with stuff turned off
}

touch_start(integer num){
toggle =!toggle;//change the value each time you touch it
if(toggle){ // if toggle is true
//turn stuff on
}
else{ // if it's not true, it must be false
//turn stuff off
}
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-06-2009 20:24
if you're using a binary value in what your code is triggering, you can do it even more simply...

example of fullbright on/off (starts "off";)
CODE

integer vBooSwitch;

default{
touch_start( integer vIntNull ){
llSetLinkPrimitiveParams( LINK_SET, [PRIM_FULLBRIGHT, ALL_SIDES, (vBooSwitch = !vBooSwitch)] );
}
}


if you use two values (like say 0 and 255) you can use multiplication to do the same thing like
(vBooSwitch = !vBooSwitch) * 255
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Hasina Solo
Registered User
Join date: 26 Oct 2009
Posts: 25
12-06-2009 21:00
thanks anyway! but cn u all modify a little, where, once the switch is clicked, the inclined track moves. Cn anyone help me on that? I am stuck on that? Can reply me asap? Thank you.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-06-2009 21:53
same idea, except use PRIM_ROTATION and PRIM_POSITION properties in a call to llSetPrimitiveParams http://wiki.secondlife.com/wiki/LlSetPrimitiveParams

I'll leave the math of the height change to you, but it's fairly simple trig that you can probably find a formula for online
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Hasina Solo
Registered User
Join date: 26 Oct 2009
Posts: 25
12-06-2009 22:16
i have thought of using that...... i have found that both the switch and button must be linked in order for it to work. But may i know what are codes should implement in the switch and track? 10q.
Hasina Solo
Registered User
Join date: 26 Oct 2009
Posts: 25
12-06-2009 23:00
i have implement this coding for the switch. is this correct?

integer myswitch;

default
{


state_entry()
{

myswitch=FALSE;

}

touch_start(integer total_number)
{

if(myswitch==FALSE)
{

//Turn switch ON

llMessageLinked(LINK_THIS, 0, "start", NULL_KEY);
myswitch=TRUE;



}
else
{

//Turn switch Off

llMessageLinked(LINK_THIS, 0, "stop", NULL_KEY);
myswitch=FALSE;





}

}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-07-2009 00:08
that will work, yes

ps
you don't need to set mySwitch to FALSE in state entry, all stated variables start as zero (which is false) or empty (if they are lists, keys, or strings)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Hasina Solo
Registered User
Join date: 26 Oct 2009
Posts: 25
12-07-2009 04:53
But even though i put mySwitch == True (state entry), but still my track cannot work. When i click on the switch, my track did not move.... do u have nay idea on this? thank you.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
12-07-2009 07:41
From: Hasina Solo
But even though i put mySwitch == True (state entry), but still my track cannot work. When i click on the switch, my track did not move.... do u have nay idea on this? thank you.

llOwnerSay is your friend!!

Seriously. Put something like 'llOwnerSay ("I got clicked! myswitch now = " + (string)myswitch);' at the end of your touch_start handler. And put more in the other script - the one that receives the link messages - the make sure they're getting the messages you expect.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Hasina Solo
Registered User
Join date: 26 Oct 2009
Posts: 25
12-07-2009 18:42
Instead of llOwnerSay, i have implement, llSay and for the track i have implement llListen.... Is it ok to implement this?
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
12-07-2009 19:55
From: Hasina Solo
Instead of llOwnerSay, i have implement, llSay and for the track i have implement llListen.... Is it ok to implement this?

I think Meade was saying to use llOwnerSay for debugging. It's much more reliable than guessing what your code is doing!

Once you've got the scripts debugged, you can remove them or comment them out.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Hasina Solo
Registered User
Join date: 26 Oct 2009
Posts: 25
12-08-2009 01:19
Thanks for the help.