Acessing and Changing the Properties Of A Quest (From Within

Post » Mon Jun 18, 2012 8:01 am

I'm trying to access and change the properties of a quest script I created, from within a spell script, and I'm having trouble doing so.

I have the quest created, and all properties are set. Let's say my quest is called MyQuest and the Script is called MyQuestScript.

I've created a spell, and I wish to access a variable that I declared (and managed) within MyQuestScript. The variable I'm trying to access is called MyVariable, type Int.

This is the Spell Effect script:
MyQuestScript Property TargetQuest AutoInt TargetVariableTargetVariable = TargetQuest.MyVariable

The error I'm receiving is:
no viable alternative at input '='

I could provide the real code if needed, but I figure this would simplify things, and the format is exactly the same.

Any ideas on what the issue is?

EDIT: Another question I had, though perhaps unrelated, is what exactly "conditional" does. Some quests and properties will have this stated at the end of the line, and I don't really understand it's purpose or function.
User avatar
Leanne Molloy
 
Posts: 3342
Joined: Sat Sep 02, 2006 1:09 am

Post » Mon Jun 18, 2012 12:14 am

MyQuestScript is not a valid type. I think the only way to do what you want is to use a global variable because there doesn't seems to be a way to access another objects scripts.
User avatar
Devils Cheek
 
Posts: 3561
Joined: Sun Aug 13, 2006 10:24 pm

Post » Mon Jun 18, 2012 1:38 am

MyQuestScript is not a valid type. I think the only way to do what you want is to use a global variable because there doesn't seems to be a way to access another objects scripts.

But it is, and this is further proven by the fact that I do not receive an error on the line that I declare it. (Or can you declare variables of gibberish without it checking the type?)

This wiki page has details regarding accessing and controlling properties of another script, but the only real detail it provides pertains to Quest scripts controlling other Quest scripts.
http://www.creationkit.com/Variables_and_Properties

However, it does state here:
From a non-owned fragment / other quest script

Need to write this... basic gist: You need to define a property in your script (and set it through the editor interface to be the other quest whose properties you want access to), then you can access that property's properties. In other words, your script has a property of the other quest; then you access that property's properties.
This is implying that it is indeed possible, and as far as I am aware, I am formulating my code as it instructs, yet I still receive an error.
User avatar
suniti
 
Posts: 3176
Joined: Mon Sep 25, 2006 4:22 pm

Post » Mon Jun 18, 2012 11:32 am

The wiki's original example was formated like this:

;I have a quest script with this in it:scriptName MQ01Script extends Questint property deadCount auto;I have a result script (OWNED by MQ01) with this in it:MQ01Script myQuest						;declares a variable "myQuest" which is a TYPE of MQ01ScriptmyQuest = GetOwningQuest() as MQ01Script  ;sets the myQuest variable to it's owning quest as the type MQ01Scriptfloat myDeadCount						 ;declaring the variable "myDeadCount"myDeadCount = myQuest.deadCount		   ;setting local variable to be the quest's property value;you can also set the quest property thusly:myQuest.deadCount = 10

The main piece missing from my code, is the "myQuest = GetOwningQuest() as MQ01Script" line. This is because I cannot access the GetOwningQuest() function. That function seems to be returning the quest name+formID and assigning it to the variable as the "MQ01Script" type. However, that information is only obtainable if it is run within the quest. It's simply tracing upwards to the quest ID. I cannot do this if I am outside the quest.

This is basically what I need to figure out how to do in my script. I need to somehow get the owning quest ID, but it does not seem to be possible unless it is run from a topic or alias directly from within the quest. Does anyone have any ideas?
User avatar
Marcia Renton
 
Posts: 3563
Joined: Fri Jan 26, 2007 5:15 am

Post » Mon Jun 18, 2012 6:11 am

Did you set the variable's property in the property menu?
User avatar
Leonie Connor
 
Posts: 3434
Joined: Mon Mar 12, 2007 4:18 pm

Post » Mon Jun 18, 2012 5:02 am

I think I'm on to something.

I have a Quest which has the script:
Scriptname MyQuestScript extends Quest Conditionalint property myVar = 5 auto conditionalint function getmyvar()  return myVarendFunction

Then an Actor with the script:
Scriptname myvariabletest extends ActorMyQuestScript Property myQuest  Auto  int myothervariable =  0Event OnInit()	 RegisterForSingleUpdate(1)endEventEvent OnUpdate()	 myothervariable = (myQuest As myQuestScript).getmyvar() ;//This doesn't work if it's not contained in a function for some reasonendEvent

This all compiles, I haven't actually run it yet but it's certainly interesting.

Edit: changed ReferenceAlias to actor
User avatar
Krystal Wilson
 
Posts: 3450
Joined: Wed Jan 17, 2007 9:40 am

Post » Mon Jun 18, 2012 7:04 am

Did you set the variable's property in the property menu?
Yes, however in my experience using properties so far, I have never been forced to hook up the property before the code will run. If the property is "coded correctly" it will never cause compiling errors, it just won't work unless you hook up the properties in the property menu.
User avatar
Noraima Vega
 
Posts: 3467
Joined: Wed Jun 06, 2007 7:28 am

Post » Sun Jun 17, 2012 10:22 pm

I think I'm on to something.

I have a Quest which has the script:
Scriptname MyQuestScript extends Quest Conditionalint property myVar = 5 auto conditionalint function getmyvar()  return myVarendFunction

Then an Actor with the script:
Scriptname myvariabletest extends ReferenceAliasMyQuestScript Property myQuest  Auto  int myothervariable =  0Event OnInit()	 RegisterForSingleUpdate(1)endEventEvent OnUpdate()	 myothervariable = (myQuest As myQuestScript).getmyvar() ;//This doesn't work if it's not contained in a function for some reasonendEvent

This all compiles, I haven't actually run it yet but it's certainly interesting.

Is that script your running hooked up to an alias within the quest that you are accessing?
User avatar
Isabella X
 
Posts: 3373
Joined: Sat Dec 02, 2006 3:44 am

Post » Mon Jun 18, 2012 2:20 pm

Because "myQuest" is already declared as type "myQuestScript", you should need to bother casting it to that type.

What error do you get if you try to compile this line?
myothervariable = myQuest.myVar

Cipscis
User avatar
x a million...
 
Posts: 3464
Joined: Tue Jun 13, 2006 2:59 pm

Post » Mon Jun 18, 2012 12:22 pm

Because "myQuest" is already declared as type "myQuestScript", you should need to bother casting it to that type.

What error do you get if you try to compile this line?
myothervariable = myQuest.myVar

Cipscis
I think I'm on to something.

I have a Quest which has the script:
Scriptname MyQuestScript extends Quest Conditionalint property myVar = 5 auto conditionalint function getmyvar()  return myVarendFunction

Then an Actor with the script:
Scriptname myvariabletest extends ReferenceAliasMyQuestScript Property myQuest  Auto  int myothervariable =  0Event OnInit()	 RegisterForSingleUpdate(1)endEventEvent OnUpdate()	 myothervariable = (myQuest As myQuestScript).getmyvar() ;//This doesn't work if it's not contained in a function for some reasonendEvent

This all compiles, I haven't actually run it yet but it's certainly interesting.

I have tried it like this, and the script seems to be compiling! I'll post my code if I test it and it works correctly.
User avatar
Darlene Delk
 
Posts: 3413
Joined: Mon Aug 27, 2007 3:48 am

Post » Mon Jun 18, 2012 1:21 pm

I have myvariabletest attached directly to an Actor actually. Kinda surprised it didn't throw a fit.

Because "myQuest" is already declared as type "myQuestScript", you should need to bother casting it to that type.

What error do you get if you try to compile this line?
myothervariable = myQuest.myVar

Cipscis

Starting 1 compile threads for 1 files...
Compiling "myvariabletest"...
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\myvariabletest.psc(11,17): no viable alternative at input '='
No output generated for myvariabletest, compilation failed.

really weird...
User avatar
Catherine Harte
 
Posts: 3379
Joined: Sat Aug 26, 2006 12:58 pm

Post » Sun Jun 17, 2012 11:48 pm

That was unexpected...
The wiki is still relatively undocumented about this - looks like it was on the "to do" list but was overlooked: http://www.creationkit.com/Variables_and_Properties#From_a_non-owned_fragment_.2F_other_quest_script

Can you find any examples in the source that came with the Creation Kit of accessing properties remotely? Not an easy thing to search for, unfortunately...

Cipscis
User avatar
Ice Fire
 
Posts: 3394
Joined: Fri Nov 16, 2007 3:27 am

Post » Mon Jun 18, 2012 4:11 am

I have myvariabletest attached directly to an Actor actually. Kinda surprised it didn't throw a fit.



Starting 1 compile threads for 1 files...
Compiling "myvariabletest"...
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\myvariabletest.psc(11,17): no viable alternative at input '='
No output generated for myvariabletest, compilation failed.

really weird...

I do not think that there is an issue with it only working within a function. I can't say I understand why myself but it does compile this way.

My script seems to work (I'm still tweaking the script for what I actually plan to do with it so I can't fully test it in game yet) using your previous method of typecasting it.
User avatar
CHangohh BOyy
 
Posts: 3462
Joined: Mon Aug 20, 2007 12:12 pm

Post » Mon Jun 18, 2012 11:56 am

That was unexpected...
The wiki is still relatively undocumented about this - looks like it was on the "to do" list but was overlooked: http://www.creationkit.com/Variables_and_Properties#From_a_non-owned_fragment_.2F_other_quest_script

Can you find any examples in the source that came with the Creation Kit of accessing properties remotely? Not an easy thing to search for, unfortunately...

Cipscis

Actually I was helping someone else on the vampire quest script which also happens to access remote properties or at least remote functions anyway. However they're all void types that don't return a value also all their calls are contained within functions so it doesn't give us any more information then we already have.

Quest: PlayerVampireQuest
Script: PlayerVampireQuestScript
Remote Script: imageSpaceModifier

Example:
Function VampireFeed()    ;Effects for hiding the change    ;VampireChangeFX.play(game.getPlayer())    VampireTransformDecreaseISMD.applyCrossFade(2.0)    utility.wait(2.0)    imageSpaceModifier.removeCrossFade()    ;VampireChangeFX.stop(game.getPlayer())        Game.IncrementStat( "Necks Bitten" )    VampireFeedMessage.Show()    VampireFeedReady.SetValue(0)    ;Game.ForceThirdPerson()    ;Game.GetPlayer().PlayIdle(VampireFeedingBedRight)    ;Player has fed, regress to Stage 1 Vampirisim    ;Remove Stage 2, 3, and 4 buffs and spells    LastFeedTime =  GameDaysPassed.Value    VampireStatus = 1    VampireProgression(Game.GetPlayer(), 1)    ;Player is no longer hated    Game.GetPlayer().RemoveFromFaction(VampirePCFaction)    Game.GetPlayer().SetAttackActorOnSight(False)    int cfIndex = 0    while (cfIndex < CrimeFactions.GetSize());         Debug.Trace("VAMPIRE: Removing enemy flag from " + CrimeFactions.GetAt(cfIndex))        (CrimeFactions.GetAt(cfIndex) as Faction).SetPlayerEnemy(false)        cfIndex += 1    endwhile    ;Start checking GameTime again if we weren't already    UnregisterforUpdateGameTime()    RegisterForUpdateGameTime(12)        EndFunction
User avatar
Miguel
 
Posts: 3364
Joined: Sat Jul 14, 2007 9:32 am

Post » Mon Jun 18, 2012 4:12 am

FYI it seems you can also extend the script as an actor instead of a ReferenceAlias. I'll update my post with the script with this change.
User avatar
TIhIsmc L Griot
 
Posts: 3405
Joined: Fri Aug 03, 2007 6:59 pm

Post » Mon Jun 18, 2012 11:38 am

I think I'm trying to do something along the same lines. I'm trying to make an npc that will remove the various bugged journal entries like "invistagate the Boethia Cultist" or "Collect Bounty from Skald". Fixing the original quests was easy enough but the entries are still in my journal. Now, I can be in game and use 'setObjectiveDisplayed WEDA02 10,0' with seems to work since it doesn't tell me that it didn't, but the entry is still in my journal.

The BQ03 quest was the first quest I fixed and I had noticed that it still wouldn't remove the entry unless I went through the dialog in game, neither setObjectiveComplete nor setObjectiveDisplayed would get rid of it.. only going through the conversation with Skald. Thats why I figured what I might need would be an npc who would run the commands to remove the offending journal entries in dialog. I made an npc 'Fixer of Journal Entries', placed them in Whiterun against the wall, attached a quest with no stages (JFQ01, thats Journal Fixer Quest 01) to them and started writing some dialog branches that would run little scripts with the setObjectiveComplete, setObjectDisplayed commands and there is where I hit a problem and I'm thinking its the same as the op's.

For instance, this is the rather simple script that 'should' run the commands to remove the 'Invistigate the Boethiah Cultist' entry..
Scriptname WEDA02Fixer extends Quest
Quest Property thisQuest Auto
thisQuest.SetObjectiveCompleted(10)
thisQuest.SetObjectiveDisplayed(10,0)

The 'thisQuest' property has been set in the property settings to the quest 'WEDA02' and this looks like it should work but when its compiled I get... "yada,yada,yada... (3,9): no viable alternative at input '.' yada,yada,yada" I can't use the 'GetOwningQuest()' because it would simply reference the parent quest for the dialog, that being JFQ01, which has no stages or journal entries (objectives) anyway. I'm gonna keep trying for another 30 minutes but its pretty late already. :wallbash:
User avatar
K J S
 
Posts: 3326
Joined: Thu Apr 05, 2007 11:50 am

Post » Mon Jun 18, 2012 11:36 am

I think I'm trying to do something along the same lines. I'm trying to make an npc that will remove the various bugged journal entries like "invistagate the Boethia Cultist" or "Collect Bounty from Skald". Fixing the original quests was easy enough but the entries are still in my journal. Now, I can be in game and use 'setObjectiveDisplayed WEDA02 10,0' with seems to work since it doesn't tell me that it didn't, but the entry is still in my journal.

The BQ03 quest was the first quest I fixed and I had noticed that it still wouldn't remove the entry unless I went through the dialog in game, neither setObjectiveComplete nor setObjectiveDisplayed would get rid of it.. only going through the conversation with Skald. Thats why I figured what I might need would be an npc who would run the commands to remove the offending journal entries in dialog. I made an npc 'Fixer of Journal Entries', placed them in Whiterun against the wall, attached a quest with no stages (JFQ01, thats Journal Fixer Quest 01) to them and started writing some dialog branches that would run little scripts with the setObjectiveComplete, setObjectDisplayed commands and there is where I hit a problem and I'm thinking its the same as the op's.

For instance, this is the rather simple script that 'should' run the commands to remove the 'Invistigate the Boethiah Cultist' entry..
Scriptname WEDA02Fixer extends Quest
Quest Property thisQuest Auto
thisQuest.SetObjectiveCompleted(10)
thisQuest.SetObjectiveDisplayed(10,0)

The 'thisQuest' property has been set in the property settings to the quest 'WEDA02' and this looks like it should work but when its compiled I get... "yada,yada,yada... (3,9): no viable alternative at input '.' yada,yada,yada" I can't use the 'GetOwningQuest()' because it would simply reference the parent quest for the dialog, that being JFQ01, which has no stages or journal entries (objectives) anyway. I'm gonna keep trying for another 30 minutes but its pretty late already. :wallbash:

Try typecasting it as we've posted above. (thisQuest as thisQuestScript).SetObjectiveCompleted(10) ect. thisQuestScript needs to be the name of the script you used in the quest you are referencing.
User avatar
Matt Bee
 
Posts: 3441
Joined: Tue Jul 10, 2007 5:32 am

Post » Mon Jun 18, 2012 1:13 am

I think I'm trying to do something along the same lines. I'm trying to make an npc that will remove the various bugged journal entries like "invistagate the Boethia Cultist" or "Collect Bounty from Skald". Fixing the original quests was easy enough but the entries are still in my journal. Now, I can be in game and use 'setObjectiveDisplayed WEDA02 10,0' with seems to work since it doesn't tell me that it didn't, but the entry is still in my journal.

The BQ03 quest was the first quest I fixed and I had noticed that it still wouldn't remove the entry unless I went through the dialog in game, neither setObjectiveComplete nor setObjectiveDisplayed would get rid of it.. only going through the conversation with Skald. Thats why I figured what I might need would be an npc who would run the commands to remove the offending journal entries in dialog. I made an npc 'Fixer of Journal Entries', placed them in Whiterun against the wall, attached a quest with no stages (JFQ01, thats Journal Fixer Quest 01) to them and started writing some dialog branches that would run little scripts with the setObjectiveComplete, setObjectDisplayed commands and there is where I hit a problem and I'm thinking its the same as the op's.

For instance, this is the rather simple script that 'should' run the commands to remove the 'Invistigate the Boethiah Cultist' entry..
Scriptname WEDA02Fixer extends Quest
Quest Property thisQuest Auto
thisQuest.SetObjectiveCompleted(10)
thisQuest.SetObjectiveDisplayed(10,0)

The 'thisQuest' property has been set in the property settings to the quest 'WEDA02' and this looks like it should work but when its compiled I get... "yada,yada,yada... (3,9): no viable alternative at input '.' yada,yada,yada" I can't use the 'GetOwningQuest()' because it would simply reference the parent quest for the dialog, that being JFQ01, which has no stages or journal entries (objectives) anyway. I'm gonna keep trying for another 30 minutes but its pretty late already. :wallbash:

I believe it's likely the same thing we were running into above. Try this:
  • Add a stage to your fixer quest with index 0
  • Add an empty log entry conditioned on the appropreiate quest stage for the quest you're trying to fix
  • Add the following code, note it will throw errors but we'll fix them in a moment
    		test0.SetObjectiveCompleted(10)		test0.SetObjectiveDisplayed(10,0)		
  • Click OK on the quest then reopen it
  • Click the script Tab
  • Click Properties and setup the link to the quest you're trying to fix
  • Go back to the quest stage tab and compile the code, it shouldn't give you any errors now
User avatar
Lyd
 
Posts: 3335
Joined: Sat Aug 26, 2006 2:56 pm

Post » Mon Jun 18, 2012 1:24 am

This is driving me crazy--I've been trying to debug for the past 3 hours. Maybe someone else can spot my error. Getting things to compile has been easy, but getting a real value returned has proven fruitless.

I have a script attached to a quest, the relevant snippet of which is:


Scriptname ESFAelaCoreDialogueScript extends Quest  Conditionalint Function GetiAggroMode()	return 1EndFunction

Then, to a reference alias in another quest, I attached this script:

Scriptname ESFAelaActorAliasScript extends ReferenceAlias  ESFAelaCoreDialogueScript Property CoreQuest Autoint iOldAggroMode = -1Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	iOldAggroMode = (CoreQuest as ESFAelaCoreDialogueScript).GetiAggroMode()	Debug.MessageBox("Aela Hit Event -- Old iAggroMode is " + iOldAggroMode)EndEvent

When Aela gets hit in combat and the OnHit event triggers, what appears in the MessageBox is "Old iAggroMode is 0". It should be 1.

I can tell from debugging that the GetiAggroMode() function simply isn't being called--a debug messagebox added to the top of that function never appears. Yet it all compiles fine. And if I change the function name in the OnHit handler to, say, GetiAggroModeX(), the compiler throws an error that a function of that name doesn't exist--so it is looking in the right place.


Edit: Success!

The code above this post in this thread may have worked for other people, but what ended up working for me was much simpler. I should have just read the wiki text more carefully, as it basically lays out the solution. Basically, in the script that needs to access a property from a quest script, you first define a Quest property, assign it to the quest in the Properties window, and then accessing that quest's properties and functions is simple:

Scriptname ESFAelaActorAliasScript extends ReferenceAlias  Quest Property MyQuest  Auto  int iOldAggroMode = -1Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	iOldAggroMode = (MyQuest as ESFAelaCoreDialogueScript).iAggroMode

Is how I can access the iAggroMode property--there's no need to create separate functions for set and get, as long as you used "auto" on the property in the core quest.
User avatar
X(S.a.R.a.H)X
 
Posts: 3413
Joined: Tue Feb 20, 2007 2:38 pm

Post » Mon Jun 18, 2012 1:15 am

you need a script to extend magic effect, put that on a magic effect and put that effect on a spell.

Then add a property to that script of TYPE referenceAlias and point it to the quest and your referenceAlias (added under "Quest Alias")

Then in that magic effect script you have a OnMagicEffectStart event (or whatever its called) and then

myProperty.ForceRefTo(Self.GetRef())

-----------

Also something to note is that the script which you attached to your alias under Quest Alias must extend ReferenceAlias or it won't do anything

Then in there you can have the OnHit event.

I create a dummy NPC (race imperial) and place him in a dummy NPC and use that as the intial "unique actor" for the reference alias
User avatar
Ash
 
Posts: 3392
Joined: Tue Jun 13, 2006 8:59 am


Return to V - Skyrim