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:
Thanks for your help :c Edit : where I am now ... ; ; Lua Code:
tried also something like Lua Code:
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:
really don't get it :D |
Gonna test this, but server are down >.<
Lua Code:
|
The simplest way to toggle a variable between zero and one is as follows:
Code:
var = 1 - var So your function could look as follows: Code:
function toghelm() |
Quote:
Thanks a lot Stromknight ! |
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:
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. |
Quote:
|
All times are GMT -6. The time now is 12:02 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI