View Full Version : Or
What is the Zscript way to say "or"? i.e. "and" is "&&". Is "or" "||", or is it something else?
Joe123
01-22-2008, 12:15 PM
or: ||
and: &&
not: !
There's no exclusive or though :(
So if I wanted the script to activate if Link was on dmap 12 or 13, I would do
if (Link->GetCurDmap= 12||13)
Right?
Joe123
01-22-2008, 02:00 PM
No, you'd do:
if(Link->GetCurDmap() == (12||13)){
Or even:
int dmap = Link->GetCurDmap();
if(dmap == (12 || 13)){
Just personal preference that bit really.
Anyway:
=
means 'is set to', so:
(Link->GetCurDmap= 12||13)
means 'Link's Current Dmap is set to 12 or 13' (which is obviously impossible),
whereas
==
means 'is equal to', so:
if(Link->GetCurDmap == 12||13)
means 'if Link's Current Dmap is equal to 12 or 13'.
Also, I think you have to put the extra brackets around like I did in the first example, and you need '()' after 'GetCurDmap', just cause that's how it works.
Oh. ==. And I know there was an error with the () in the code. I was just typing it from memory. Thanks. Day and Night script, here I come.
ScaryBinary
01-22-2008, 09:00 PM
...Maybe I'm off my rocker here, but I don't think any of that will actually work. That's very un-C like as far as syntax goes, and I had trouble getting statements like that to compile (and when they did, I got unreliable results). In one case, I got it to compile, but the if statement was always executed no matter what I was checking.
I think you'll need to do something like:
if ((Link->GetCurDmap() == 12) || (Link->GetCurDmap() == 13)) {
// blah blah blah
} instead.
It'd be a tiny bit faster to store the GetCurDmap() result in a local variable first.
int CurDMap = Link->GetCurDmap();
if ((CurDMap == 12) || (CurDMap == 13)) {
// blah blah blah
}
C-Dawg
01-22-2008, 09:06 PM
...Maybe I'm off my rocker here, but I don't think any of that will actually work. That's very un-C like as far as syntax goes, and I had trouble getting statements like that to compile (and when they did, I got unreliable results). In one case, I got it to compile, but the if statement was always executed no matter what I was checking.
I think you'll need to do something like:
if ((Link->GetCurDmap() == 12) || (Link->GetCurDmap() == 13)) {
// blah blah blah
} instead.
It'd be a tiny bit faster to store the GetCurDmap() result in a local variable first.
int CurDMap = Link->GetCurDmap();
if ((CurDMap == 12) || (CurDMap == 13)) {
// blah blah blah
}
I'm with Scary Binary. The way to test if a variable is equal to X or Y is to compare it with X, then compare with Y. I'm not aware of any short cuts, though I could be wrong.
I'm with Scary Binary. The way to test if a variable is equal to X or Y is to compare it with X, then compare with Y. I'm not aware of any short cuts, though I could be wrong.
Okay. Thanks guys!
pkmnfrk
01-23-2008, 10:16 PM
I can guarantee that there are no short cuts. This isn't English, this is ZScript!
I can guarantee that there are no short cuts. This isn't English, this is ZScript!
And I like English better! Although at least with ZScript you don't have to learn grammer.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.