Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

Or

9 replies · 2,054 views · Started 22 January 2008

What is the Zscript way to say "or"? i.e. "and" is "&&". Is "or" "||", or is it something else?

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?

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.

...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
}

ScaryBinary wrote:...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.

C-Dawg wrote: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 wrote: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.