Inside3D!
     

How to make an if/or in 1 line

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
skite2001



Joined: 17 Nov 2008
Posts: 17

PostPosted: Wed Jun 30, 2010 4:51 pm    Post subject: How to make an if/or in 1 line Reply with quote

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



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Wed Jun 30, 2010 4:55 pm    Post subject: Reply with quote

if (a==c || b==d)

|| is logical or.
| is binary or.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Mexicouger



Joined: 01 May 2010
Posts: 129

PostPosted: Wed Jun 30, 2010 4:58 pm    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger MSN Messenger
skite2001



Joined: 17 Nov 2008
Posts: 17

PostPosted: Wed Jun 30, 2010 8:31 pm    Post subject: Reply with quote

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



Joined: 04 Jul 2008
Posts: 94

PostPosted: Wed Jun 30, 2010 8:34 pm    Post subject: Reply with quote

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



Joined: 01 May 2010
Posts: 129

PostPosted: Wed Jun 30, 2010 9:37 pm    Post subject: Reply with quote

So close Surprised

Anyways, When do you use those Logics? I don't understand what the Difference is.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Wed Jun 30, 2010 10:26 pm    Post subject: Reply with quote

(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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    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