Can't use inherited functions?

Post » Thu Aug 25, 2016 3:34 pm

I'm trying to write a simple program, however when I try to compile this I get this error:



Scriptname weapTest extends ObjectReference
{test script}

import Form
import Actor
import Weapon

Actor Property PlayerREF auto
Weapon Property weapT auto

String stringT;

Event OnActivate(ObjectReference akActionRef)
weapT = PlayerREF.GetEquippedWeapon(0)
stringT = weapT.GetDisplayName()
EndEvent

When I compile it I get this error: "GetDisplayName() is not a function"



The function I'm trying to use is from SKSE, however I don't think that explains what's going on. If I am understanding this correctly, Weapon inherits ObjectReference, so shouldn't Weapon also inherit it's functions too? Why can't I call the function on the inherited type? Is there something I'm doing wrong or a way around this?

User avatar
Robert DeLarosa
 
Posts: 3415
Joined: Tue Sep 04, 2007 3:43 pm

Post » Thu Aug 25, 2016 6:29 am

The Weapon script does not extend ObjectReference. Weapon extends Form, which is also the script that ObjectReference extends so both Weapon and ObjectReference branch off from Form. You could use the GetDisplayName function in the WornObject script. It is a bit different from the one in ObjectReference in that it would be called like this:



;GetDisplayName(Actor akActor, Int aiHandSlot, Int aiSlotMask)
stringT = WornObject.GetDisplayName(PlayerRef, 0, 0) ;Left hand
stringT = WornObject.GetDisplayName(PlayerRef, 1, 0) ;Right hand

By the way, you do not need to import scripts like you would in a language like Python. The Import statement just gives you access to global functions (functions defined in a script with the Global keyword) without having to type out the name of the script (unless leaving out the name of the script would make it ambiguous as a result of there being multiple scripts, imported or inherited, with a function with the same name).



;The definition of the Notification function in the Debug script (notice the Global keyword at the end).
;Function Notification(string asNotificationText) native global

;Without importing the Debug script:

Function SomeFunc()
Debug.Notification("How the function would be called without importing the Debug script.")
EndFunction


;When importing the Debug script:

Import Debug

Function SomeFunc()
Notification("How the same function could be called when importing the Debug script.")
EndFunction


;If the current script also had a definition for a function called Notification (or inherited one) and the Debug script was imported:

Import Debug

Function Notification(String asMessage)
;Some lines...
EndFunction

Function SomeFunc()
Self.Notification("This script's version of Notification")
Debug.Notification("The Debug script's version of Notification")
Notification("Compiler error. Ambiguous as to which version is to be used.")
EndFunction
User avatar
Sara Lee
 
Posts: 3448
Joined: Mon Sep 25, 2006 1:40 pm

Post » Thu Aug 25, 2016 4:51 am

And you should never import base script types like Form, Weapon, or Actor. Imports are for the library classes like Debug, Game, and Math.

User avatar
carly mcdonough
 
Posts: 3402
Joined: Fri Jul 28, 2006 3:23 am

Post » Thu Aug 25, 2016 9:54 am

Oh thank you! I feel dumb now. I don't know why I thought that Weapon extended ObjectReference, derp.

User avatar
Kanaoka
 
Posts: 3416
Joined: Fri Jun 16, 2006 2:24 pm


Return to V - Skyrim