Jump to content

Using 2 or more if statements in the same line.

Recommended Posts




  if player1y<76 then e=14 : if f{1} then e=13



  if player1y<76 then e=14
  if player1y<76 && f{1} then e=13


Both of these examples seem to work perfectly fine in my code. The top example uses less memory.


But I have been advised to never use 2 or more if statements on the same line.




Is it because it's generally bad practice and can lead to confusing code?


Or does it actually cause a glitch and make the game crash upon reading? Because in terms of memory usage, if the top line reads correctly every time, obviously it would be preferable.





Edited by freshbrood

Share this post

Link to post
Share on other sites

I actually didn't know you could do that, but the first example would be split up on several lines like this


 if player1y>=76 then skip


 if f{1} then e=13



It's easier to read, especially if you add more stuff or if statements down the line.

You might want to try this instead btw

if f{1} then e=13 else e=14 


Another good thing is that it's more similar to the assembly it turns into, if you do this..


 if player1y>=76 then skip

 if !f{1} then a


 goto skip





you're pretty much writing assembly

Edited by Lillapojkenpåön
  • Like 1

Share this post

Link to post
Share on other sites

The bB page says these things:


"Using multiple if…thens in a single line might not work correctly if you are using boolean operators."


"If you use || in an if…then statement, the statement must be located at the beginning of a line. At this time, compilation will succeed but your program will probably not work correctly. This issue will probably be fixed in a later version."


"The else keyword might not work correctly in a statement containing &&. The else keyword may also not work as expected when there is more than one if…then on a single line."

  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...