forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

if NOT statements

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
stonepimp



Joined: 23 Sep 2005
Posts: 5

PostPosted: Wed Oct 05, 2005 5:38 am    Post subject: if NOT statements Reply with quote

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
View user's profile Send private message
BePe86



Joined: 02 Oct 2005
Posts: 10
Location: Norway

PostPosted: Wed Oct 05, 2005 5:42 am    Post subject: Reply with quote

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
View user's profile Send private message
stonepimp



Joined: 23 Sep 2005
Posts: 5

PostPosted: Wed Oct 05, 2005 6:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Wed Oct 05, 2005 6:58 am    Post subject: Reply with quote

Store all variables in a table, use two nested for loops, where you compare in the inner loop the indices of both loops and if they are not equal, you compare the values. If they are equal, return false, otherwise return true at the end of the function.

But this is not Lua Player related, I just don't want this to be a general Lua help forum, take a look at http://www.lua.org/ http://lua-users.org/wiki/TutorialDirectory http://www.lua.org/lua-l.html and the very good book http://www.lua.org/pil/
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group