Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Little Script Debugging Help Please

Ody Naglo
Registered User
Join date: 1 Apr 2008
Posts: 31
08-28-2008 23:42
string reload_sound="e5de9fb0-c4d5-4830-aa19-a57d864104c5";
string semiauto_sound="Report";
string fullauto_sound="Report";
string firemodeswitch_sound="8532afcf-509e-113e-9b58-a81395d0c223";
string dryfire_sound="b38bdcc9-3a98-8875-da60-b4d1e6805796";
string deploy_sound="17ca1c1c-96a2-e966-1839-fd5d7abf4cdd";
string initmessage = "M4 SOPMOD- Sniper Configuration";
string semiauto_silencedsound="7f4a1b73-7b30-b5b4-5f8c-b43162f06fe6";
string fullauto_silencedsound="6a8368b6-e207-1ed8-8b0c-ea71289a37bd";
key owner;
string reloading_anim="Reload";
integer gotperms = FALSE;
integer dialoglistenhandle;
integer listenhandle;
integer firingmode;
string bulletname = "Training Bullet";
integer safe = TRUE;
integer silenced;
integer reloading;
integer settext = TRUE;
list main_menu = ["bullet","firemode","safe","nosafe","reload","options","draw","sling","help"];
list firemode_menu = ["auto","single","back...","silenceron","silenceroff"];
list bullet_menu = ["training","damage","push","phantom","back..."];
list option_menu = ["texton","textoff","resetgun","back...","effectson","effectsoff"];
DoSetText()
{
integer ammo = (integer)llGetObjectDesc();
string text;
string safety;
if(ammo < 0)
{
ammo = 0;
}
if(safe)
{
safety = "On";
}
else
{
safety = "Off";
}
text = llGetObjectDesc() + "\n" + "Safety:" + safety;
if(settext)
{
llSetText(text,<225,0,0>,1.0);
}
else
{
llSetText("",<0,0,0>,0.0);
}
}
Dialog(key id,list menu,string text)
{
llDialog(id,text,menu,25);
}
Rez(string what,integer passed)
{
llMessageLinked(LINK_SET,passed,what,(string)firingmode);
}
Init()
{
gotperms = FALSE;
if(owner != llGetOwner())
{

NewOwner();

}
else
{
GetPerms(llGetOwner());
// silenced = FALSE;
llWhisper(6666,"invisible " + (string)llGetOwner());
llInstantMessage(llGetOwner(),initmessage);
llListen(0,"",llGetOwner(),"";);
llListen(25,"",llGetOwner(),"";);
DoSetText();
}
}
NewOwner()
{
owner = llGetOwner();
firingmode = 1;
bulletname = "Training Bullet";
listenhandle = llListen(0,"",owner,"";);
llMessageLinked(LINK_SET,-5,"lookforupdate",NULL_KEY);
// GetPerms(owner);
Reload();
Init();
}
GetPerms(key id)
{
llRequestPermissions(id,PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);

}
Reload()
{
if(settext)
{
llSetText("Reloading",<225,0,0>,1.0);
}
llStopSound();
//llResetOtherScript("rifle.rez4";);
llMessageLinked(LINK_SET,-1,"reload",NULL_KEY);
llSetObjectDesc("100";);
// llStartAnimation(reloading_anim);
//Rez("default clip",0);
llSleep(1);
llTriggerSound(reload_sound,0.8);
reloading = FALSE;
DoSetText();
}
Fire()
{
integer ammo = (integer)llGetObjectDesc();
if(!safe && !reloading)
{
if(ammo > 0)
{
Rez(bulletname,10000);
if(firingmode == 1)
{
llTriggerSound(semiauto_sound,1.0);
}
if(firingmode == 2)
{
llTriggerSound(fullauto_sound,1.0);
}
DoSetText();
}
else if (reloading != TRUE && ammo <= 0)
{
reloading = TRUE;
Reload();
}
}
}
default
{
state_entry()
{
if(owner != llGetOwner())
{
NewOwner();

}

}

attach(key id)
{
if(id != NULL_KEY)
{
//llSetScriptState("rifle.perms",TRUE);
Init();
}
else
{
//llSetScriptState("rifle.perms",FALSE);
llWhisper(6666,"visible " + (string)llGetOwner());
//llStopAnimation("hold_r_rifle";);
llReleaseControls();
llSensorRemove();
}
}



run_time_permissions(integer perm)
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT,TRUE,TRUE);
gotperms = TRUE;
llMessageLinked(LINK_SET,98769,"Auto Turret v2 Works",NULL_KEY);
llSensorRepeat("",owner, AGENT, 20, TWO_PI, .1);

}



