by FDARI » Sat Dec 17, 2011 8:02 am
If an actor that has no target or tracer compares AAPTR_TARGET and AAPTR_TRACER with this function, they will be treated as equal, because they are both null references. Is that the best behaviour? In most situations, you will want to "act" only if they are the same
and non-null. If you'd end up adding
&& !ComparePointer(AAPTR_TARGET, AAPTR_NULL) a lot, you might be happier with a function that returns false/does not jump, if an actor is NULL. I could rewrite it that way, but you'd have to go a little further to check specifically for null, and to allow two null-pointers to be equal.
Current methods:
Pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)
Pointer is null: ComparePointers(AAPTR_SOMETHING, AAPTR_NULL)
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE) && !ComparePointers(AAPTR_SOMETHING, AAPTR_NULL)
Alternative methods:
Pointer equality: Not built in
Pointer is null: Not built in
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)
For specific needs you could complement the alternative method (non-null pointer equality only) with an ACS library / function:
Spoiler: Pointer existence tests
Code: Select all
#define script_ptrtest 1
function int ActorExists(int tid, int ptr)
{
return ACS_ExecuteWithResult(script_ptrtest, tid, ptr);
}
script script_ptrtest (int tid, int ptr)
{
SetResultValue(SetActivator(tid, ptr));
}
Pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE) || !(ActorExists(0, AAPTR_SOMETHING) || ActorExists(0, AAPTR_ELSE)) // They're non-null equal or both null
Pointer is null: !ActorExists(0, AAPTR_SOMETHING)
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)
There are many ways to set up that script and function, or just a script. I ran the SetActivator() in a separate script instance so that it won't affect the calling script.
If an actor that has no target or tracer compares AAPTR_TARGET and AAPTR_TRACER with this function, they will be treated as equal, because they are both null references. Is that the best behaviour? In most situations, you will want to "act" only if they are the same [i]and[/i] non-null. If you'd end up adding [i]&& !ComparePointer(AAPTR_TARGET, AAPTR_NULL)[/i] a lot, you might be happier with a function that returns false/does not jump, if an actor is NULL. I could rewrite it that way, but you'd have to go a little further to check specifically for null, and to allow two null-pointers to be equal.
Current methods:
Pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)
Pointer is null: ComparePointers(AAPTR_SOMETHING, AAPTR_NULL)
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE) && !ComparePointers(AAPTR_SOMETHING, AAPTR_NULL)
Alternative methods:
Pointer equality: Not built in
Pointer is null: Not built in
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)
For specific needs you could complement the alternative method (non-null pointer equality only) with an ACS library / function:[spoiler=Pointer existence tests][code]#define script_ptrtest 1
function int ActorExists(int tid, int ptr)
{
return ACS_ExecuteWithResult(script_ptrtest, tid, ptr);
}
script script_ptrtest (int tid, int ptr)
{
SetResultValue(SetActivator(tid, ptr));
}[/code]Pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE) || !(ActorExists(0, AAPTR_SOMETHING) || ActorExists(0, AAPTR_ELSE)) // They're non-null equal or both null
Pointer is null: !ActorExists(0, AAPTR_SOMETHING)
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)
There are many ways to set up that script and function, or just a script. I ran the SetActivator() in a separate script instance so that it won't affect the calling script.[/spoiler]