Jump to content

Get reference to an object


Recommended Posts

I'm used to setting a var to an object and using it's properties and methods but for the life of me I can't figure this out in papyrus. I have a trigger (DefaultEmptyTrigger) that I want to use setstage on a quest when the player enters the trigger. I have created a new script on the trigger and added the following code:

 

Scriptname RW9test1 extends ObjectReference Const
Quest Property RW9enableCPSwb Const Auto
Event OnTriggerEnter(ObjectReference akTriggerRef)
if akTriggerRef == Game.GetPlayer()
Debug.MessageBox(akTriggerRef + " just entered us!")
RW9enableCPSwb.SetStage(10)
endif
EndEvent
The debug message does display in game so I know the trigger is running the code. So how do I set the var or property RW9enableCPSwb to a quest object?
Thanks :)
Edited by RoadWarrior9
Link to comment
Share on other sites

The static variable reference properties button on scripts had me baffled for some time (e.g. took me forever to figure out how to actually make PlayerRef work) and to tun that painful learning into help:

 

if you manually typed in Quest Property RW9enableCPSwb Const Auto then you need to remove it and ... Select your script, press [properties] button, dropdown arrow next to [add property] button, Create Using Form, In FormEditorID box the Quest data ID of your quest (RW9enableCPSwb ?), the quest property will be injected into your script with an invisible link to its actual form reference id.

Link to comment
Share on other sites

If you already created the script and attached to the object, you could just open the properties and assign the quest to the property. There's no need to delete it from the script (which would cause a compile error due to the setstage command remaining) and add it back via the properties window.

 

Also you could use a vanilla script which has the exact same function "DN009_SetStageOnEnterScript". Then you just set the quest and stage properties accordingly. You won't get the message box, though after you've set it up you wouldn't want it anyway.

 

There's no particular reason you have to use a built in vanilla script though. If you wish to use your own you may. I personally like to use vanilla scripts when applicable for 2 reasons: 1. so I don't have to write the code myself, 2. save mod file size. Though for small scripts like this one in particular it's of negligible consequence.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...