Major Issue with Papyrus

Post » Sat Jan 07, 2017 2:43 pm

I found a huge problem in Papyrus: the expression None != AnyVariable always returns false.



It happens because the variable gets cast to the None type, and all Nones are None. So None == AnyVariable is automatically true in Papyrus.



If the order looks weird, bear in mind that courses in Java and C often recommend doing it that to avoid certain stupid errors. But it sure as heck doesn't work in Papyrus.



Do people know about this? Are there other references to this issue?

User avatar
Matthew Barrows
 
Posts: 3388
Joined: Thu Jun 28, 2007 11:24 pm

Post » Sat Jan 07, 2017 5:32 am

Not an issue. Papyrus is not Java, so write the code the way the compiler expects it. If AnyVaiable != None produces the right result, then that's the way to write it.

User avatar
Adam
 
Posts: 3446
Joined: Sat Jun 02, 2007 2:56 pm

Post » Sat Jan 07, 2017 1:58 pm

The standard idiom in Papyrus to check for a valid reference is the same as using a boolean variable in a condition. You should just be using the variable itself as the test.



if SomeReference
; do things with SomeReference
endif

Short-circuit operators do work, so code like this is fairly common.



if SomeRef && SomeRef.GetDistance(PlayerRef)
; do something
endif

There are also cases where you need to check the type of the reference.



if SomeRef as Actor
; use some function that only works on actors
endif
User avatar
Chris Ellis
 
Posts: 3447
Joined: Thu Jul 26, 2007 10:00 am


Return to V - Skyrim