Jump to content

and/or


dennismonsewicz

Recommended Posts

I've been wondering about this myself..

 

Would it also then be possible to give the code choices?

 

Like say if this event happens

 

The code can either run this script

 

or

 

this script

 

or this script

 

which ever one it chooses.

 

Maybe if you matched it up with a math.random sort of thing?

Link to comment
Share on other sites

no. a script cannot "choose". Its programmed to do a certain thing. Once it finds that it has the permissions to go on, it will, with the first thing.

 

for example, this is pointless:

if (($var == 2 OR $var == 3) OR ($var == 2 AND $var == 3)) {

 

}

 

Main problem here:

a $var cannot equal 2 things at the same time. Unless its in an array, in which case you would use array functions, not "=="

 

Link to comment
Share on other sites

exactly.  

 

($var == 2 AND $var == 3)

 

would break down because $var cannot equal two things at the same time.  Now if you were to do this:

 

$var = 5;

if(($var > 4) AND ($var < 6)) {

  // condition is true, code here will execute

} elseif (($var > 4) OR ($var < 6)) {

 // condition is true, but will not get executed because the first condition was true

}

 

But you could do this:

 

$var = 10;

if(($var > 4) AND ($var < 6)) {

  // condition is not true, code here won't execute

} elseif (($var > 4) OR ($var < 6)) {

 // condition is true, code will execute

}

 

Link to comment
Share on other sites

okay && is the same as AND and || is the same as OR.  The only difference between them is the order in which PHP will parse them mathematically.  Kind of like how division will always be performed before multiplication, then addition, then subtraction.  && will take precedence over AND and || will take precedence over OR so if you used both of && and AND in the same condition, && will be evaluated first. 

Link to comment
Share on other sites

you mixed a math.random in there tho it would be able to choose.

 

cuase you could setup a bunch of different cases.. or a bunch of Dynamic cases that use other data

 

and say $action=math.random or something

 

then say

 

switch($action)

 

case '1':

//do this option

break;

case '2':

//do this

break;

 

ect...

Link to comment
Share on other sites

Well, just to reinforce the point, you can't have an and/or because it logically makes no sense.  It's the equivalent of OR technically. >_>

 

Not necessarily. 

 

OR:

a  b

X  X true

X  O true

O  X true

O  O false

 

yes, if you do a condition with an OR, it will evaluate true if both are true, making it like an AND, but you would not be able to separate the logic.  For instance, if you wanted to do one thing if either one of them would be true (OR), but you wanted to do something else if both were true (AND), you could not do that with an OR by itself.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.