|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
I need som help with this, i have 3 variables, they all can have a value between 0 and 1 (as example show), any bether/smarter way to check this? i need to be able to use diffrent commands depending on what the %var is set to..
if (%var1 == 1) || (%var2 == 1) || (%var3 == 0) { do stuff }
if (%var1 == 1) || (%var2 == 0) || (%var3 == 1) { do other stuff }
if (%var1 == 0) || (%var2 == 1) || (%var3 == 1) { do other stuff }
if (%var1 == 0) || (%var2 == 1) || (%var3 == 1) { do stuff }
if (%var1 == 1) || (%var2 == 1) || (%var3 == 0) { do other stuff }
if (%var1 == 1) || (%var2 == 0) || (%var3 == 1) { do other stuff }
if (%var1 == 1) || (%var2 == 0) || (%var3 == 1) { do stuff }
if (%var1 == 1) || (%var2 == 0) || (%var3 == 0) { do other stuff }
if (%var1 == 0) || (%var2 == 0) || (%var3 == 1) { do other stuff }
I hope you understand. Thnx
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,156 |
To really help you I'd want to know what "stuff" you want to do.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
elseif/else-constructs and/or condition-nesting might help... it really depends on what you're after, and on whether some of the various commands are identical or related, and so on.
So far, as you have three instances of "1-0-1" and two instances of "1-1-0" and of "0-1-1", you could merge their respective commands under one condition each, saving 4 lines. Of course only as long as you don't change the variables' values in the commands itself.
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
You could us a bitwise operation:
var %bitvar = $calc(%var1 + %var2 * 2 + %var3 * 4)
if (%bitvar == 0) { dostuff with all vars = 0 }
elseif (%bitvar == 1) { do stuff with var1 = 1, var2-3 = 0 }
elseif (%bitvar == 2) { do stuff with var2 = 1, var1&3 = 0 }
elseif (%bitvar == 3) { do stuff with var1-2 = 1, var3 = 0 }
elseif (%bitvar == 4) { do stuff with var3 = 1, var1-2 = 0 }
elseif (%bitvar == 5) { do stuff with var1&3 = 1, var2 = 0 }
elseif (%bitvar == 6) { do stuff with var2&3 = 1, var1 = 0 }
elseif (%bitvar == 7) { do stuff with all vars = 1 } That is if the vars are only 0's or 1's and don't change through your coding ....
Last edited by FroggieDaFrog; 10/01/11 04:19 AM.
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
Thank you, i think i can do somthing with your code, good example, i try and get back if i cant solve it.
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
You could shorten the code in you sig: if ($me == tired) { echo -a Get a pot of coffee now $me $+ . }
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
I think sparta wants to "return" when not tired, but to get a cup of coffee when he's tired. That sig is served as a satire if you get the drill. :P If the reduced size of the code is concerned, using $iif will shorten it by about 15 bytes. $iif($me != tired,return,echo -a Get a pot of coffee now $me $+ .)
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Return by itself in that seems slightly odd. I might have added an extra "command" in there...
if ($me != tired) { Run 10 miles | return } | else { echo -a Get a pot of coffee now $+($me,.) }
Run 10 miles could easily be changed to anything that might make you tired. In other words, if you aren't tired, go get tired and then return for your pot of coffee. If you're already tired, just get the pot of coffee.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
if $me != tired { return to work } echo -a Get a pot of coffee now, $me $+ .
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
Speaking of running, I've attempted to run 10 miles but failed. The longest miles I can run for thus far is five miles. I'm gonna keep training my body and build up my endurance to increase my mileage eventually. Excuse me for hijacking the thread for a general talk. :P @Froggie, without the else, usually the first if condition needs to be added with a return or halt.
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
hence the return to work :P
|
|
|
|
|