Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Switch help

Nathan Clayton
Registered User
Join date: 16 May 2005
Posts: 3
05-19-2005 23:34
Ok, I'm having a little trouble here. Let's say I want to have an object switch between two functions. When I do it like this, I keep getting the particle effect swirl around the object. I figured it had to do with the state, so I tried doing the switch inside a function...tried switching the state etc. and it does it no matter what I try. Any help would be appreciated.

///////////////////////////////////////
//Script to switch between two things//
///////////////////////////////////////

integer switch = 1; // int switch

one() // first function
{
switch = 2; // switch to two
llSay(0, "Switched to Two.";);
}

two() // second function
{
switch = 1; // switch back to one
llSay(0, "Switched to One.";);
}



default
{
state_entry()
{
while (TRUE)
{
if (switch = 1) {one();} // if switch is 1, go to function one
if (switch = 2) {two();} // if switch is 2, go to function two
}
}
}
Jimmy Loveless
Hello, avatar!
Join date: 1 Oct 2004
Posts: 35
05-19-2005 23:53
a single equals sign is an assignment operator, to be used like so:

x = 4

a double equals sign is the comparison operator, to be used like so:

if (x == 4)

Soo, if you use if (switch == 1) it should work.
Kali Dougall
Purple and Spikey
Join date: 5 Feb 2005
Posts: 98
05-19-2005 23:53
Change "switch = 1" to "switch == 1". = is an assignment operator, == is a comparison operator. Very common mistake.

Also, the particle swirl around an object just indicates that it's saying something.
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
try some states
05-20-2005 07:17
You may want to try states as well..

default
{
state_entry()
{
llOwnerSay("Hey I'm in the default state.";);
}
touch_start(integer param)
{
state notdefault;
}
}

state notdefault
{
state_entry()
{
llOwnerSay("Hey I'm no longer in the default state.";);
}
touch_start(integer param)
{
state default;
}

}
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
05-20-2005 07:25
From: Nathan Clayton
When I do it like this, I keep getting the particle effect swirl around the object...


The particle effect is being caused by the llSay function.

If you make anything 'speak' aloud with llSay(0,"Insert text here";); it will cause the particle effect. Using a private channel llSay(34,"Insert text etc.... supresses the particles, but you can't hear what it's saying.
_____________________
--------------------------------------------------------
Surina Skallagrimson
Queen of Amazon Nation
Rizal Sports Mentor

--------------------------------------------------------
Philip Linden: "we are not in the game business."
Adam Savage: "I reject your reality and substitue my own."
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
05-20-2005 11:51
Man, if I had a dollar for every time i used = instead of ==.

Wish it was like VB in that it didnt care, if there's an if before the "=" it knows it's a comparison and not an assignment.

But then again, if i had a dollar for everytime I forgot to capitalize something too. Such is life.
_____________________
----------------------------------------------------------
--The mind's eye is limited only by its focus--
Hiro Turnbull
Freelance Scripter
Join date: 20 Apr 2005
Posts: 24
Vb :p
05-20-2005 13:00
That is why I don't like VB because it doesn't care.
Nathan Clayton
Registered User
Join date: 16 May 2005
Posts: 3
05-20-2005 14:25
Thank you guys so much!