Jump to content

Photo

Boolean operator syntax error


9 replies to this topic

#1 tdp OFFLINE  

tdp

    Chopper Commander

  • 138 posts

Posted Mon May 28, 2018 11:08 AM

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.randomter...ds.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?



#2 Osgeld OFFLINE  

Osgeld

    Quadrunner

  • 5,512 posts
  • Location:Nashville, TN

Posted Mon May 28, 2018 11:25 AM

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

Edit you need a space tween - and 2

Edited by Osgeld, Mon May 28, 2018 11:29 AM.


#3 tdp OFFLINE  

tdp

    Chopper Commander

  • Topic Starter
  • 138 posts

Posted Tue May 29, 2018 11:53 AM

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?



#4 Lewis2907 ONLINE  

Lewis2907

    Chopper Commander

  • 245 posts
  • Location:Senatobia, MS

Posted Tue May 29, 2018 12:21 PM

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. 



#5 bogax OFFLINE  

bogax

    Dragonstomper

  • 761 posts

Posted Tue May 29, 2018 5:50 PM

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, Tue May 29, 2018 6:01 PM.


#6 tdp OFFLINE  

tdp

    Chopper Commander

  • Topic Starter
  • 138 posts

Posted Wed May 30, 2018 9:32 AM

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, Wed May 30, 2018 9:32 AM.


#7 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,698 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed May 30, 2018 12:35 PM

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.



#8 tdp OFFLINE  

tdp

    Chopper Commander

  • Topic Starter
  • 138 posts

Posted Wed May 30, 2018 2:05 PM

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


Edited by tdp, Wed May 30, 2018 2:22 PM.


#9 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,698 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed May 30, 2018 2:22 PM

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


#10 tdp OFFLINE  

tdp

    Chopper Commander

  • Topic Starter
  • 138 posts

Posted Wed May 30, 2018 2:39 PM

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

 

Thank you so much!!






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users