Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Gun script is not loading properly

Maeve Morgan
ZOMG Resmod!
Join date: 2 Apr 2004
Posts: 1,512
11-26-2004 19:55
I have a weapon I made with just a simple gun script and I have to attach it recompile the script detach it then reattach it to get it to work properly and I have no idea why
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-26-2004 20:01
because when you compile the code in the state entry you don't check if the object is attached and if it is then run the same code as is used for if the object is attached. The easy way of doing this is to make a single function that you call from both events to handle the initilization.

CODE

integer PermNeed;

init(integer perm)
{
if((perm&PermNeed) == PermNeed)
{
//what ever code you need to run when an object is attached blah blah blah
}
else
{
llRequestPermissions(llGetOwner(), PermNeed);
}
}

default
{
state_entry()
{
PermNeed = PERMISSION_TRIGGER_ANIMATION |
PERMISSION_TAKE_CONTROLS |
PERMISSION_ATTACH;
if(llGetAttached())
init(llGetPermissions());
}
attach(key a)
{
if(a!=NULL_KEY)
init(llGetPermissions());
else
{
//whatever code you need to run when the object dettaches
}
}
run_time_permissions(integer a)
{
init(a);
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey