Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Setting values in global variables

Yann Teazle
Registered User
Join date: 30 Jun 2005
Posts: 5
04-04-2006 21:26
Ok, so I've been trying to piece together some scripting knowledge over the last few days, but I've hit a wall.

The script in question listens for a link_message with a UUID, and also listens for the commands "lock" or "unlock". On hearing the UUID, it sets global variable TARGET to that value. On hearing "lock" or"unlock", it enters states "on" or "off" respectively.

On state starts the particles flowing on entry. Off state clears the particles.

Or, at least, it SHOULD do. In fact, what it does is just sit there grinning at me for three days. I've discovered that if I put a linked message listen event in the "on" state and wait for the TARGET key there, the particles flow just fine. But only for five seconds.

Now, this says to me that TARGET isn't updating or being read properly.

Here's the full script; I hope someone can spot an obvious mistake I'm making :)

CODE
key TARGET;

default
{
link_message(integer sender_num, integer num, string str, key id)
{
if (num==5) TARGET=(key)str;

if (num==1)
{
if (str=="lock") state on ;

if (str=="unlock") state off ;
}
}
}


state on {
state_entry()
{
integer flags;
flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
if (TARGET != "") flags = flags | PSYS_PART_TARGET_POS_MASK;

llParticleSystem([ PSYS_PART_MAX_AGE,3.0,
PSYS_PART_FLAGS,flags,
PSYS_PART_START_COLOR, <1,1,1>,
PSYS_PART_END_COLOR, <1,1,1>,
PSYS_PART_START_SCALE,<.075,.075,.075>,
PSYS_PART_END_SCALE,<.075,.075,.075>,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE,
PSYS_SRC_BURST_RATE,.05,
PSYS_SRC_ACCEL, <0,0,0>,
PSYS_SRC_BURST_PART_COUNT,25,
PSYS_SRC_BURST_RADIUS,0.0,
PSYS_SRC_BURST_SPEED_MIN,0.0,
PSYS_SRC_BURST_SPEED_MAX,0.0,
PSYS_SRC_TARGET_KEY,TARGET,
PSYS_SRC_INNERANGLE,1.55,
PSYS_SRC_OUTERANGLE,1.55,
PSYS_SRC_OMEGA, <0,0,10>,
PSYS_SRC_MAX_AGE, 10.0,
PSYS_SRC_TEXTURE, "chain",
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 1.0 ]);
}
}

state off {
state_entry(){llParticleSystem([]);}
}
Geoff Gavaskar
who, me?
Join date: 29 Dec 2005
Posts: 21
04-04-2006 21:54
Minimally, each state in which you might recieve a message must have a listener. Alternatively, you must transition from each non-listening state to a state (in this case, default) that has a listener. Otherwise, you'll be stuck in the new state, and no be able to to listen.

Something else to consider...make yourself a global "DebugSay" method, and have each state_entry have an llOwnerSay telling you what state you're in. When you're done with the debugging, you can just comment out the llOwnerSay statement in your DebugSay method.

Good Luck!
Yann Teazle
Registered User
Join date: 30 Jun 2005
Posts: 5
04-05-2006 08:59
Good tips - having debugged, it look like I'm entering and exiting states as I was hoping.

Still no luck getting the global variable TARGET to work between states though. Am I right in thinking that you can change a global variable within a scope, and have it at that value in all scopes until the next change? Or does the change only stay within that scope?
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-05-2006 09:18
Your problem is the link messages.

Once you get the link message 1, you're going into a state with no link message handler (no matter whether it's "on" or "off";), so you won't ever get any more link messages.
Yann Teazle
Registered User
Join date: 30 Jun 2005
Posts: 5
04-05-2006 09:20
aaaaaah - I see what you mean.

Thanks guys :)