Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Jump not jumping

Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
12-16-2007 12:27
The jump statement is pretty straightforward, but this is the first time I've used it, so perhaps there's some arcane knowledge I'm missing.

CODE

changed (integer intChange) {
if (intChange & CHANGED_ALLOWED_DROP) {
integer x;
integer intLoadCard = FALSE;

string strItemName;
integer intItemType;
key keyItemCreator;

integer intInvCount = llGetInventoryNumber(INVENTORY_ALL);

llSay(0, (string)intInvCount);

for (x=0; x<intInvCount; x++) {
strItemName = llGetInventoryName(INVENTORY_ALL, x);
keyItemCreator = llGetInventoryCreator(strItemName);
intItemType = llGetInventoryType(strItemName);

llSay(0, (string)x + " [" + strItemName + "]");

if (keyItemCreator == keyCreator) {
llSay(0, "My Creator!");
jump continue;
}

if (keyItemCreator == keyTenant
&& intItemType == INVENTORY_NOTECARD
&& strItemName == "Guest List") {
intLoadCard = TRUE;
jump continue;
}

llSay(0, "Kill it!!!!");

llRemoveInventory(strItemName);

@continue;
}
}
}


The "keyCreator" is elsewhere set to llGetCreator(). On inventory items belonging to the creator, I get both the "my creator" and "kill it" messages -- i.e. there is no jump.

Pardon the thread overloading, but also with this code, when the loop comes to the script itself, llGetInventoryName() returns a null string. I've tested it in other places, and it returns the script name with no problem. Any issues here I might not be aware of?
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
12-16-2007 12:41
From: Siann Beck
Pardon the thread overloading, but also with this code, when the loop comes to the script itself, llGetInventoryName() returns a null string. I've tested it in other places, and it returns the script name with no problem. Any issues here I might not be aware of?
I figured out this part -- deleting inventory items changes the numbering of the remaining ones; I need to make a list (yay!) of items to be deleted, and delete them after the loop (with, of course, another loop).
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
12-16-2007 23:55
The trick when deleting inventory is to loop BACKWARDS through the list.

for (x=(intInvCount-1);x>=0;x--)
{
}
Meroth Junge
Registered User
Join date: 25 Apr 2007
Posts: 21
12-17-2007 01:56
It seems by testing, that only one jump is allowed per label. See here: http://www.lslwiki.net/lslwiki/wakka.php?wakka=jump&show_comments=1

You can fix this by having @continue1; @continue2; one right after the other, and jump continue1; jump continue2; instead of one jump continue; used twice. Or you can structure your code better so that jumps are not needed :) (since, you know, using jumps is considered bad habit in programming).
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
12-17-2007 14:38
From: Meroth Junge
It seems by testing, that only one jump is allowed per label.
How bizarre!

From: Meroth Junge
Or you can structure your code better so that jumps are not needed :) (since, you know, using jumps is considered bad habit in programming).
That's what I ended up doing -- restructuring the code, but I don't know that I'd say it's better; I think the original was easier to read. And the old saw about jump == evil just ain't always so. No one says anything about such things as break and continue (what I was trying to emulate), and that's essentially what they are.
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
12-17-2007 14:58
The whole jump/break/continue handling in LSL is a complete crock IMNSHO :mad:


You might want to use lslint on your code, it will catch junk like this and other gotcha's like the compiler exceeding it's own stack!