How to make an if/or in 1 line
Moderator: InsideQC Admins
7 posts
• Page 1 of 1
How to make an if/or in 1 line
Hello, first my script:
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")
?
- Code: Select all
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")
?
-

skite2001 - Posts: 17
- Joined: Mon Nov 17, 2008 5:40 pm
- Code: Select all
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);
}
-

Mexicouger - Posts: 514
- Joined: Sat May 01, 2010 10:12 pm
Mexicouger wrote:
- Code: Select all
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: Select all
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.
-

skite2001 - Posts: 17
- Joined: Mon Nov 17, 2008 5:40 pm
(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.
(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.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