control(key id,integer held,integer change)
{
integer pressed = held & change;
integer down = held & ~change;
integer released = ~held & change;
integer inactive = ~held & ~change;
if(pressed & CONTROL_ML_LBUTTON)
{
if(firingmode==1 && !safe && !reloading)
{
Fire();
}
if(firingmode==2 && !safe && !reloading)
{
Fire();
}
}
if(released & CONTROL_ML_LBUTTON)
{
if(firingmode==2) Fire();
llStopSound();
llResetOtherScript("rifle.rez";);
llResetOtherScript("rifle.rez2";);
llResetOtherScript("rifle.casings";);
llResetOtherScript("rifle.casings2";);
if(reloading)
{
Reload();
}
}
if(down & CONTROL_ML_LBUTTON)
{
if(firingmode==2 & !reloading)
{
Fire();
}
if(firingmode==2 && !safe && !reloading)
{
if(silenced)
{
llLoopSound(fullauto_silencedsound,1.0);
}
else
{
llLoopSound(fullauto_sound,1.0);
}
}

}
if(pressed || down & CONTROL_ML_LBUTTON)
{
if(reloading)
{
llStopSound();
llTriggerSound(dryfire_sound,1.0);
}
}
}
listen(integer channel,string name,key id,string message)
{

list args = llParseString2List(llToLower(message),[" "],[]);
if (id == llGetOwner())
{
if(llList2String(args,0) == "back...";)
{
Dialog(id,main_menu,"main menu";);
}
if(llList2String(args,0) == "help";)
{
llGiveInventory(llGetOwner(),"help";);
}
if(llList2String(args,0) == "options";)
{
Dialog(id,option_menu,"Options";);
}
////////////////////////////////

if(llList2String(args,0) == "silenceron";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Silencer Enabled";);
silenced = TRUE;

//////////////////////////////
}
if(llList2String(args,0) == "silenceroff";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Silencer Disabled";);
silenced = FALSE;

//////////////////////////////
}
if(llList2String(args,0) == "resetgun";)
{
llOwnerSay("Resetting Scripts...";);
llResetOtherScript("rifle.casings";);
llResetOtherScript("rifle.rez";);
llResetOtherScript("rifle.rez2";);
llResetScript();
}
if(llList2String(args,0) == "texton";)
{
llOwnerSay("SetText Enabled";);
settext = TRUE;
DoSetText();
}
if(llList2String(args,0) == "textoff";)
{
llOwnerSay("SetText Disabled";);
settext = FALSE;
DoSetText();
}
if(llList2String(args,0) == "bullet";)
{
Dialog(id,bullet_menu,"Bullet Menu";);
}
if(llList2String(args,0) == "effectson";)
{
llOwnerSay("Special Effects on - clipfall/bulletcasings";);
llSetScriptState("rifle.casings",TRUE);
llSetScriptState("rifle.casings2",TRUE);
llMessageLinked(LINK_SET,-5,"effectson",NULL_KEY);
}
if(llList2String(args,0) == "effectsoff";)
{
llOwnerSay("Effects off";);
llSetScriptState("rifle.casings",FALSE);
llSetScriptState("rifle.casings2",FALSE);
llMessageLinked(LINK_SET,-5,"effectsoff",NULL_KEY);
}
if(llList2String(args,0) == "firemode";)
{
Dialog(id,firemode_menu,"Firing Mode Menu";);
}
if(llList2String(args,0) == "reload";)
{
Reload();
}
if(llList2String(args,0) == "auto";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Auto Firingmode Selected";);
firingmode = 2;
}
if(llList2String(args,0) == "single";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Single Firingmode Selected";);
firingmode = 1;
}
if(llList2String(args,0) == "training";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Training Bullet Selected. Causes 1 Dmg";);
bulletname = "Training Bullet";
}
if(llList2String(args,0) == "damage";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Damage Bullet Selected, Causes 100 Dmg";);
bulletname = "Damage Bullet";
}
if(llList2String(args,0) == "phantom";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Phantom Bullet Selected, Goes through walls and shields easily.";);
bulletname = "Phantom Bullet";
}
if(llList2String(args,0) == "push";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Push Bullet Selected, Pushes av a good distance.";);
bulletname = "Push Bullet";
}
if(llList2String(args,0) == "safe";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Safety On";);
safe = TRUE;
}
if(llList2String(args,0) == "nosafe";)
{
llTriggerSound(firemodeswitch_sound,0.5);
llOwnerSay("Safety Off";);
safe = FALSE;
}
if(llList2String(args,0) == "draw";)
{
safe = FALSE;
settext = TRUE;
//llSetScriptState("rifle.anims",TRUE);
llWhisper(6666,"invisible " + (string)llGetOwner());
llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);
}
if(llList2String(args,0) == "sling";)
{
safe = TRUE;
settext = FALSE;
//llSetScriptState("rifle.anims",FALSE);
//llStopAnimation("rifle.anim.standing";);
// llStopAnimation("rifle.anim.aim";);
llWhisper(6666,"visible " + (string)llGetOwner());
llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES);
}
}
DoSetText();
llListenControl(dialoglistenhandle,FALSE);
}

