Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script not resetting on inventory change

Snickers Snook
Odd Princess - Trout 7.3
Join date: 17 Apr 2007
Posts: 746
01-13-2010 18:43
Is this the correct way to reset scripts within an object to figure out when the owner changes? It didn't work for a friend of mine I gave one of my scripty things to. It's in the "Running" state which is where all my code is. Should it be in Entry?

changed(integer change) {
if ((change & (CHANGED_INVENTORY | CHANGED_OWNER))) {
hide_me();
llResetScript();
}
_____________________

Buh-bye forums, it's been good ta know ya.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-13-2010 19:00
/me scratches her head. Looks right to me.

The state_entry does something that makes it obvious that the script has reset?

Do you have multiple states in the script? Only the changed event for the current state should get fired.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
01-13-2010 19:01
From: Snickers Snook
Is this the correct way to reset scripts within an object to figure out when the owner changes? It didn't work for a friend of mine I gave one of my scripty things to. It's in the "Running" state which is where all my code is. Should it be in Entry?

changed(integer change) {
if ((change & (CHANGED_INVENTORY | CHANGED_OWNER))) {
hide_me();
llResetScript();
}


no...
CODE

changed (integer change)
if (change && CHANGED_OWNER)
{
// owner changed....
}

is the right way. (make sure you do your brackets like to to tee off Void too :) )

CHANGED_INVENTORY refers to the object inventory, not the avatar's inventory.... CHANGED_INVENTORY is used if say, you want to test if the object inventory has changed (i.e. a notecard is dropped in or edited).
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-13-2010 19:24
From: Johan Laurasia
no...
CODE

if (change && CHANGED_OWNER)


Er.. You sure about that? I think you have too many &'s in there.

What she has in the OP looks like it should reset if the object changes owners or if something in the objects inventor changes.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Snickers Snook
Odd Princess - Trout 7.3
Join date: 17 Apr 2007
Posts: 746
01-13-2010 19:32
Sindy is correct, If something changes in the object's inventory, ie. the chat card, i want the script to reset. Not the avatar's inventory.
_____________________

Buh-bye forums, it's been good ta know ya.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-13-2010 19:34
I'd put an 'llOwnerSay ("changed fired with " + (string)change);' right at the top of that changed event..
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
01-14-2010 00:55
I think you need to test for the two changes seperately; the way it's shown in the original post the test will only return TRUE if *both* the CHANGED_OWNER and CHANGED_INVENTORY flags are set. To trigger it if *either* flag is set try:

if (changed & CHANGED_INVENTORY || changed & CHANGED_OWNER)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-14-2010 02:03
not necessary bit wise comparisons with | (b-OR)combine to have all set bits in the comparison, and the & (b-AND) comparison operates to match bits that are set in both...

ex
pretend your two values for owner and inventory are the second and third positions
(001b | 010b) == 011b == (1 b-OR 2) ==3
now see what the possible mattches from the changed event would show
(001b & 011b) == 001b == (1 b-AND 3) ==1 (changed reports inventory)
(010b & 011b) == 010b == (2 b-AND 3) == 2 (changed reports owner)
(011b & 011b) == 011b == (3 b-AND 3) == 3 (changed reports both)
(100 & 011b) == 000b == (4 b-AND 3) == 0 (changed reported something else)

only 0 evaluates to false, all else evaluates to true, so as long as change reports one of the b-OR'd components and compares with b-AND it'll be something besides 0 and therefore true
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
01-14-2010 02:29
You are entirely correct, Void.

Which brings me back to wondering about the "Running" state Snickers mentions...

If they're talking about a declared state (and not the overall running/not running state of the script), could it be that while there's change event code in state Running the script is still in a different one - e.g. default.

And I've only just noticed the very last question, "Should it be in Entry?".

There seems to be some confusion over states and events here, and I'm not sure it isn't mine...
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-14-2010 06:45
From: Johan Laurasia
no...
CODE

changed (integer change)
if (change && CHANGED_OWNER)
{
// owner changed....
}

is the right way. (make sure you do your brackets like to to tee off Void too :) )
No, this code is incorrect.

The code inside the braces would get executed whenever "change" is nonzero -- i.e., on ANY change.

CHANGED_OWNER is nonzero, and therefore is always equavalent to TRUE for logical operators like "&&" and "||".

Be careful not to confuse logical operators with bitwise operators ("&" and "|";).
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-14-2010 06:49
Snicks, the problem is NOT with the code snipped you posted, so look elsewhere.

Your clause will execute (hide and reset) on owner change or inventory change, if the state is in that state.

So, make sure the script is in the state you think it is. For example, put an llSay() in the changed handler, before your test.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-14-2010 06:53
From: Pete Olihenge
I think you need to test for the two changes seperately; the way it's shown in the original post the test will only return TRUE if *both* the CHANGED_OWNER and CHANGED_INVENTORY flags are set. To trigger it if *either* flag is set try:

if (changed & CHANGED_INVENTORY || changed & CHANGED_OWNER)
This is equivalent to (but takes more byte code space than) the OP's.

Also, because there are some flaws with operator precedence that I can never recall exactly, I recommend adding more parens:

if ((changed & CHANGED_INVENTORY) || (changed & CHANGED_OWNER))
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-14-2010 07:04
From: Lear Cale
This is equivalent to (but takes more byte code space than) the OP's.

