Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

How to make an if/or in 1 line

| Inside3d Forums Forum Index -> QuakeC Programming

View previous topic :: View next topic
Author | Message
--- | ---
skite2001 Joined: 17 Nov 2008 Posts: 17 |

Posted: Wed Jun 30, 2010 4:51 pm Post subject: How to make an if/or in 1 line |

Hello, first my script:

Code:
if (s == "wizmet1_2") { r = rint(random() * 3); if (r == 0) sound (e, CHAN_AUTO, "walk/metal1.wav", 0.5, ATTN_NORM);
else if (r == 1)
sound (e, CHAN_AUTO, "walk/metal2.wav", 0.5, ATTN_NORM);
else if (r == 2)
sound (e, CHAN_AUTO, "walk/metal3.wav", 0.5, ATTN_NORM);
else
sound (e, CHAN_AUTO, "walk/metal4.wav", 0.5, ATTN_NORM);
}
if (s == "ecop1_6")
{
r = rint(random() * 3);
if (r == 0)
sound (e, CHAN_AUTO, "walk/metal1.wav", 0.5, ATTN_NORM);
else if (r == 1)
sound (e, CHAN_AUTO, "walk/metal2.wav", 0.5, ATTN_NORM);
else if (r == 2)
sound (e, CHAN_AUTO, "walk/metal3.wav", 0.5, ATTN_NORM);
else
sound (e, CHAN_AUTO, "walk/metal4.wav", 0.5, ATTN_NORM);
}

and now my question...how can i add the 2nd unneeded bunch of script to the 1st one, like:
if (s == "wizmet1_2") or (s == "ecop1_6")
?

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Wed Jun 30, 2010 4:55 pm Post subject: |

if (a==c || b==d) || is logical or. | is binary or. _________________ What's a signature?

Back to top |

Mexicouger Joined: 01 May 2010 Posts: 129 |

Posted: Wed Jun 30, 2010 4:58 pm Post subject: |

Code:
if (s == "wizmet1_2" | s == "ecop1_6") { r = rint(random() * 3); if (r == 0) sound (e, CHAN_AUTO, "walk/metal1.wav", 0.5, ATTN_NORM);
else if (r == 1)
sound (e, CHAN_AUTO, "walk/metal2.wav", 0.5, ATTN_NORM);
else if (r == 2)
sound (e, CHAN_AUTO, "walk/metal3.wav", 0.5, ATTN_NORM);
else
sound (e, CHAN_AUTO, "walk/metal4.wav", 0.5, ATTN_NORM);
}

Back to top |

skite2001 Joined: 17 Nov 2008 Posts: 17 |

Posted: Wed Jun 30, 2010 8:31 pm Post subject: |

Mexicouger wrote:

Code:
if (s == "wizmet1_2" | s == "ecop1_6") { r = rint(random() * 3); if (r == 0) sound (e, CHAN_AUTO, "walk/metal1.wav", 0.5, ATTN_NORM);
else if (r == 1)
sound (e, CHAN_AUTO, "walk/metal2.wav", 0.5, ATTN_NORM);
else if (r == 2)
sound (e, CHAN_AUTO, "walk/metal3.wav", 0.5, ATTN_NORM);
else
sound (e, CHAN_AUTO, "walk/metal4.wav", 0.5, ATTN_NORM);
}

sry mexi, doesn't work!
if i try to compile the files, i get the error:
"type mismatch for | (string and string)"
@Spike
sry, i want that "s==" is always "s=="! means i only want different textures be the same string
changed to:

Code:
if (s == "wizmet1_2" || s == "ecop1_6")

now it works^^
thx for the help
Last edited by skite2001 on Wed Jun 30, 2010 8:38 pm; edited 1 time in total

Back to top |

mk Joined: 04 Jul 2008 Posts: 94 |

Posted: Wed Jun 30, 2010 8:34 pm Post subject: |

Because you must use the logical 'or', not the binary 'or'. _________________ Makaqu engine blog / website. Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.

Back to top |

Mexicouger Joined: 01 May 2010 Posts: 129 |

Posted: Wed Jun 30, 2010 9:37 pm Post subject: |

So close Anyways, When do you use those Logics? I don't understand what the Difference is.

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Wed Jun 30, 2010 10:26 pm Post subject: |

(1 || 2) == 1 (1 | 2) == 3 is the difference. :P More seriously though.. (string | float) == syntax error
(string || float) == compares each side against 0/empty string.
They also have a different order of precidence, eg:
if (s == "wizmet1_2" | s == "ecop1_6")
is interpreted as:
if (s == ("wizmet1_2" | s) == "ecop1_6")
and then you're doing ((string == float) == string) which is two syntax errors.
_________________
What's a signature?

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> QuakeC Programming | All times are GMT
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 © 2004 phpBB Group