Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Global variables are resetting?

Caterpillar Recreant
Registered User
Join date: 20 May 2007
Posts: 1
06-03-2007 15:40
I'm trying to create an object that can store its position, resume its position, or destroy itself on command. Here's the whole script as I have it right now.

From: someone
vector DestinationPos;
rotation DestinationRot;

default
{
state_entry()
{
llListen(1,"",llGetOwner(),"";);
vector DestinationPos = llGetPos();
rotation DestinationRot = llGetRot();
}

listen(integer channel, string name, key id, string message)
{
if (llToLower(message) == "store";) {
vector DestinationPos = llGetPos();
rotation DestinationRot = llGetRot();
llSay(0, "Position stored at " + (string)DestinationPos);
}

if (llToLower(message) == "reset";) {
llSetStatus(STATUS_PHYSICS, FALSE);
llSetStatus(STATUS_PHANTOM, TRUE);
llSetAlpha(0.4, -1);
llSetPos(DestinationPos);
llSetRot(DestinationRot);
llSay(0, "Position reset to " + (string)DestinationPos);
llSleep(1);
llSetStatus(STATUS_PHYSICS, TRUE);
llSetStatus(STATUS_PHANTOM, FALSE);
llSetAlpha(1, -1);
}

if (llToLower(message) == "clear";) {
llSay(0, "Cleared.";);
llDie();
}
}
}


The problem is, when I try the resetting command, it thinks my "DestinationPos" and "DestinationRot" variables are the default 0...s, even though I set them with both the store command and in state_entry. They are supposed to be global variables, right? How are they being wiped clean?
Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
06-03-2007 16:24
just remove the "vector" and "rotation" in your state entry and listen event. You already defined your global variable before the default. your redefineing them again in the state and listen event as locals.