Once again, can't get Papyrus to do ANYTHING

Post » Wed Aug 21, 2013 5:56 pm

I am this close to just pretending skyrim doesn't exist and modding oblivion again.

Here's what I want:

I have a quest.

I have a quest script.

When the player is on a certain stage of the quest, in a certain cell, I want things to happen.

Event OnInit()    RegisterForUpdate(5)EndEventEvent OnUpdate()if (Game.GetPlayer().GetParentCell() == aaaCell001)if (aaaMainQuest01.getstage() == 6)Debug.MessageBox("Do Cool Stuff")endifendifEndEventCell Property aaaCell001  Auto  Quest Property aaaMainQuest01  Auto  

Absolutely not a damn thing happens. I removed my if statements in case something was wrong with them, still nothing happens. Nothing at all.

Worst scripting language I've ever seen. I'm guessing I need to define a property for my property for a property? And then define a property for that?

User avatar
Kevin Jay
 
Posts: 3431
Joined: Sun Apr 29, 2007 4:29 am

Post » Wed Aug 21, 2013 11:56 am

Try putting in some extra debug messages/notifications...

  1. Immediately in the OnUpdate - make sure you're actually getting update events
  2. In your first If statement - make sure it's detecting the player is in that cell
  3. Print the stage actually returned

When coding anything in any language, the way to spot errors is patiently and methodically trace through your code and use liberal debugging code to find where things aren't happening as you expect and why.

For instance, if you're using a savegame which had an earlier version of your mod with different properties on that quest script, is it still using the old properties instead of the new one? Is the quest for somereason not ever getting to that stage, or passing through it within the 5 second gap between updates?

[edit]

You might also want to think about using an OnLocationChange event on a Player alias. That RegisterForUpdate could cause savegame corruption for anyone who uninstalls your mod, and is a heavier burden on the scripting system. An OnLocationChange will only fire off each time the player moves to a new location, and most (though I admit, not all) internal cells have their own location.

User avatar
Maria Leon
 
Posts: 3413
Joined: Tue Aug 14, 2007 12:39 am

Post » Wed Aug 21, 2013 1:06 pm

Thanks for your suggestions.

The script works, the problem was that I tested it midway through the quest and "oninit" runs at the quest start. So oninit never ran.

Thanks again.

User avatar
Richard Thompson
 
Posts: 3302
Joined: Mon Jun 04, 2007 3:49 am

Post » Wed Aug 21, 2013 6:59 am

The problem could be a number of things.

If this quest has already started before you load the save you're testing it on, it won't receive any OnInit events. This event is only received once the first time the game loads with the esp that contains the quest. Try it on a clean save that's never seen the quest.

Edit: Also, right now the script only registers for a single update, which means it will only check if the player is in the cell once (the very first time the game is loaded on a clean save). You could simply register for another update in the onUpdate() event (as andyw suggested), but that is not a very safe way to script, and may result in a lot of unneeded script processing/lag. Apologies, misread the function -- it will keep updating :-) However, still not the safest method to script this quest event--registering for updates is discouraged as it creates dirty saves.

The best way to set this up would probably be to put the script in a reference alias, and wait until the quest hits stage six, then have a script fragment on stage six that inserts the player into that reference alias. The reference alias itself can then have a script that will track the cell the player is in until reaching the desired target cell. You wouldn't even need a script attached to the quest itself in this scenario.

To try this method:

Make a new reference alias on your quest, check the "optional" flag without changing anything else and save the reference alias. Then add this script to the reference alias:

Scriptname aaaCellQuestScript extends ReferenceAliasCell property aaaCell001 autoQuest property aaaMainQuest01 autoEvent OnCellAttach()if Game.GetPlayer().GetParentCell() == aaaCell001if (aaaMainQuest01.getstage() == 6)Debug.MessageBox("Do Cool Stuff")GoToState("QuestFinished")endifendifEndEventState QuestFinishedEvent OnCellAttach()   ;replace with an empty event to stop tracking the playerEndEventEndState

And add this script fragment to stage six of your quest:

ReferenceAlias property myRefAlias auto    ;fill with the reference alias that has the above script attached to it.myRefAlias.forceRefTo(Game.GetPlayer() as ObjectReference)

You will need to fill the properties in the CK, of course.

User avatar
[Bounty][Ben]
 
Posts: 3352
Joined: Mon Jul 30, 2007 2:11 pm

Post » Wed Aug 21, 2013 7:23 pm

You know that saying about workmen blaming their tools? ;)

Once you learn to embrace Properties instead of fighting them, you'll realise the true power you wield at your fingertips

But yeh, rather then checking every five seconds, do what egocarib suggested and use the OnCellAttach() event

EDIT: or andyw's suggestion of OnLocationChange(). So many ways to skin a cat...

EDIT2: also, for future reference, its been deemed that the best practice for using the OnUpdate() event is to use "RegisterForSingleUpdate(5)", then inside your OnUpdate() event add the same line at the end to make it loop. Then you can just Stop() your quest and it will automatically unregister or use UnregisterForUpdate() to break the loop, otherwise you risk the dreaded Save Bloat™

- Hypno
User avatar
MatthewJontully
 
Posts: 3517
Joined: Thu Mar 08, 2007 9:33 am

Post » Wed Aug 21, 2013 4:27 am

Indeed. It's just so disheartening, I felt like I could do anything with Oblivion. Here, I feel completely lost. I guess I'll have to adjust, though.

User avatar
Victoria Bartel
 
Posts: 3325
Joined: Tue Apr 10, 2007 10:20 am

Post » Wed Aug 21, 2013 4:29 am

Thats what these forums are for :)

- Hypno

User avatar
Cathrine Jack
 
Posts: 3329
Joined: Sat Dec 02, 2006 1:29 am


Return to V - Skyrim