Thread Tools Display Modes
02-08-17, 06:48 AM   #1
Benio
A Murloc Raider
Join Date: Jul 2016
Posts: 8
Update SecureStateDriver

How can I update SecureStateDriver?


I had registered SecureStateDriver:
Lua Code:
  1. RegisterStateDriver(frame, stateid, conditional);
  2. frame:SetAttribute("_onstate-" ..stateid, [=[
  3.     -- code
  4. ]=];
and I want to update conditional and code.

I've tried:
Lua Code:
  1. UnregisterStateDriver(frame, stateid);
  2. RegisterStateDriver(frame, stateid, NEW_conditional);
  3. frame:SetAttribute("_onstate-" ..stateid, [=[
  4.     -- NEW code
  5. ]=];

However running RegisterStateDriver after UnregisterStateDriver seems setting all conditional values to true until they change their state.
Is it bug, intended, or I am doing something wrong?
  Reply With Quote
02-09-17, 02:06 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Drivers for the same attribute on the same frame should overwrite each other without needing to unregister. What you might be facing is when your new conditional returns the same string that the state is already set to, the OnState function won't run.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-09-17, 02:13 AM   #3
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
When you doing the RegisterStateDriver, it's not in combat, you can use SecureCmdOptionParse(newcondition) to get the result and run you snippet by yourselves.
  Reply With Quote
02-10-17, 07:30 AM   #4
Benio
A Murloc Raider
Join Date: Jul 2016
Posts: 8
Thank you very much. So it turns out that:
  • RegisterStateDriver registers SecureStateDriver, but if it's called again with same stateid, it updates its conditional instead.
    That's misleading name that led me to misunderstanding how it works, thanks again for clarifying.

  • UnregisterStateDriver is redundant since RegisterStateDriver can actually update its conditional.
    This allows to remove unregistering part completelly since it's never needed.

  • OnState won't run until conditional changes if it's set already.
    This requires to set "state-" ..stateid out of combat, using SecureCmdOptionParse.

Finally, the following, corrected code works like a charm for both registering and updating SecureStateDriver:
Lua Code:
  1. frame:SetAttribute("_onstate-" ..stateid, [=[
  2.     -- code
  3. ]=];
  4. RegisterStateDriver(frame, stateid, conditional);
  5. frame:SetAttribute("state-" ..stateid, SecureCmdOptionParse(conditional));

Last edited by Benio : 02-10-17 at 07:34 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Update SecureStateDriver

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off