Jump to content
ℹ️ Intermittent Download History issues ×

Calling Functions from Other Scripts


AlexanderCription

Recommended Posts

I've been looking into this for a few hours now, mostly looking at solutions found through Google, and either the solution generates an error I don't understand or it simply does nothing.

 

Quest Objects:

_BloodThirst_MainQuest - Start Game Enabled and is used to store experience and level int properties

_BloodThirst_KillUpdate - Kill Actor Event Enabled, the quest resets to allow it to be re-obtained, and is used to update the experience and level int properties in the MainQuest

 

Basic Mod Description:

Every time the player kills an NPC the player gains X Bloodthirst experience.

 

Current Script Setup:

Quest/Script: _BloodThirst_MainQuest, BloodThirst_MainScript

Scriptname BloodThirst_MainScript extends Quest

Int Property thirstLevel Auto  
Int Property thirstExp Auto 

Function UpdateThirst()

	thirstExp = thirstExp + 1
	debug.notification("Bloodthirst Exp: " + thirstExp)

EndFunction

Event OnInit()

	Debug.Notification("Bloodthirst Loaded")

EndEvent

Quest/Script: _BloodThirst_KillUpdate, BloodThirst_UpdateScript

Scriptname BloodThirst_UpdateScript extends Quest

Quest Property ThisQuest  Auto
BloodThirst_MainScript Property MainScript Auto

Event OnStoryKillActor(ObjectReference akVictim, ObjectReference akKiller, Location akLocation, int aiCrimeStatus, \
  int aiRelationshipRank)

	MainScript.UpdateThirst()

	ThisQuest.Reset()

endEvent

Issue with setup:

The current setup compiles fine, but in game when a kill happens the function UpdateThirst() does not run. I have tested it in game with "Debug.Notification(MainScript.thirstExp)" and it displays the exp value, which is 0; however, for some reason it will not run the function.

 

I have tried using full properties with the Quest.GetQuest"xxxx" function get(), and the setup using GetLinkedRef() which gave an error about not being able to cast a none to a quest I believe. This has been the only setup that doesn't give a compiler error.

 

After a bit I started looking at the source scripts of some of the mods I have installed and found that XPMSE uses the same setup and is able to call their functions fine; this confused me even more.

 

So, if you know what I'm doing wrong or know of another way that works, let me know.

 

Thanks,

 

P.S. C++ was easier to learn than this...

 

Link to comment
Share on other sites

try

Scriptname BloodThirst_UpdateScript extends Quest

import BloodThirst_MainScript

Quest Property ThisQuest  Auto

Event OnStoryKillActor(ObjectReference akVictim, ObjectReference akKiller, Location akLocation, int aiCrimeStatus, \
  int aiRelationshipRank)

	BloodThirst_MainScript.UpdateThirst()

	ThisQuest.Reset()

endEvent

I don't work with quest scripts often, but I think the above should work.

Link to comment
Share on other sites

try

Scriptname BloodThirst_UpdateScript extends Quest

import BloodThirst_MainScript

Quest Property ThisQuest Auto

Event OnStoryKillActor(ObjectReference akVictim, ObjectReference akKiller, Location akLocation, int aiCrimeStatus, \
int aiRelationshipRank)

BloodThirst_MainScript.UpdateThirst()

ThisQuest.Reset()

endEvent

I don't work with quest scripts often, but I think the above should work.

 

 

Thanks for the reply.

 

I ended up getting this error "cannot call the member function UpdateThirst alone or on a type, must call it on a variable". Not exactly sure what this means, but at least the compiler is saying something.

 

Update: I was able to get it to compile using (MainScript as BloodThirst_MainScript).UpdateThirst() but it still doesn't run the function.

Edited by AlexanderCription
Link to comment
Share on other sites

Did you fill the properties including the one for the script? That's the first thing to check when scripts, objects and the like are not communicating as expected. I see nothing wrong with your scripts.

 

Ahhh, it looks like I didn't fill the property for the MainScript. Which is interesting, I would have never thought of that. I assumed the compiler would pick up something like that.

 

Thank you, I thought the creation kit just hated me.

Edited by AlexanderCription
Link to comment
Share on other sites

The compiler does pick up that the script exists which is why it is able to compile. But the record that the script is attached to has no idea if the script or any other objects in use on the script exist without being explicitly told. Properties is how we tell that record what we intend to use.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...