I've learned a lot thru the classroom logs, mostly lua and tables stuff. Thanks a lot Rowne! :D
I'm gonna go "Aceify" my addons now. If there are a couple of other tutorials, that will probably help me more.
I even learned the ~= symbol, I was always using "not x == y" since I didn't knew better...:oops:
:idea:
Just wanted to leave something to help others too (even if it's late in the thread). Perhaps nobody will see this, or it was solved before... Anyway...
In section [M], Rowne mentionned a trick about having "t = t<2 and t or 2" or stuff around it, but in the version of the text file I read, it's still in the normal form : "if t < 2 then t = 2 end"
I wanted to check if it's possible to use "ternaries" to solve this.
Here's an explanation from the lua doc how "and" & "or" works
X and Y -> if X is true (or any value away from 0/nil), return Y else return X (return false)
X or Y -> if X is true, return X else return Y
Also, the "and" is going before the "or"
now, for the math problem:
if t < 2 then t = 2 end
Can it be shortened to the form: t = t<2 and t or 2 (or something near this)?
Step 1:
t<2 and t
if t is bigger, it will give t
if t is lower, it will give true
Step 2:
t (true) or 2 -> will give t
true or 2 -> will give true... not what we want
The solution is: t = t>=2 and t or 2
Step 1:
t >= 2 and t
it will return t if it's bigger
it will return false if it's lower
Step 2:
t (true) or 2 -> will return t
false or 2 will return 2
Bonus:
if t is nil: t>=2 and t will return nil
nil or 2 will return 2
To use "and" & "or" on the same line, we need to be careful to check that the return value isn't always true, we must make it false to continue the chain.
0
Thanks a lot Rowne! :D
I'm gonna go "Aceify" my addons now. If there are a couple of other tutorials, that will probably help me more.
I even learned the ~= symbol, I was always using "not x == y" since I didn't knew better...:oops:
:idea:
Just wanted to leave something to help others too (even if it's late in the thread). Perhaps nobody will see this, or it was solved before... Anyway...
In section [M], Rowne mentionned a trick about having "t = t<2 and t or 2" or stuff around it, but in the version of the text file I read, it's still in the normal form : "if t < 2 then t = 2 end"
I wanted to check if it's possible to use "ternaries" to solve this.
Here's an explanation from the lua doc how "and" & "or" works
X and Y -> if X is true (or any value away from 0/nil), return Y else return X (return false)
X or Y -> if X is true, return X else return Y
Also, the "and" is going before the "or"
now, for the math problem:
if t < 2 then t = 2 end
Can it be shortened to the form: t = t<2 and t or 2 (or something near this)?
Step 1:
t<2 and t
if t is bigger, it will give t
if t is lower, it will give true
Step 2:
t (true) or 2 -> will give t
true or 2 -> will give true... not what we want
The solution is: t = t>=2 and t or 2
Step 1:
t >= 2 and t
it will return t if it's bigger
it will return false if it's lower
Step 2:
t (true) or 2 -> will return t
false or 2 will return 2
Bonus:
if t is nil: t>=2 and t will return nil
nil or 2 will return 2
To use "and" & "or" on the same line, we need to be careful to check that the return value isn't always true, we must make it false to continue the chain.