Access to functionsvariables in other scripts

Post » Sat Aug 17, 2013 10:21 pm

Because I frequent here so much my questions regarding this span over three or four "Quick Questions, Quick Answers" already so it makes much more sense to make an own thread for this.

I've made this script:
Scriptname myScriptParent extends QuestmyScriptChild property Child auto
and this:
Scriptname myScriptChild extends Quest
compiled both, went into the Creation Kit, made the Quest "myScriptParent" and "myScriptChild", attached the appropriate script to each quest, and added the quest "myScriptChild" as property to the script "myScriptParent".

Then I've made a function for the parent script I can call on will to test some features and expanded both scripts:
Scriptname myScriptParent extends QuestmyScriptChild property Child autofunction atWill()		int randomInt = Memory.test()		debug.Notification("RandomInt is " + randomInt)		Memory.aVal = True		debug.Notification("Memory.aVal is " + Memory.aVal)	endFunction
and
Scriptname myScriptChild extends Questbool property aVal auto hiddenevent OnInit()		aVal = False	endEventint function test()		debug.Notification("Menu.test started")		debug.Notification("aVal is " + aVal)		return 10	endFunction


Calling a function of a different script works fine (the message "Menu.test started" appears ingame), setting a variable of a variable and then printing it works fine, too (the message "aVal is True" appears ingame).
However when I want to read a variable of a different script or getting the return value of a function of a different script the game starts to behave strangely; the next messages I get are ""RandomInt is 0" and "RandomInt is 10" (yes, I get both messages even though I only have the line once in my script), likewise the next messages are "Memory.aVal is False" and "Memory.aVal is True".
I've tested it with other variables, e.g. string, and got "String is " and "String is test" as message. The patter seems to be: If the variable has the default value (e.g. 0 for int and float, False for bool, "" for string etc.) the (correct) message only appears once, but when the varible has a different value (e.g. "test" instead of "") first the default value and then the correct value is printed.

I've even tried this:
function onWill()		if Memory.aVal		debug.Notification("Memory.aVal is True")	else		debug.Notification("Memory.aVal is False")	endIf	endFunction
Ingame BOTH messages appeared.



Here's my papyrus.log:
[08/17/2013 - 02:49:39PM] ERROR: Cannot call test() on a None object, aborting function callstack:	[ (330012C4)].myScriptParent.test() - "myScriptParent.psc" Line 45	[ (330012C4)].myScriptParent.onWill() - "myScriptParent.psc" Line 39[08/17/2013 - 02:49:39PM] warning: Assigning None to a non-object variable named "::temp0"stack:	[ (330012C4)].myScriptParent.test() - "myScriptParent.psc" Line 45	[ (330012C4)].myScriptParent.onWill() - "myScriptParent.psc" Line 39


It seems that I make something wrong when trying to access functions/variables from other scripts but I don't know what.
User avatar
Sheeva
 
Posts: 3353
Joined: Sat Nov 11, 2006 2:46 am

Return to V - Skyrim