GetOwningQuest error

Post » Mon Jun 18, 2012 7:01 am

I'm trying to follow this tutorial on how to manipulate variables from multiple scripts - http://www.creationkit.com/Safely_increment_variable_from_multiple_scripts

I've created a quest that runs at startup and attached 2 scripts to it. One script contains a load of 'auto' properties that I want to change, the other script tries to change the properties.

The 2nd script consists of...

Event OnInit()aaaMREVariablesScript mreVarmreVar = GetOwningQuest() as aaaMREVariablesScriptendEvent

But compilation of the 2nd script fails at the 'mreVar = GetOwningQuest() as aaaMREVariablesScript' line with 'GetOwningQuest is not a function or does not exist'.

Any ideas as to what I'm doing wrong?
User avatar
Victoria Vasileva
 
Posts: 3340
Joined: Sat Jul 29, 2006 5:42 pm

Post » Sun Jun 17, 2012 10:53 pm

If your script extends Quest and is attached to a quest, you don't need GetOwningQuest. What you need is to get the object itself, but scoped as the other script so you can access the other script's properties.

Something like:

mreVar = ((self as Quest) as aaaMREVariablesScript)
User avatar
Ryan Lutz
 
Posts: 3465
Joined: Sun Sep 09, 2007 12:39 pm

Post » Sun Jun 17, 2012 6:50 pm

Many thanks for that...it compiles now.

Originally I had tried to do this with the 2nd script attached to a different quest (which should require the GetOwningQuest bit, if I understand you)...but it still failed compilation at the same line. Any ideas on that?
User avatar
Nims
 
Posts: 3352
Joined: Thu Jun 07, 2007 3:29 pm

Post » Mon Jun 18, 2012 2:23 am

After re-reading your post I think I get it...any script that extends a quest doesn't need GetOwningQuest() to get access to another quest's properties (is that right?).

The scripts compile now, but the properties won't change...I've turned on logging and a line has been added to it saying...'Cannot call bAffectFatigue() on a None object, aborting function call'. I'm guessing that the 'mreVar = ((self as Quest) as aaaMREVariablesScript)' line is not returning anything.

Is there anyway I can check this?
User avatar
Georgine Lee
 
Posts: 3353
Joined: Wed Oct 04, 2006 11:50 am

Post » Mon Jun 18, 2012 12:31 am

Both scripts would need to extend Quest.

As far as GetOwningQuest() - that's a special function that only applies to scripts that are on objects owned by a particular quest - quest stage fragments; topic info fragments; scene fragments; ReferenceAlias scripts. The only way that function works is that the script you're calling it on knows about it's "owning quest". A script that is directly on a quest IS that quest, it isn't owned by it.
User avatar
Pawel Platek
 
Posts: 3489
Joined: Sat May 26, 2007 2:08 pm

Post » Mon Jun 18, 2012 12:08 am

Ahhhhhh...you've got to love the Sleep Fairies and insight they bestow...

I think I've finally got it...so thought I'd go through it for anyone else having a similar problem...

You have 2 quests...Quest1 & Quest2. Each quest has a script attached to it. Quest1's script contains a property you want to be able to change from Quest2's script.

Contents of script 1:-
Scriptname Quest1Script extends Quest Int Property SomeProperty = 0 Auto 

Contents of script 2:-
Scriptname Quest2Script extends Quest Quest Property Quest1Ref  Auto Event OnInit()  Quest1Script Quest1ScriptRef  Quest1ScriptRef = (Quest1Ref as Quest) as Quest1Script  Quest1ScriptRef.SomeProperty = 1endEvent

The Quest property in script 2 should be set to Quest1 in the Quest2 scripts page. The first line of the OnInit then declares a variable of type Quest1Script (the script you want to access the properties of). The second line sets that variable by first getting the quest (Quest1Ref as Quest) and then getting the script attached to it (as Quest1Script). The third line then sets the property in the other quest. Job done.
User avatar
herrade
 
Posts: 3469
Joined: Thu Apr 05, 2007 1:09 pm


Return to V - Skyrim