Also, because there are some flaws with operator precedence that I can never recall exactly, I recommend adding more parens:

if ((changed & CHANGED_INVENTORY) || (changed & CHANGED_OWNER))

been testing those...

& definitely has a higher precedent than || (everything except assignments to it's left has a higher precedent than || and && ) however the right side of that does get evaluated first...

when the operators precedence and evaluation article is done it'll be much clearer
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Dytska Vieria
+/- .00004™
Join date: 13 Dec 2006
Posts: 768
01-14-2010 08:07
Keep in mind there is a bug with CHANGED_INVENTORY. See https://jira.secondlife.com/browse/SVC-304
_____________________
+/- 0.00004
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-14-2010 10:41
For more about omitting parentheses:

https://jira.secondlife.com/browse/SVC-779

Evidently the issue only arises (at least, according to the jira) between "&&" and "||". In any case, it's wise to add more parens than you otherwise might.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-14-2010 22:55
From: Lear Cale
For more about omitting parentheses:

https://jira.secondlife.com/browse/SVC-779

Evidently the issue only arises (at least, according to the jira) between "&&" and "||". In any case, it's wise to add more parens than you otherwise might.

it's not a bug and Sian nailed it in the follow up comment... && and || have equal precedence which you can demonstrate with
(0&&0||1)!=(0&&;(0||1))
(1||0&&0)!=(1||(0&&0))

but thanks for the jira, I'll update it.
yeah, I know it's weird, I'm not sure if there is another language where they have equal precedence.... I really need to finish that Operator Precedence article.

ETA:
PS, Lear is right though; if you are sure which gets done first, use lots of parentheses to guarantee they get done in the order you expect. especially since this would fail (1 | 0 == 0) because equivalence is evaluated before bitwise OR.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-15-2010 05:16
From: Void Singer
it's not a bug
I'd call it a bug. No sensible person would intentionally design a language this way. They're Boolean operators, and in Boolean algebra, "and" s a multiplicative operator whereas "or" is an additive one, with the same algebraic properties of those operators.

However, it's the kind of bug we have to live with. If they fixed it, it would break content.

The precedence of bitwise operators in C makes no sense either, but fortunately that of the logical ones do. I've never seen any rationale for C's bitwise operator precedence, which is way too low, so we've all learned to always use parens whenver using them.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-15-2010 06:46
personally I'd have stuck with standard operator precedence, but then if I'd had my fruthers, that wouldn't be the same either so I feel ya.... it's not a bug, because it was done by design... no matter how poor the design choice ;)

although I'm not sure treating them as single bit multiplicative, or additive is useful when there aren't actually boolean types involved (because in this case those types of comparisons could overflow, unless they are first converted)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-15-2010 08:17
From: Void Singer
.... it's not a bug, because it was done by design... no matter how poor the design choice ;)
Really? Show me the design document.

From: someone
although I'm not sure treating them as single bit multiplicative, or additive is useful when there aren't actually boolean types involved (because in this case those types of comparisons could overflow, unless they are first converted)
These are *boolean* operators. The operands are by definition booleans (e.g., integers converted to TRUE/FALSE values, where zero is FALSE and any nonzero value is TRUE).

The operators are additive and multiplicative only in terms of their properties vis-a-vis distibutive, associative, and commutative properties, and what that implies for the most appropriate precedence order. Forget about overflow, which can't happen for boolean operations.

Seriously, I doubt there's no defense of this, other than "that's how it works, so live with it." If there is a good defense, I'd be interested to hear it.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-15-2010 08:17
We have a term for this in the industry: "Operating as implemented".

:-)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-15-2010 12:43
From: Lear Cale
Really? Show me the design document.

oh come on, you know as well as I that it couldn't happen accidentally =P

From: someone
These are *boolean* operators. The operands are by definition booleans (e.g., integers converted to TRUE/FALSE values, where zero is FALSE and any nonzero value is TRUE).

heh, seems like I just had this discussion... and I can't prove that they aren't being converted to booleans, although that implies an internal typing that would be another layer and another slowdown... if I had to guess, I'd think they're being done as if chains, testing for zero.

From: someone
The operators are additive and multiplicative only in terms of their properties vis-a-vis distibutive, associative, and commutative properties, and what that implies for the most appropriate precedence order. Forget about overflow, which can't happen for boolean operations.

that's just another reason I'm not sure they are are true boolean operations.

From: someone
Seriously, I doubt there's no defense of this, other than "that's how it works, so live with it." If there is a good defense, I'd be interested to hear it.

I can think of one... we both said it... if we had our choice we'd do it differently... looks like he did (is it sad that I can't remember who wrote it? was it cory? I forget)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-15-2010 13:35
If they aren't boolean operators, what are they?

It doesn't matter whether integer values are converted to 0's and 1's; whether that happens or not is merely an implementation detail.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-16-2010 03:56
I'll concede that it doesn't really really matter how it's implemented, other than us ending up with equal precedence for those two operators...

the point I was trying to push was that because they are equal precedence, treating them as boolean multiplication/addition implies a different precedence, so might not be very helpful to people learning LSL as treating them as plain comparisons.

ps
as a funny aside, it may be that the else end of an if executes faster in this implementation, but I'd have to test, and I doubt it's a useful difference.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -