Custom Function does not exist?

Post » Tue Jun 19, 2012 8:00 pm

I'm trying to create a custom function in a script. But when I save it, I get an error saying it " is not a function or does not exist"

I even pasted this example from the wiki, but it gave me the same error...

ReferenceAlias Property QuestGiver AutoReferenceAlias Property QuestGiverBackup Autoint Property QuestGiverKiller auto conditional  ;0 = unset, 1 = player, -1 not the playerfunction HandleQuestGiverDeath(Actor Killer, ReferenceAlias DeadActorAlias)   if DeadActorAlias == QuestGiver	 QuestGiver.ForceRefTo(QuestGiverBackup.GetReference())	 SetStage(110)	  if Killer == Game.GetPlayer()		 QuestGiverKiller = 1	  else		 QuestGiverKiller = -1	  endIf   endifendFunction


What am I missing? :-P
User avatar
Amanda Furtado
 
Posts: 3454
Joined: Fri Dec 15, 2006 4:22 pm

Post » Tue Jun 19, 2012 1:53 pm

Maybe I'm getting my extensions and pointers mixed up :-P
This is the relevant part of the script I have...

Spoiler

Scriptname SAWDOnHit extends ActiveMagicEffect{SAWD OnHit Damage Calculation}Keyword property VendorItemAnimalHide autoKeyword property ArmorMaterialDaedric autoKeyword property ArmorMaterialDragonplate autoKeyword property ArmorMaterialDragonscale autoKeyword property ArmorMaterialDwarven autoKeyword property ArmorMaterialEbony autoKeyword property ArmorMaterialElven autoKeyword property ArmorMaterialElvenGilded autoKeyword property ArmorMaterialGlass autoKeyword property ArmorMaterialHide autoKeyword property ArmorMaterialImperialHeavy autoKeyword property ArmorMaterialImperialLight autoKeyword property ArmorMaterialImperialStudded autoKeyword property ArmorMaterialIron autoKeyword property ArmorMaterialIronBanded autoKeyword property ArmorMaterialLeather autoKeyword property ArmorMaterialOrcish autoKeyword property ArmorMaterialScaled autoKeyword property ArmorMaterialSteel autoKeyword property ArmorMaterialSteelPlate autoKeyword property ArmorMaterialStormcloak autoKeyword property ArmorMaterialStudded autoKeyword property ArmorNightingale autoKeyword property ArmorDarkBrotherhood autoKeyword property ArmorCuirass autoKeyword property VendorItemArrow autoKeyword property WeapTypeBoundArrow autoKeyword property WeapTypeBow autoKeyword property WeapTypeDagger autoKeyword property WeapTypeSword autoKeyword property WeapTypeGreatsword autoKeyword property WeapTypeWarAxe autoKeyword property WeapTypeBattleaxe autoKeyword property WeapTypeMace autoKeyword property WeapTypeWarhammer autoKeyword property WeapTypeStaff autoKeyword property WeapMaterialDaedric autoKeyword property WeapMaterialDraugr autoKeyword property WeapMaterialDraugrHoned autoKeyword property WeapMaterialDwarven autoKeyword property WeapMaterialEbony autoKeyword property WeapMaterialElven autoKeyword property WeapMaterialFalmer autoKeyword property WeapMaterialFalmerHoned autoKeyword property WeapMaterialGlass autoKeyword property WeapMaterialImperial autoKeyword property WeapMaterialIron autoKeyword property WeapMaterialOrcish autoKeyword property WeapMaterialSilver autoKeyword property WeapMaterialSteel autoKeyword property WeapMaterialWood autoSPELL PROPERTY SAWDStagger2 AUTOSPELL PROPERTY SAWDStagger AUTOSPELL PROPERTY SAWDKneel AUTOSPELL PROPERTY SAWDDamageHeavy AUTOSPELL PROPERTY SAWDDamageModerate AUTOSPELL PROPERTY SAWDDamageLight AUTOSPELL PROPERTY SAWDBleedHeavy AUTOSPELL PROPERTY SAWDBleedModerate AUTOSPELL PROPERTY SAWDBleedLight AUTOActor property Target autoint ResistPenetration = 0int ResistCut = 0int ResistConcussion = 0Event OnEffectStart(Actor akTarget, Actor akCaster)Target = akTargetendEventFunction DetectArmorResistances(Actor Target)If ( Target.WornHasKeyword(ArmorCuirass))  ResistPenetration = 0  ResistCut = 0  ResistConcussion = 0  If ( Target.WornHasKeyword(ArmorMaterialDaedric))   ResistPenetration = 250   ResistCut = 250   ResistConcussion = 250  ElseIf ( Target.WornHasKeyword(ArmorMaterialDragonplate))   ResistPenetration = 225   ResistCut = 225   ResistConcussion = 225  ElseIf ( Target.WornHasKeyword(ArmorMaterialEbony))   ResistPenetration = 200   ResistCut = 200   ResistConcussion = 200  ElseIf ( Target.WornHasKeyword(ArmorMaterialDwarven))   ResistPenetration = 175   ResistCut = 170   ResistConcussion = 175  ElseIf ( Target.WornHasKeyword(ArmorMaterialOrcish))   ResistPenetration = 150   ResistCut = 150   ResistConcussion = 150  ElseIf ( Target.WornHasKeyword(ArmorMaterialDragonscale))   ResistPenetration = 150   ResistCut = 150   ResistConcussion = 150  ElseIf ( Target.WornHasKeyword(ArmorMaterialImperialHeavy))   ResistPenetration = 140   ResistCut = 140   ResistConcussion = 140  ElseIf ( Target.WornHasKeyword(ArmorMaterialSteelPlate))   ResistPenetration = 130   ResistCut = 130   ResistConcussion = 130  ElseIf ( Target.WornHasKeyword(ArmorMaterialGlass))   ResistPenetration = 130   ResistCut = 130   ResistConcussion = 130    ElseIf ( Target.WornHasKeyword(ArmorMaterialSteel))   ResistPenetration = 120   ResistCut = 120   ResistConcussion = 120  ElseIf ( Target.WornHasKeyword(ArmorMaterialIronBanded))   ResistPenetration = 110   ResistCut = 110   ResistConcussion = 110  ElseIf ( Target.WornHasKeyword(ArmorMaterialElvenGilded))   ResistPenetration = 110   ResistCut = 110   ResistConcussion = 110    ElseIf ( Target.WornHasKeyword(ArmorMaterialIron))   ResistPenetration = 100   ResistCut = 100   ResistConcussion = 100  ElseIf ( Target.WornHasKeyword(ArmorMaterialElven))   ResistPenetration = 100   ResistCut = 100   ResistConcussion = 100    ElseIf ( Target.WornHasKeyword(ArmorMaterialScaled))   ResistPenetration = 75   ResistCut = 90   ResistConcussion = 60  ElseIf ( Target.WornHasKeyword(ArmorMaterialImperialStudded))   ResistPenetration = 60   ResistCut = 80   ResistConcussion = 40    ElseIf ( Target.WornHasKeyword(ArmorMaterialStormcloak))   ResistPenetration = 50   ResistCut = 75   ResistConcussion = 35  ElseIf ( Target.WornHasKeyword(ArmorNightingale))   ResistPenetration = 50   ResistCut = 35   ResistConcussion = 30    ElseIf ( Target.WornHasKeyword(ArmorMaterialStudded))   ResistPenetration = 45   ResistCut = 35   ResistConcussion = 30  ElseIf ( Target.WornHasKeyword(ArmorMaterialImperialLight))   ResistPenetration = 40   ResistCut = 30   ResistConcussion = 25  ElseIf ( Target.WornHasKeyword(ArmorMaterialLeather))   ResistPenetration = 40   ResistCut = 30   ResistConcussion = 25    ElseIf ( Target.WornHasKeyword(ArmorDarkBrotherhood))   ResistPenetration = 30   ResistCut = 30   ResistConcussion = 20  ElseIf ( Target.WornHasKeyword(ArmorMaterialHide))   ResistPenetration = 15   ResistCut = 15   ResistConcussion = 15  ElseIf ( Target.WornHasKeyword(VendorItemAnimalHide))   ResistPenetration = 15   ResistCut = 15   ResistConcussion = 15    Else   ResistPenetration = 0   ResistCut = 0   ResistConcussion = 0  EndIfEndIfendFunctionEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)  if akBaseObject as Armor	Target.DetectArmorResistances()  endIfendEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)  if akBaseObject as Armor	Target.DetectArmorResistances()  endIfendEvent

It doesn't recognize the function "DetectArmorResistances"
What can I do to fix that?
User avatar
Keeley Stevens
 
Posts: 3398
Joined: Wed Sep 06, 2006 6:04 pm

Post » Tue Jun 19, 2012 8:42 am

You've used 2 Target vars here.
The property one is of type Actor, and that's where you have the compiler hunting for DetectArmorResistances when you use Target.DetectArmorResistances().

You declare that function in this script, so it doesn't need a prefix, and also it takes an Actor as a param.
So that would be DetectArmorResistances(Target).

Inside that function, 'Target' will be referring to the passed-in parameter, not the script-global of the same name.
That's not a problem to the compiler, but makes your code harder to understand.
If you call the function parameter fTarget, then you can still access the script-global Target if needed, and your heas is less likely to explode when you look at your code in a few months time :)
User avatar
Alan Whiston
 
Posts: 3358
Joined: Sun May 06, 2007 4:07 pm

Post » Tue Jun 19, 2012 8:28 pm

The function should be called like this:
DetectArmorResistances(Target)

because you defined it as such:
Function DetectArmorResistances(Actor Target)

But like Tuna said, you can't use Target inside the function because it's already defined at the script-global level. Technically, if Target is already defined, you shouldn't even need to pass it to the function.

Before you go too much further though, I have to ask. Are you trying to get "OnObjectEquipped" events from within the MagicEffect? Those need to be in the Actor Script as far as I know.
User avatar
Darren
 
Posts: 3354
Joined: Wed Jun 06, 2007 2:33 pm

Post » Tue Jun 19, 2012 12:03 pm

Thank you all! It seems to work now! :-D


Before you go too much further though, I have to ask. Are you trying to get "OnObjectEquipped" events from within the MagicEffect? Those need to be in the Actor Script as far as I know.

Yes, I'm a very bad boy :-P

Using a script that extends ActiveMagicEffect is the only way I could figure out to get my script to apply to racial spells.

I had to use the "OnEffectStart" event to get the target of the magic effect... which is hopefully giving me the ability to use the function with the actor in particular.
User avatar
Rach B
 
Posts: 3419
Joined: Thu Mar 08, 2007 11:30 am


Return to V - Skyrim