Help Understanding RegisterForUpdate()

Post » Thu Jun 21, 2012 6:56 am

So I created the below script and attached it to a pair of gloves. The idea was to toggle a Perk on and off depending on whether the gloves are equipped.

The debug messages for equipping/unequipping fire off just fine. The Perk is added/removed as it should be.

My attempt to get periodic updates showing the gloves are still equipped was a failure. My best guess is that I can't use that function in a script that extends ObjectReference, but I don't know for sure. Here's the code.

Scriptname MyPerkToggle extends ObjectReferenceperk property MyPerk autoEvent OnEquipped(Actor akActor)	Debug.MessageBox("We were equipped by the player!")	Game.GetPlayer().AddPerk(MyPerk)	RegisterForUpdate(5)endEventEvent OnUnequipped(Actor akActor)	Debug.MessageBox("We were unequipped by the player!")	Game.GetPlayer().RemovePerk(MyPerk)	UnregisterForUpdate()endEventEvent OnUpdate()	 Debug.MessageBox("Still equipped!")endEvent

I'd appreciate any pointers as to my failure here... I'm sure it's pretty obvious, just can't figure where my logic went wrong.
User avatar
Vahpie
 
Posts: 3447
Joined: Sat Aug 26, 2006 5:07 pm

Post » Wed Jun 20, 2012 10:39 pm

This may or may not solve your issue - try using 5.0 instead of just 5.
User avatar
Lou
 
Posts: 3518
Joined: Wed Aug 23, 2006 6:56 pm

Post » Thu Jun 21, 2012 12:47 pm

Thanks for the response. Tried, but no luck. :(
User avatar
Ludivine Poussineau
 
Posts: 3353
Joined: Fri Mar 30, 2007 2:49 pm

Post » Thu Jun 21, 2012 4:59 am

I may be wrong on this too, but after looking at the explanation of RegisterForUpdate on the wiki, it strikes me that it may be ignored in an ObjectReference script.
I know that if you put it in a quest script with an IsEquipped condition, it would work fine.
User avatar
Reanan-Marie Olsen
 
Posts: 3386
Joined: Thu Mar 01, 2007 6:12 am

Post » Thu Jun 21, 2012 5:30 am

OK, so found the answer here... and it's not entirely my fault. I'm blaming this one on Beth. :wink:

Turns out, items that are in containers (which includes your inventory) have issues with passing the ObjectReference ID. In short, can't use RegisterForUpdate() on a script that's attached to an item in a container or inventory.

What I had to do was... create a Magical Effect that calls the script that then calls for the updates. Then, I made an enchant with that script and enchanted the gloves. When the gloves are worn, the Enchant registers for the updates and sends the warning message. The messages stop when I take off the gloves.
User avatar
CxvIII
 
Posts: 3329
Joined: Wed Sep 06, 2006 10:35 pm

Post » Thu Jun 21, 2012 4:31 am

That makes me very sad, I developed some wonderful Token scripts in Oblivion, looks like they will be mostly useless now...

OK, so found the answer here... and it's not entirely my fault. I'm blaming this one on Beth. :wink:

Turns out, items that are in containers (which includes your inventory) have issues with passing the ObjectReference ID. In short, can't use RegisterForUpdate() on a script that's attached to an item in a container or inventory.

User avatar
ImmaTakeYour
 
Posts: 3383
Joined: Mon Sep 03, 2007 12:45 pm


Return to V - Skyrim