Unexpected variable error
-
Hey guys,
I'm trying to make a space shooters game and it is giving me an unexpected variable error.
I have finished coding the game. Here is my code where it is giving me an error.if moveEnemy==true then
enemies[enemyCount].x += ((85/alienSpace) * enemyDirection)
endif
setSpriteLocation(enemies[enemyCount], { enemies[enemyCount].x, enemies[enemyCount].y } )
If (enemies[enemyCount].x > gwidth() - 50 or enemies[enemyCount].x < 50) and getSpriteVisibility(enemies[enemyCount])
dropRow = true
endif -
@ahallett2002 It is difficult to tell from this code snippet. I think we will need to see some more. I suspect that enemyCount is a loop counter. If it is a for loop it needs to go from 0 to the length of your enemies array. You must have first called createSprite() for every entry in the array.
-
I’ve had this when I forget to write ‘loop’ or ‘then’ ...
-
You're missing a "then" on the end of the "If" line, hence dropRow is unexpected.
For what it's worth, this is completely unnecessary too:
setSpriteLocation(enemies[enemyCount], { enemies[enemyCount].x, enemies[enemyCount].y } )
What you're doing there is saying "hey, set sprite.x to sprite.x". Or in other words,
enemies[enemyCount].x += ((85/alienSpace) * enemyDirection)
directly sets the x position of the sprite, you don't need to call thesetSpriteLocation
method just to be sure. -
@Martin thanks! That got rid of the error. Now its giving me an error for the repeat function
Code:
printAt(0.0,enemyMoveCounter,"---"-alienSpeed) If dropRow then enemyDirection *= -1 for enemyCount=0 to 40 loop enemies[enemyCount].y += 50 enemies[enemyCount].x ((85/aliensSpace * enemyDirection) dropRow = false repeat
-
I've added the backticks to display it properly and also indented it properly.
It should be obvious what the error is telling you now :)
[edit] Actually, I can see five errors altogether, but maybe some are just typos?
-
Let's see if I can type this without error - the line where you modify X will be a guess as to what you actually want to do...
printAt(0, 0, enemyMoveCounter, "---", -alienSpeed) // you were missing a comma after 0 and after the second " If dropRow then enemyDirection *= -1 for enemyCount = 0 to 40 loop enemies[enemyCount].y += 50 enemies[enemyCount].x = ((85 / aliensSpace) * enemyDirection) // = was missing and close bracket after aliensSpace repeat dropRow = false endif // was missing - suspect this was the real problem
-
I'm also guessing there's a logic issue there because you're only checking
drawRow
once in the outer if statement and yet you are setting it to false 40 times in the for loop. Either you mean it to do something different to what it is doing or it could be moved to the line between therepeat
and theendif
, thus only setting it to false once. I've modified my answer. -
@Martin yes it was, thanks for the edit. The game works perfectly fine now!!