About Monkey 2 › Forums › Monkey 2 Programming Help › Continue Line
This topic contains 26 replies, has 12 voices, and was last updated by 
 abakobo
 1 year, 5 months ago.
- 
		AuthorPosts
 - 
		
			
				
February 18, 2017 at 3:16 am #7193
I don’t like line continuation characters at all. If there’d be only one change to make, I’d request that “+” qualify as a continuation character, or make all operators qualify. Don’t know how messy that would be, but I’d presume that using “..” will be unfun for parsers and/or preclude using it in the monkey1 way for slicing (is that even a thing anymore?)
October 22, 2017 at 3:42 am #11270Is there a format to split an “IF” statement over multiple lines?
October 22, 2017 at 4:17 am #11271Not currently, I haven’t felt the need so far for anything beyond the current scheme of allowing line splitting after ‘(‘, ‘,’ and ‘[‘. That’s just the way I like to code I guess – if a line get so long it’s wider than a page, I like to break it into bits. Ditto with functions longer than a page(ish).
But that’s just me. The ‘..’ token is currently unused and I’d be OK with adding that for line ‘continuation as it’s clean and simple and makes it obvious that you are in fact splitting a line.
October 22, 2017 at 4:24 am #11273Good! Thought I was missing something and I was trying everything to get it to work
In MonkeyX1 I had:
[/crayon]Monkey12345[crayon-5cb9d03c71e19271175762 inline="true" ]if game.level.getCollisionTile(x - image.w2 + amount, tempY + image.h2 - amountY) > 0 orgame.level.getCollisionTile(x + image.w2 - amount, tempY + image.h2 -amountY) > 0 orgame.level.getCollisionTile(x, tempY + image.h2 - amountY) > 0 thenBut in Monkey2 its currently:
If _level.GetCollisionTile(tempX - w2 , position.y + h2 - 1 ) = 0 And _level.GetCollisionTile(tempX - w2 , position.y - h2) = 0 And _level.GetCollisionTile(tempX - w2 , position.y) = 0(hmmm that is meant to be one long line…)
So its a bit long to read nicely…
October 22, 2017 at 4:40 am #11276In the meantime, you could break long ‘And’ If statements into multiple block Ifs, eg:
Monkey1234567If _level.GetCollisionTile(tempX - w2 , position.y + h2 - 1 ) = 0If _level.GetCollisionTile(tempX - w2 , position.y - h2) = 0If _level.GetCollisionTile(tempX - w2 , position.y) = 0EndifEndifEndifThis is what I tend to do – I like having just one statement per line (as you might have guessed).
October 22, 2017 at 4:44 am #11278Yeah, but I needed an ElseIf for all the conditions
[/crayon]Monkey123456[crayon-5cb9d03c7ac82860558344 inline="true" ]If _level.GetCollisionTile(tempX - w2 , position.y + h2 - 1 ) = 0 And _level.GetCollisionTile(tempX - w2 , position.y - h2) = 0 And _level.GetCollisionTile(tempX - w2 , position.y) = 0position.x = tempXElseposition.x = Round((position.x - w2) / _level.TileSize) * _level.TileSize + w2EndIn one place I did split it up like so:
[/crayon]Monkey12345678910111213141516171819202122[crayon-5cb9d03c7ac88890595387 inline="true" ]Local tileData:Int[] = New Int[3]tileData[0] = _level.GetCollisionTile(position.x - w2 + amount, tempY + h2 - amountY)tileData[1] = _level.GetCollisionTile(position.x + w2 - amount, tempY + h2 - amountY)tileData[2] = _level.GetCollisionTile(position.x, tempY + h2 - amountY)If tileData[0] > 0 Or tileData[1] > 0 Or tileData[2] > 0deltaValue.y = 0_jumping = falseposition.y = Round((tempY + h2) / _level.TileSize) * _level.TileSize - h2SetupStandAnimation()If tileData[0] = 92 Or tileData[0] = 93 Or tileData[1] = 92 Or tileData[1] = 93 Or tileData[2] = 92 Or tileData[2] = 93SetupDieAnimation()deltaValue.y = -430EndElseposition.y = tempYEndOctober 22, 2017 at 5:07 am #11279add stuff, but don’t break stuff.
October 22, 2017 at 5:11 am #11280add stuff, but don’t break stuff.
Definitely! EOL handling is strangely tricky, but think I have it covered this time around.
October 22, 2017 at 8:51 am #11284My preference would be to use “And” / “Or” as the line continuation instead of .. if possible
October 22, 2017 at 7:58 pm #11293I vote for the ‘..’ to split lines, strings should just be added to itself ‘MyString += “My text’ sort of thing.
October 22, 2017 at 10:44 pm #11294“..” isn’t intuitive though and seems like going backwards to me as Monkey 1 had And / Or.
October 24, 2017 at 10:01 am #11303“..” and “And” and “Or” !?
All of them would be usefull.. - 
		AuthorPosts
 
You must be logged in to reply to this topic.