Using properties in custom functions

Post » Mon Jun 18, 2012 8:14 am

I'm trying to call a function in a quest's script, from within a topic info fragment in the same quest, so I don't have to copypaste the code to every part of the dialog where I want to use it.

The function itself (which compiles just fine):
Scriptname nyczSBSScripts extends QuestMiscObject Property Gold001 AutoGlobalVariable Property nyczSBSAccount AutoFunction Deposit(int amount)  Game.GetPlayer().RemoveItem(Gold001, amount)  nyczSBSAccount.Mod(amount)endFunction

And the papyrus fragment that calls it: (from within a topic info)
nyczSBSScripts q = getowningquest() as nyczSBSScriptsq.Deposit(1000)

The problem is that it seems to ignore the property definitions in the main script when the function is called (during runtime). Do I have to define the properties locally in the fragment, or am I going about this all wrong?
User avatar
TOYA toys
 
Posts: 3455
Joined: Sat Jan 13, 2007 4:22 am

Post » Mon Jun 18, 2012 7:15 am

Apparently you have to. It works, I've used properties successfully in a fragment before.
User avatar
Raymond J. Ramirez
 
Posts: 3390
Joined: Sun Oct 14, 2007 8:28 am

Post » Mon Jun 18, 2012 1:53 pm

Apparently you have to. It works, I've used properties successfully in a fragment before.
I presume you refer to defining the properties in every fragment. I can use the properties in the code directly in the fragment, but not in the function I call.

This is the (relevant part of the) log:
[02/12/2012 - 03:07:09PM] error: Cannot add None to a containerstack:	[ (00000014)].Actor.RemoveItem() - "" Line ?	[nyczSBS (0C000D92)].nyczSBSScripts.Deposit() - "nyczSBSScripts.psc" Line 7	[topic info 0C000D99 on quest nyczSBS (0C000D92)].TIF__01000D99.Fragment_0() - "TIF__01000D99.psc" Line 10[02/12/2012 - 03:07:09PM] error: Cannot call Mod() on a None object, aborting function callstack:	[nyczSBS (0C000D92)].nyczSBSScripts.Deposit() - "nyczSBSScripts.psc" Line 8	[topic info 0C000D99 on quest nyczSBS (0C000D92)].TIF__01000D99.Fragment_0() - "TIF__01000D99.psc" Line 10[02/12/2012 - 03:07:09PM] warning: Assigning None to a non-object variable named "::temp2"stack:	[nyczSBS (0C000D92)].nyczSBSScripts.Deposit() - "nyczSBSScripts.psc" Line 8	[topic info 0C000D99 on quest nyczSBS (0C000D92)].TIF__01000D99.Fragment_0() - "TIF__01000D99.psc" Line 10

The full code of the fragment looks like this:
;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment;NEXT FRAGMENT INDEX 1Scriptname TIF__01000D99 Extends TopicInfo Hidden;BEGIN FRAGMENT Fragment_0Function Fragment_0(ObjectReference akSpeakerRef)Actor akSpeaker = akSpeakerRef as Actor;BEGIN CODEnyczSBSScripts q = getowningquest() as nyczSBSScriptsq.Deposit(100);END CODEEndFunction;END FRAGMENT;END FRAGMENT CODE - Do not edit anything between this and the begin commentMiscObject Property Gold001  AutoGlobalVariable Property nyczSBSAccount  Auto
User avatar
Katie Louise Ingram
 
Posts: 3437
Joined: Sat Nov 18, 2006 2:10 am

Post » Mon Jun 18, 2012 7:28 pm

Ok, I seem to have figured out a way to to it. Apparently functions called from another script ignore all properties that are defined in their own script, so to use any you have to provide them as arguments. Anyway, this is how they look now, and they work:

Fragment
;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment;NEXT FRAGMENT INDEX 1Scriptname TIF__01000D99 Extends TopicInfo Hidden;BEGIN FRAGMENT Fragment_0Function Fragment_0(ObjectReference akSpeakerRef)Actor akSpeaker = akSpeakerRef as Actor;BEGIN CODEnyczSBSScripts.Deposit(100, Gold001, nyczSBSAccount);END CODEEndFunction;END FRAGMENT;END FRAGMENT CODE - Do not edit anything between this and the begin commentMiscObject Property Gold001  Auto GlobalVariable Property nyczSBSAccount  Auto 

Script
Scriptname nyczSBSScriptsFunction Deposit(int amount, MiscObject gold, GlobalVariable account) global  Game.GetPlayer().RemoveItem(gold, amount)  account.Mod(amount)endFunction
User avatar
Marcin Tomkow
 
Posts: 3399
Joined: Sun Aug 05, 2007 12:31 pm

Post » Mon Jun 18, 2012 5:24 am

Thanks for posting an update with the cause and solution (and updating the wiki, if that was you!). Topics like this are often just abandoned after the author has the solution.
User avatar
Oscar Vazquez
 
Posts: 3418
Joined: Sun Sep 30, 2007 12:08 pm

Post » Mon Jun 18, 2012 4:53 pm

Yeah, that was me. Hopefully it'll help people with similar problems. :smile:
User avatar
Tom Flanagan
 
Posts: 3522
Joined: Sat Jul 21, 2007 1:51 am


Return to V - Skyrim