| View previous topic :: View next topic |
| Author |
Message |
stonepimp
Joined: 23 Sep 2005 Posts: 5
|
Posted: Wed Oct 05, 2005 5:38 am Post subject: if NOT statements |
|
|
Hi folks,
love the work you guys are doing and so am building a few lua games... I'll release them when I'm comfortable at others laughing at my code ;-) or more likely when they work ok.
anyway, rather than a huge mess of complicated recursive code, is it possible to have a statement that looks like the following code
if variable1 ~= variable2 ~= variable3 ~= variable4 then
-- do something
end
also I've checked the math. wiki descriptions but couldn't find anything. Is there anyway to compute factorials ? ie 4! (4*3*2*1) - other than a self written recursive function (again!).
many thanks guys
SP. |
|
| Back to top |
|
 |
BePe86
Joined: 02 Oct 2005 Posts: 10 Location: Norway
|
Posted: Wed Oct 05, 2005 5:42 am Post subject: |
|
|
Hi. you could do if var1 ~= var2 and var2 ~= var3 and var3~=4 ... ... then
...
end...
but that looks ugly, and using tables with for is better.
As for the factorial, you could also use for here as well, but I prefer the recursive thing. _________________ EU PSP 1.52 -> 2.0 -> 1.50
Untold Legends
32MB + 1GB Memory Sticks |
|
| Back to top |
|
 |
stonepimp
Joined: 23 Sep 2005 Posts: 5
|
Posted: Wed Oct 05, 2005 6:39 am Post subject: |
|
|
yeap tried to go down that route, but...
variable1 = "10"
variable2 = "20"
variable3 = "30"
variable4 = "10"
so using "if var1 ~= var2 and var2 ~= var3 and var3~=4"
the above statement would be true (var1 doesn't equal var2, variable2 doesn't equal var3 and var3 doesn't equal var4) but...
I want var1 ~=var2 ~= var3 ~= var4 (ie none of these variables can be the same...
Please note the solution for the above is simple but when you have 10+ variables the number of combinations grows significantly !
(eg. 3628800 combinations for 10 variables - and I'm not written that and statement out by hand!).
Any other ideas? will try anything you suggest !?%@
;-) |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
|
| Back to top |
|
 |
|