Jump to content

Photo

Question about Basic "if"


6 replies to this topic

#1 asdronin OFFLINE  

asdronin

    Space Invader

  • 26 posts

Posted Fri May 10, 2019 7:28 PM

Hi all,

As I have coded using variations of Basic language before (like Dark Basic Pro) I tend to think of some syntax things that should be the same always but of course its never everything the same. Then I wonder, how can I make a "if then" structure thats longer than one line? I have seen in all the sources I explored so far that if there is more than one command you just use ":" to add more things in same line, but isnt there a way to write that in several lines? I tend to prefer to have one command by line, I mean I see it better even if that makes the code longer, so I tried what I learned in the past and tried with "endif" or "end if" or just "end" and nothing appears to work, in help and tutorials I see always : is used in same line so maybe thats the only way we can make more than one thing happen inside a "if" block, could you please clarify this?



#2 Mord OFFLINE  

Mord

    River Patroller

  • 2,697 posts
  • Location:Canada

Posted Sat May 11, 2019 5:16 AM

Currently there's no way to have multi-line if-then-else structures.  Most you can do is have the commands that need to be done separated with colons on the same line.  sometimes I've done blocks of code intended for an if statement as it's own subroutine and just plugged that in. Not the most efficient but certainly more legible. 

 

Other times I've set up the IF statement so that it'll look for a skip condition. So if I wanted a bunch of commands to activate when A < 10, I'd instead write the if statement to be if A >= 10 then goto skiplabel.  That way if it doesn't jump ahead to that label, it means the condition I really wanted is true, and I can safely execute a block of code between the if statement and the skiplabel.



#3 asdronin OFFLINE  

asdronin

    Space Invader

  • Topic Starter
  • 26 posts

Posted Sat May 11, 2019 10:14 PM

Thanks a lot Mord, so we have to deal with these techniques to do that, I think that should have been implemented in the tool other way but of course its a complex thing for the author. Additionally as I have verified "else" should always be in same line too (I got error saying "else" is not recognized word), I will follow your guidelines and hoepfully I manage to deal with this, I think it makes it harder to make a game but not impossible of course.

 

By the way, a little off topic question, what games have you made? your avatar seems very familiar to me so maybe I played a game you made without knowing it was your creation, in any case your avatar is quite cool =)



#4 Mord OFFLINE  

Mord

    River Patroller

  • 2,697 posts
  • Location:Canada

Posted Sun May 12, 2019 2:38 PM

I tend to get distracted easily so I haven't actually completed a full game yet.  On the 7800 I've mostly worked on Graze Suit Alpha although I've done a bunch of various demos, most of them involving attempts at scrolling in 7800basic. Use to tinker with the 2600 in assembly long before that but again never actually finished anything.



#5 asdronin OFFLINE  

asdronin

    Space Invader

  • Topic Starter
  • 26 posts

Posted Sun May 12, 2019 5:03 PM

Well its hard to make a game using these tools and language we have here, I looked into the Graze Suit Alpha video on youtube and it looks very cool fast action game, quite well done, I know how hard is to complete a game in any tool when you work on your own, requires lot of time and energy, Im sure you will complete one game soon and will be great, I found out your rpgtiledemo when I was searching for tile related games and its an awesome code really, keep making great stuff =)



#6 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 29,023 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sun May 12, 2019 5:49 PM

Other times I've set up the IF statement so that it'll look for a skip condition. So if I wanted a bunch of commands to activate when A < 10, I'd instead write the if statement to be if A >= 10 then goto skiplabel.  That way if it doesn't jump ahead to that label, it means the condition I really wanted is true, and I can safely execute a block of code between the if statement and the skiplabel.


Speaking of that, although the batari Basic page is for Atari 2600 programming, it has a section that talks about the same thing:

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



#7 asdronin OFFLINE  

asdronin

    Space Invader

  • Topic Starter
  • 26 posts

Posted Sun May 12, 2019 7:24 PM

Thanks a lot for showing this Random Terrain, I think as said I will be using these techniques to deal with the "if" structure you have implemented =), certainly Im part of the endif addicts group haha so these techniques work fine for me =)






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users