# Boolean operator syntax error

## Recommended Posts

Hello Guys,

I have been using the following without issue:-

```if x= 49 || x=57 then a=26
```

But if I use the following, I get a Syntax error:-

```if x= c-2 || x=c+2 then a=26
```

I guessing I'm missing something really obvious here, but what have I done wrong. I have checked out http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#boolean, and from what I can see, what I'm doing is good. For what I'm trying to do, it is important that the x value is compared against the result of the c value.

The weird thing is that the following compiles without issue:-

```if x=c+1 then a=14
```

Is the problem that I'm doing x=c-2 followed by the boolean or?

##### Share on other sites

try

if x= (c-2) || x=(c+2) then a=26

Edit you need a space tween - and 2

Edited by Osgeld

##### Share on other sites

Thanks for the response Osgeld. Spaces is not the issue:-

```if x = c - 5 || x = c + 5 then a=28
```

The above still fails to compile. I also tried:-

```if x = (c - 5) || x = (c + 5) then a = 28
```

But still no cigar. Any further ideas?

##### Share on other sites

tdp,

I got this to compile:

if x= c-2 then a=26 else if x=c+2 then a=26

I'm not sure if this is what you are looking for, thanks.

##### Share on other sites
This Works

```
if x <> c - 2 && x <> c + 2 then skip
a = 26

skip
```

This Works better

```
if c - 2 <> x && c + 2 <> x then skip
a = 26

skip
```
Edited by bogax

##### Share on other sites

Thanks guys. Digging into the RT bBatari docs some more, I can see that OR (||) has more restrictions on it that AND (&&). Case in point:-

```if player0x = c + 5 && player0y = d + 5 then a=30
```

The above compiles fine. Now, just swap the operator from AND to OR:-

```if player0x = c + 5 || player0y = d + 5 then a=30
```

The above does not compile. Looks like there are stricter restrictions on OR, compared to AND. Still trying stuff.

Edited by tdp

##### Share on other sites

Earlier versions of bB couldn't use math in if-thens, so we did the math in temporary variables and used those in the if-thens. I still do that to avoid any problems.

##### Share on other sites

Hello Random - what do you mean by temporary variables? Will need to hit the docs again to learn more.

Edited by tdp

##### Share on other sites

Hello Random - what do you mean by temporary variables?

randomterrain.com/atari-2600-memories-batari-basic-commands.html#temp_variables

Example:

```   temp6 = c + 5 : temp5 = d + 5
if player0x = temp6 || player0y = temp5 then a = 30```

##### Share on other sites

@RT - Awesome stuff. I will try this later.

Thank you so much!!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.