Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

HORRIBLE script... help me xD

Remus Cooper
Second Life Resident
Join date: 26 Nov 2004
Posts: 7
04-05-2005 09:04
From: someone

float settingx = FALSE;
float settingy = FALSE;
float settingz = FALSE;
float portset = FALSE;
vector posloc;
string posx;
string posy;
string posz;


default
{
state_entry()
{
llListen(0, "", llGetOwner(), "";);
float settingx = FALSE;
float settingy = FALSE;
float settingz = FALSE;
float portset = FALSE;
}
listen(integer channel, string name, key id, string message)
{
if (message == "set";) {
settingx = TRUE;
settingy = TRUE;
settingz = TRUE;
llSay(0, "input x";);
}
if (settingx == TRUE) {
posx = message;
settingy = TRUE;
settingx = FALSE;
llSay(0, "input y";);
}
if (settingy == TRUE) {
posy = message;
settingz = TRUE;
settingy = FALSE;
llSay(0, "input z";);
}
if (settingz == TRUE) {
posz = message;
settingz = FALSE;
portset = TRUE;
posloc = <;(string)posx,(string)posy,(string)posz>;
llSay(0, "ready to teleport to input coordinates";);
}
if (portset == TRUE) {
if (message == "port";) {
llSetPos((vector)posloc);
llResetScript();
}
}
}
}



NOW... I know this is horrible, but I would appreciate help... so no throwing up! you can do that AFTER you tell me whats wrong with my script! apart from all of it!
Kali Dougall
Purple and Spikey
Join date: 5 Feb 2005
Posts: 98
04-05-2005 09:28
I... I think I see what you're trying to do here. And I can guess why it's not doing what you want.

If you say "set," the code sets those three variables to true, right? Then without further ado, three if statements check whether they're true. Well, of course they're going to be true, you just set them. Maybe this is what you want:

CODE

listen(integer channel, string name, key id, string message) {
if (message == "set") {
settingx = TRUE;
llSay(0, "input x");
} else if (settingx == TRUE) {
posloc.x = (float)message;
settingy = TRUE;
settingx = FALSE;
llSay(0, "input y");
} else if (settingy == TRUE) {
posloc.y = (float)message;
settingz = TRUE;
settingy = FALSE;
llSay(0, "input z");
} else if (settingz == TRUE) {
posloc.z = (float)message;
settingz = FALSE;
portset = TRUE;
llSay(0, "ready to teleport to input coordinates");
} else if (message == "port" && portset == TRUE) {
llSetPos(posloc);
llResetScript();
}
}

I fixed a few things there... introduced you to the world of "else" and boolean operators... and also, you can set components of vectors directly (posloc.x) instead of using another variable, so I eliminated posx and so forth.

If you're so inclined, you could also give it the entire vector on one line of speech (`set 10 10 10'):
CODE

listen(integer channel, string name, key id, string message) {
list msglist = llParseString2List(message, [" "], []);
if (llList2String(msglist, 0) == "set") {
posloc.x = (float)llList2String(msglist, 1);
posloc.y = (float)llList2String(msglist, 2);
posloc.z = (float)llList2String(msglist, 3);
llSetPos(posloc);
}
}
Kali Dougall
Purple and Spikey
Join date: 5 Feb 2005
Posts: 98
04-05-2005 09:30
Oh, also, please avoid having listeners on channel 0, as all the traffic on this channel results in a bigger hit to sim performance. A higher channel (3, 11, 537538, doesn't matter) is easier on your sim. Have you hugged your sim today?
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
04-05-2005 09:32
Uhhhh.... :eek:

Trying to do something like this?

CODE
default
{
// Set position on channel 1 by saying position (ie. /1 <1,1,1>)
// Right-click and select "Teleport!"
state_entry()
{
llListen(1, "", llGetOwner(), "");
llSetSitText("Teleport!");
}

listen(integer chan, string name, key id, string msg)
{
llSitTarget((vector)msg - llGetPos(),<0,0,0,1>);
}

changed(integer change)
{
if(change & CHANGED_LINK)
{
llSleep(0.5);
llUnsit(llAvatarOnSitTarget());
}
}
}

Now then, as to your problem here...

First of all, if you want us to fix problems in general, please don't just say "Fix please" and post code. Tell us what you want the code to do so we can help you with your problem. I had to guess what you wanted to do based on what the code was saying.

The code here is a simpler means of "teleportation."


Second, as for your specific, code problems...

1) Vectors take floats for each subcommand (ie. <;(float)var,(float)var,(float)var>)
2) You can just input the whole thing at once, not one at a time, and just do (vector)msg
3) llSetPos is limited to 10m movements per llSetPos. You would need a loop if you used that, and it would be buggy.
4) You can just use the "sit hack" instead. That's what this does. This is untested, but it's generally the acceptible format... if the teleport is sending you in the wrong direction, flip llGetPos and (vector)msg.
_____________________
---
Remus Cooper
Second Life Resident
Join date: 26 Nov 2004
Posts: 7
04-05-2005 12:02
Egh... sorry, and thanks for replying =)

Yeah... I AM trying to make a teleport script here, but I don't have much experience with LSL (as with the vast majority of people who post "help" here, I guess), so thanks for the help ^_^. I'm used to scripting in my own, horrible, clunky way so thanks as well for giving me shorter scripts to play with... what I was trying to do was, rather than having a stationary cube that teleports, I was trying to make a teleport that is variable, ie it can teleport to different locations (duh ^_^). Jeff:I tried using (vector) but it didnt seem to want to work... but I get now what I did wrong (apart from scripting evilly in the first place).


thanks all ^_^
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
04-05-2005 12:19
Something no one else caught yet: if you want to store TRUE and FALSE values, the variable type you want is integer, not float. Change settingx, settingy, and settingz to integers. Comparing floats with == isn't sure to always work (although it will in this case).