touch_start(integer total_number)
{
gotperms = TRUE;
if(llDetectedKey(0) == llGetOwner())
{

Dialog(llDetectedKey(0),main_menu,"Main Menu";);

}
}


link_message(integer sender,integer num, string message, key id)
{
if (num == 35432) //Remote Control On
{
GetPerms(llGetOwner());

}
if (num == 54368) // Remote Control Off
{
llReleaseControls();
llSensorRemove();
llSetText("", <1,1,1>, 1);
}

}

sensor(integer sense)
{

rotation k = llDetectedRot(0);
llRotLookAt(k, 1, 1);
}
no_sensor()
{

}
}








Anyone who helps or tries to help gets a free "Little Pet Noob" =)
Hagar Qinan
Registered User
Join date: 26 Jul 2007
Posts: 1
recompile ?
08-29-2008 04:19
I stopped at the first entry in your list : (I Rez it and its says - "whispers: unexpected runtime environment";).

I checked to make sure that the message does not appear somewhere in your script (unless it's in some other script you didn't show us). The bizarre behaviour you describe further on suggests problems with the bytecode.
So -- first step : open the sourcecode, add a space somewhere (to change the source text) and save it again, forcing it to recompile.
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
Double permissions?
08-29-2008 09:01
In the NewOwner() function you've got:
.....
GetPerms(owner);
Reload();
Init();

The first line in Init() = "gotperms = FALSE;"

This made me think there should only be Init(); in the NewOwner() function.

Making this change seems to do the trick, but withhout the object(s) and the other scripts in the linkset I can't be totaly sure.
Ody Naglo
Registered User
Join date: 1 Apr 2008
Posts: 31
08-29-2008 13:20
From: Ron Khondji
In the NewOwner() function you've got:
.....
GetPerms(owner);
Reload();
Init();

The first line in Init() = "gotperms = FALSE;"

This made me think there should only be Init(); in the NewOwner() function.

Making this change seems to do the trick, but withhout the object(s) and the other scripts in the linkset I can't be totaly sure.





Thanks that helped alot =) just






- When I say "RC" to take control the premission menu comes up and it script errors at the same time and it says ( Could not find object ''. ) twice & plays a sound twice.

