Thread Tools Display Modes
04/14/14, 04:24 PM   #1
Etupa
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
Help with toggle value/function

Hi here, need your help I've messed up with else if or etc make 0 1 as a var... don't get it at all ;_;

I'm trying to make a toggle function with one keybinds, bindings.xml part is ok for me but have no more idea for lua... u_u

Basicaly, I want 0 became 1 or 1 became 0 ... ^^;

Lua Code:
  1. local function helm()  
  2.         local control = ZO_OptionsWindow.controlTable[3][8]
  3.         SetSetting(control.system, control.settingId, 0)   
  4.     end
  5. --or
  6.  
  7.     local function nohelm()
  8.         local control = ZO_OptionsWindow.controlTable[3][8]
  9.         SetSetting(control.system, control.settingId, 1)   
  10.     end

Thanks for your help :c




Edit :
where I am now ... ; ;


Lua Code:
  1. function toghelm()
  2. local control = ZO_OptionsWindow.controlTable[3][8]
  3. SetSetting(control.system, control.settingId, (var))
  4.     var = x
  5.         if x == 0 then return nohelm()
  6.         elseif x == 1 then return helm()
  7.     end
  8.  
  9. end
  10.            
  11.     local function helm()  
  12.         local control = ZO_OptionsWindow.controlTable[3][8]
  13.         SetSetting(control.system, control.settingId, 0)   
  14.     end
  15.     local function nohelm()
  16.         local control = ZO_OptionsWindow.controlTable[3][8]
  17.         SetSetting(control.system, control.settingId, 1)   
  18.     end

tried also something like

Lua Code:
  1. function toghelm()
  2. local control = ZO_OptionsWindow.controlTable[3][8]
  3. SetSetting(control.system, control.settingId, (var))
  4.    var = helmvar
  5.       if helmvar == 1 then var = 0
  6.       elseif helmvar == 0 then var = 1
  7.    end
  8. end

Well, those always return 0 (helm is on) ... but can't catch the way to make 0 to 1 et 1 to 0 at function execution ^^;


one more try...

Lua Code:
  1. function toghelm()
  2.     local control = ZO_OptionsWindow.controlTable[3][8]
  3.         local helmstate = GetSetting(control.system, control.settingId)
  4.         if helmstate == 1 then return helm()
  5.         elseif helmstate == 0 then return nohelm()  
  6.     end
  7. end
  8.  
  9.            
  10. local function helm()  
  11.     local control = ZO_OptionsWindow.controlTable[3][8]
  12.     SetSetting(control.system, control.settingId, 0)   
  13. end
  14.  
  15. local function nohelm()
  16.     local control = ZO_OptionsWindow.controlTable[3][8]
  17.     SetSetting(control.system, control.settingId, 1)   
  18. end

really don't get it

Last edited by Etupa : 04/15/14 at 03:58 AM.
  Reply With Quote
04/15/14, 07:43 AM   #2
Etupa
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
Gonna test this, but server are down >.<

Lua Code:
  1. function toghelm()                         
  2. local control = ZO_OptionsWindow.controlTable[3][8]
  3. local var = GetSetting(control.system, control.settingId)                                  
  4.         if var == 1
  5.             then var = 0
  6.         else
  7.             var = 1
  8.     end                                    
  9. SetSetting(control.system, control.settingId,(var))
  10. end
  Reply With Quote
04/15/14, 08:29 AM   #3
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
The simplest way to toggle a variable between zero and one is as follows:

Code:
var = 1 - var
You can do it using xor as well, but I don't believe that's fully implemented in the version of LUA that's embedded within ESO.

So your function could look as follows:

Code:
function toghelm()                          
    local control = ZO_OptionsWindow.controlTable[3][8]
    local var = GetSetting(control.system, control.settingId)                                   
    SetSetting(control.system, control.settingId,(1-var))
end
Hope that helps!

Last edited by Stormknight : 04/15/14 at 08:33 AM.
  Reply With Quote
04/15/14, 11:26 AM   #4
Etupa
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
Red face

Originally Posted by Stormknight View Post
...
I will try this too as soon as server is up ! seems right to me

Thanks a lot Stromknight !
  Reply With Quote
04/15/14, 01:00 PM   #5
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
At least one code would produce an exception:"function expected but got nil" if used the way it is pasted here. So, when you paste code, it is important to paste it correctly and not modify it in between. The order of declarations etc. are important in LUA, unlike Python or JavaScript.


Your first snippet:
Lua Code:
  1. function toghelm()
  2. local control = ZO_OptionsWindow.controlTable[3][8]
  3. SetSetting(control.system, control.settingId, (var))
  4.     var = x
  5.         if x == 0 then return nohelm()
  6.         elseif x == 1 then return helm()
  7.     end
  8.  
  9. end


There is no x. If there is no x, it is nil. If x is nil, then the comparisons are "nil == 0" which is false and "nil == 1" which is also false. Neither helm() nor norhelm() gets executed.
  Reply With Quote
04/15/14, 03:37 PM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Iyanga View Post
Your first snippet:
Lua Code:
  1. function toghelm()
  2. local control = ZO_OptionsWindow.controlTable[3][8]
  3. SetSetting(control.system, control.settingId, (var))
  4.     var = x
  5.         if x == 0 then return nohelm()
  6.         elseif x == 1 then return helm()
  7.     end
  8.  
  9. end


There is no x. If there is no x, it is nil. If x is nil, then the comparisons are "nil == 0" which is false and "nil == 1" which is also false. Neither helm() nor norhelm() gets executed.
I guess there should be x = var instead of var = x.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Help with toggle value/function


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