Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

scope issue and use of global variables

LizardTongue Surface
Registered User
Join date: 31 May 2005
Posts: 11
07-01-2005 04:51
NOTE: this code works as is, for all the more it does, but is only the first brick of my project.

okies this all the code that i have at the moment. it is meant to go into a child prim in a linked set. trying to preserve a start position and rotation for a child prim in a linked set that can be used in multiple functions/states

if the first two lines are uncommented and the equivalent lines from the touch state(or is that a function? still trying to straighten that out) are commented out then it takes us back to <0,0,0> of the parent prim every time and i want to move back to it's original relative postion.

will be using owner commmands and offsets later on, for now just trying to figure out how the llGetLocalPos and llGetLocalRot are working as well as straighting out the scope issue.

the state_entry and on_rez are set up so that i know when the script starts up and are not really doing anything at the moment. i'm sure i will find a use for them later tho :)

am i missing something here about the use of global variables?

CODE

//vector startpos = llGetLocalPos;
//rotation startrot = llGetLocalRot;

default
{
state_entry()
{
llOwnerSay("Hello, Avatar!");
}

on_rez(integer startparm)
{
llOwnerSay("Hello, Avatar!");
}

touch_start(integer total_number)
{
vector pos = llGetLocalPos(); //local copy for use with offsets later
rotation rot = llGetLocalRot(); //local copy for use with offsets later
vector startpos = llGetLocalPos(); //need to get this up scope to global level
rotation startrot = llGetLocalRot(); //need to get this up scope to global level
llOwnerSay("pos= " + (string)pos);
llOwnerSay("rot= " + (string)rot);
llOwnerSay("startpos= " + (string)startpos);
llOwnerSay("startrot= " + (string)startrot);

llSetPos(pos + <0.1,0.1,0.1>); // these two are to give us some movement and
llSetRot(rot + <1,0,1,0>); //and rotation from base relative position

llSleep(2.0); //hold postion so we can see that it actually moved

llSetPos(startpos); //moving back to original postion
llSetRot(startrot); //moving back to original rotation
}
}
Max Case
Registered User
Join date: 23 Dec 2004
Posts: 353
07-01-2005 05:59
Hi Lizardtoungue,

as far as globals go, your top bits
//vector startpos = llGetLocalPos;
//rotation startrot = llGetLocalRot;

won't work for 2 reasons:
First, they are not the actual function calls - I bet you removed the brackets cuz they were giving you errors :),

//vector startpos = llGetLocalPos();
//rotation startrot = llGetLocalRot();

so, by adding the brackets we have fixed that, but then...

2: your next problem is that you can't initialize globals with dynamic data outside of a function or state, so.... you may want something like this:

vector startpos;
rotation startrot;

and then in your state_entry for default you would have:
startpos = llGetLocalPos();
startrot = llGetLocalRot();

Personally, what Ilike to do is declare my global variables, and make a little function just underneath I can call to initialize them.
////gvars////
vector startpos;
rotation startrot;

init()
{
startpos = llGetLocalPos();
startrot = llGetLocalRot();
}

This way, you just call init(); in your default:state_entry

Also, touch is really not a state or function. Think of it more as an 'event'.

Hope that helps,
Max.
LizardTongue Surface
Registered User
Join date: 31 May 2005
Posts: 11
07-01-2005 12:29
Thanks Max. Option 2 worked perfectly (after i remembered to make it a void call :))

Now on to Phase II of the 'Perfekt, Mondo Cool, Gotta have it' killer item (I hope)

llGetLocalPos/Rot both use the root prim as reference point so question is this:

if i have the following linked item as a chain:

ROOT -> CHILD1 -> CHILD2 -> CHILD3

how can i get CHILD3 to see CHILD2 as its' root while CHILD2 sees CHILD1 as its' root and CHILD1 uses the actual ROOT? (i want to use position offsets and facings relative to the previous prim in the chain not the ROOT; except CHILD1, of course, which uses the ROOT, and ROOT which will be bossing the chain gang as it were)

have the feeling i'm going to be playing with llRezObject and passing parms before this is over as well as digging into the math for the llGetLocalPos/Rot functions

the eventual idea is that the ROOT has a listener and parser then issues commands using link messages that propagate down the chain (may be using some modified form of link messages as well, i just love when the existing tools _almost_ do what i want:))

and may end up with some form of the

// Open Shifting Float and Follow Script, by Foolish Frost.
// From Open Basic Follower/Facing Script, by Logan Bauer.

for the child prims

with my luck, once i get all this figured out and working i'll find a shop that's been selling the very thing for months

Thanks for any help gang,
LizardTongue (wishing llSetPos and llSetRot worked on attachments)
Racer Plisskin
Rezerator
Join date: 2 Jan 2005
Posts: 147
07-01-2005 17:51
While doing what you want with chained prims is possible, it's gonna be really code intensive.

The Havoc2 physics engine will support 'ragdoll' physics so the problem above should be vastly simplified once it is incorporated in SL

For now, probably the only thing you can do is something like this:

prim1: calculate it's offsets from root - send info to prim2
prim2: calculate it's offsets from prim1 then add prim 1s offsets - report info to prim3
prim3: calculate it's offsets from prim2 then add prim 2s offsets, etc...

The final prim in the chain sends a trigger message to everyone to move all at once to final locations so we don't get prims flailing about on their own... ;)

If root is moving in relation to the world while the calculations are happening, this could get weird results as well... ;)

Slow and clunky... Yuck.

--- EDIT ---

If you want to make a 'static' set of configurations for your 'device' you could precalculate all the possible offsets and rotations and simply plug in the numbers as needed based on a single call from root to achieve any of the desired result configurations... MUCH faster at runtime and much less work for the sim to handle. ;)

This is how I work the multi-prim doors on my Lamborghini and Delorean (you can play with a demo version at busy bens car lot to see it in action - you have to sit in the demo car to work the doors, only owners can work them from outside the car).

Racer P.
_____________________
"What's important in life is not how many breaths we get to take but those moments that take our breath away." -- Jaques Cousteau

"A thin line separated serious homicidal purpose from buffoonery." -- Dean Koontz

"CanYouFixTheSpaceBarOnMyKeyboard?" -- Email to Helpdesk