Using functions of another script

Post » Tue Jul 23, 2013 10:00 pm

I've seen a few mods that somehow managed to call a function from a different script but I'm unable to do this myself.

Basically I have this main script:

Scriptname MainScript extends Quest{Main Script}ScriptTest Property test Autoint x = 0x = test.counter(x)

And want to call a function from this test script:

Scriptname TestScript extends Quest  {Test Script}int function counter(int x)    x += x    return xEndFunction

However the compiler always throws out the error that "no viable input at '.'".

What do I have to do to be able to call a function from another script?

User avatar
SWagg KId
 
Posts: 3488
Joined: Sat Nov 17, 2007 8:26 am

Post » Wed Jul 24, 2013 10:12 am

Hi,

first of all you have to compile the to be called script first, then the calling script, so the calling script knows about the to be called.

Second, any statements must be in a Function or a Event block.

Chnage your MainScript like this (and check the spelling TestScript <-> ScriptTest)

Scriptname MainScript extends Quest{Main Script}TestScript Property mytest Autofunction testfunc()	int x = 0	x = mytest.counter(x)endfunction

-docblacky

User avatar
QuinDINGDONGcey
 
Posts: 3369
Joined: Mon Jul 23, 2007 4:11 pm

Post » Wed Jul 24, 2013 10:45 am

The solution was way too simple. -.-

Thanks for the quick help.
User avatar
ladyflames
 
Posts: 3355
Joined: Sat Nov 25, 2006 9:45 am

Post » Tue Jul 23, 2013 8:18 pm

I'll attempt to explain this...with an example code.

Scriptname myParentQuestScript extends Quest; Lets say you want to pull functions from this Quest script.; The name of the Quest this script is attached to is myParentQuest. Function myQuestFunction()
Scriptname myChildQuestScriptTest extends Objectreference Quest property myParentQuest auto Event Example() myParentQuestScript myQuestVariable = myParentQuest as myParentQuestScript myQuestVariable.myQuestFunction()EndEvent

Hope that helps.

User avatar
Eoh
 
Posts: 3378
Joined: Sun Mar 18, 2007 6:03 pm


Return to V - Skyrim