mIRC Home    About    Download    Register    News    Help

Print Thread
#228762 09/01/11 07:47 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
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..
Code:
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,.) }
sparta #228770 09/01/11 11:50 PM
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
To really help you I'd want to know what "stuff" you want to do.

sparta #228772 10/01/11 12:09 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
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.

sparta #228776 10/01/11 04:13 AM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
You could us a bitwise operation:

Code:
  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.

I am SReject
My Stuff
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
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. smile


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #229030 19/01/11 05:10 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
You could shorten the code in you sig:
Code:
if ($me == tired) { echo -a Get a pot of coffee now $me $+ . }
grin


I am SReject
My Stuff
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
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.
Code:
$iif($me != tired,return,echo -a Get a pot of coffee now $me $+ .)

Tomao #229066 20/01/11 01:46 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
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...

Code:
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. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
if $me != tired { return to work }
echo -a Get a pot of coffee now, $me $+ .


I am SReject
My Stuff
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: Riamus2
Run 10 miles
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. cool

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.

Tomao #229079 20/01/11 07:53 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
hence the return to work
:P


I am SReject
My Stuff

Link Copied to Clipboard