- ";( Could not find object ''. ) twice & plays a sound twice." Also happens when I say Turret.

- When the menu is up if I choose "No" the Sensor activates anyways and follows what ever I look at as if I press yes. with no fire control.

- if I hit No I get a message saying " Script trying to take controls from owner but PERMISSION_TAKE_CONTROLS permission not set!"
Ody Naglo
Registered User
Join date: 1 Apr 2008
Posts: 31
08-29-2008 14:21
COMMAND SCRIPT




key owner;
default
{

state_entry()
{

owner = llGetOwner();
llListen(0,"","owner","Turret";);
llListen(0,"","owner","RC";);

}
listen(integer channel, string name, key id, string message)
{

if (message == "Turret";)
{
llMessageLinked(LINK_SET,54368,"rifle.main",NULL_KEY);
llSleep(1);
llMessageLinked(LINK_SET,89769,"Auto Turret v2 Works",NULL_KEY);
llSleep(1);
llSay(0,"Auto Turret Engaged";);

}


if (message == "RC";)
{
llMessageLinked(LINK_SET,98769,"Auto Turret v2 Works",NULL_KEY);
llSleep(1);
llMessageLinked(LINK_SET,35432,"rifle.main",NULL_KEY);
llSleep(1);
llSay(0,"You Have Control";);

}

}

}
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-29-2008 15:07
From: Ody Naglo
I figured out what Script was making it error and make sounds its my command script for switching between RC and Turret Seems the Linked messages are messing up help? =)

I changed the " " in llMessageLinked(LINK_SET,54368,"",NULL_KEY); to llMessageLinked(LINK_SET,54368,NULL_KEY,NULL_KEY);
and the error messaged changed to Could not find object '00000000-0000-0000-0000-000000000000'.



This sends to the link set a message saying, "54368, NULL_KEY (as a string) and NULL_KEY (as a key).

Without knowing what the receiver script says it's a bit hard to tell, but I would hazard a guess that you've told it to look for something with either the string "str" or the key "id" indicated in

link_message(integer sender_num, integer num, string str, key id)

Your link message, in other words, is setting the values of both the string strand the key id to NULL_KEY (which is a short way of saying '00000000-0000-0000-0000-000000000000'.) and the receiver script is trying to find either something with the name indicated by str or the key indicated by id.

What information are you trying to pass to the receiver and what's it supposed to do with it?
Ody Naglo
Registered User
Join date: 1 Apr 2008
Posts: 31
08-29-2008 15:30
From: Innula Zenovka
This sends to the link set a message saying, "54368, NULL_KEY (as a string) and NULL_KEY (as a key).

Without knowing what the receiver script says it's a bit hard to tell, but I would hazard a guess that you've told it to look for something with either the string "str" or the key "id" indicated in

link_message(integer sender_num, integer num, string str, key id)

Your link message, in other words, is setting the values of both the string strand the key id to NULL_KEY (which is a short way of saying '00000000-0000-0000-0000-000000000000'.) and the receiver script is trying to find either something with the name indicated by str or the key indicated by id.

What information are you trying to pass to the receiver and what's it supposed to do with it?






I fixed it hehe ty man you gave me just enuff to figure it out on my own xD

I UPDATED THE ABOVE SCRIPTS TO THE FIXED ONES


TURRET SCRIPT:


//cache this global variable to not have to compute it again and again
rotation rot90OnZ;
// Strength and damping are values used to control how llRotLookAt and llLookAt move, these values are tunable.
float strength = 1.0;
float damping = 1.0;
key owner;

