Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Any Idea why this is not working? Uses linked_messages

FifthPegasus Writer
Registered User
Join date: 4 Jun 2007
Posts: 3
06-09-2007 17:58
If anyone has some idea as to why this code does not work I would love to hear it. What this code does not show is the linked prims message they send. but it is a fairly simple message and the debug text shows the messages are getting transmitted just fine. So it is in this part of the script that the error is arising:

CODE

// Set global Variables
integer Repeat;
vector TargetPosition;
rotation Level;
integer Switch;

default
{
state_entry()
{
llSay(DEBUG_CHANNEL, "Platform Ready.");
}
link_message(integer sender_num, integer Num, string Report, key ID)
{
//Debug Info
llSay(DEBUG_CHANNEL, "Message: " + Report +"\n PrimNum: " +(string) sender_num + "\n Switch: " +(string) Switch);

//Change the Switch

if ( sender_num = 4)
{
Switch = 1;
}

if (sender_num = 3)
{
Switch = -1;
}

// Move it

llSetStatus(STATUS_PHYSICS, TRUE);
for(Repeat= 0; Repeat<50; Repeat+=1)
{
TargetPosition = llGetPos();
TargetPosition.z = TargetPosition.z + (50 * Switch);
llMoveToTarget(TargetPosition, 1);
if (TargetPosition.z > 100)
{
Repeat =500;
}
}

}
}


Edit: What the debug message tells me is that the Switch Variable is Not changing. Why it isn't I have no clue.
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
06-09-2007 18:09
These guys:

CODE

if ( sender_num = 4)
{
Switch = 1;
}

if (sender_num = 3)
{
Switch = -1;
}


Should likely be:

CODE

if ( sender_num == 4)
{
Switch = 1;
}

if (sender_num == 3)
{
Switch = -1;
}
FifthPegasus Writer
Registered User
Join date: 4 Jun 2007
Posts: 3
06-09-2007 18:14
I figured it was a foolish little oversight and it sure enough was.

Thanks for pointing that out =^_^=

No telling how many years it would have taken me to notice >.>
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
06-09-2007 18:14
a little cleanup, if your just checking a value, like you are, don't use if... if... instead use if.. else if... this will save the code from executing every time that it goes though. Basically if the first statement is true, it won't bother to check the second statement if you use if else if.

CODE

if ( sender_num == 4)
{
Switch = 1;
}

else if (sender_num == 3)
{
Switch = -1;
}


so if sender_num is 4, the code won't even bother to make a check after it has finished the true statement of the block in the if (sender_num == 4), it will skip past the
else if (sender_num == 3) block.

Just a helpful little hint when you have a whole bunch of if statements and your only checking one thing. It will speed up the execution time a little.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
06-09-2007 18:15
/me nods.. = is for when you want to assign a value to a variable, == is for when you want to test the value of a variable.

This is while some people would have written it like "if (3 == sender_num)" instead. That will generate a compile-time error if you use = by mistake.