default
{

state_entry()
{
//first save a rotation we'll be usign later:
rot90OnZ = llEuler2Rot(<0,0,PI_BY_TWO>;);
llSay(0, "Ready For Operation";);
llSensorRepeat( "", "",AGENT,96, PI,0.2);
}
link_message(integer sender, integer num, string msg, key id)
{

if (num == 89769)
{
llSensorRepeat("","", AGENT, 20.0, TWO_PI, 0.2);
llSetText("", <1,1,1>, 1);


}


if (num == 98769)
{
llSensorRemove();

}

}

sensor(integer sense)
{
vector target = llDetectedPos(0); // A vector to look at.
target = target - llGetPos(); //make it local
//the direction of the target, normalized:
vector wantedFwd = llVecNorm(target);
//taking the horizontal component of the target vector,
//and rotating it 90 degrees around Z to get a horizontal
//vector pointing pependicular to the target:
vector wantedLeft=llVecNorm(<target.x, target.y, 0.0>;) * rot90OnZ;
//create a global rotation that would satisfy these 2 vectors
rotation rot = llAxes2Rot(wantedFwd, wantedLeft, wantedFwd % wantedLeft);
//make the object look at the rotation:
llRotLookAt(rot, strength, damping);
//llSetRot(rot);


}
}





All thats left to fixed is:


- it Drops 2 shell s. Happens when I say RC/Turret or hit YES/NO on premission window. I also get a message in the bottom right hand corner saying"Unable to complete requested Object. Object is missing from Database."

- When the menu is up if I choose "No" the Sensor activates anyways and follows what ever I look at as if I press yes. with no fire control.

- if I hit No I get a message saying " Script trying to take controls from owner but PERMISSION_TAKE_CONTROLS permission not set!"

-When I set the gun to silencer mode both shooting sounds play. Silencer and Normal gun fire








rifle.casings Script


default
{
link_message(integer sender_num,integer num,string str,key id)
{
if(str == "fire";)
{
integer ammo = (integer)llGetObjectDesc();
if(ammo > 0)
{
llRezObject("shell",llGetPos() + <llFrand(1.0),llFrand(1.0),0>,ZERO_VECTOR,llGetRot(),0);
}
}

}
}





rifle.casings2 Script


integer effects = TRUE;
default
{
link_message(integer sender_num,integer num,string str,key id)
{

if(str == "fire" && id == (string)"2" || str == "fire" && id == (string)"3";)
{
integer ammo = (integer)llGetObjectDesc();
if(ammo > 0)
{
llRezObject("shell",llGetPos() + <llFrand(1.0),llFrand(1.0),0>,ZERO_VECTOR,llGetRot(),0);
}
}

}
}
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
More.
08-30-2008 03:20
In the first script you also have:
From: someone

link_message(integer sender,integer num, string message, key id)
{
if (num == 35432) //Remote Control On
{
GetPerms(llGetOwner());

}
if (num == 54368) // Remote Control Off
{
llReleaseControls();
llSensorRemove();
llSetText("", <1,1,1>, 1);
}

}

sensor(integer sense)
{

rotation k = llDetectedRot(0);
llRotLookAt(k, 1, 1);
}
no_sensor()
{

}


If you want remote controle you request permision. You have however allready requested permission at startup so there's a conflict.
Change this to: if (!gotperms) GetPerms(llGetOwner());
And switching to turretmode releases the controls, so you should add: gotperms = 0;

Furthermore, you've got a sensor in here that's also in the turretscript. I'ld remove that.

This would make the above snippet look like:

CODE


link_message(integer sender,integer num, string message, key id)
{
if (num == 35432){ //Remote Control On
if (!gotperms) GetPerms(llGetOwner());
}
else if (num == 54368){ // Remote Control Off
llReleaseControls();
gotperms = 0;
llSetText("", <1,1,1>, 1);
}
}



I also noticed you have a gotperms = TRUE in the touch event.
This should really only be set in the runtime permissions since touching doesn't mean giving permission.

Finally. Since it's a turret, there really is no need for all the reloading animations and stuff. The attach event seems redundant as well.
However I may be missing the bigger picture :)

p.s.
I've helped.
Where's my little pet noob! :D
Ody Naglo
Registered User
Join date: 1 Apr 2008
Posts: 31
08-30-2008 03:52
Ron Khondji that didnt solve my problems at all. Everything still works the same as it did b4 =P this script is driving me nuts xD