I found a few typos in your code.
Here's some of the prominent I have noticed:
- Inconsistent Intendation
elsif
mistyped as else if
end
statements seemingly placed with no sense
- No spacing and no comments
And please, take commenting seriously. It is being pointed out for a reason. After all, you still want to read your code if you come back to it in a couple of weeks or months. The else if
s and the misplacements of the end
keyword have caused microstudio to misinterpret your code, giving the error.
Below I have posted the fixed code of the main file. And please, keep your intendation more consistent. It can avoid confusion and beginner mistakes.
init = function()
player = object
xvel = 0
yvel = 0
Direction = 0
image = "engine"
width = 54
height = 141
xscale = 0.5
yscale = 0.5
rotvel = 0
x = 0
y = -68
speed = 0
test = 0
boom = 0
boomed = 0
terminal = false
end
camera = object
x = 0
y = 0
following = player
end
char = object
x = 0
y = 0
image = "player"
eject = 0
yvel = 0
end
end
local PI = 3.14159
toRadians = function(degrees)
return degrees * (PI / 180)
end
move = function(steps)
if player.Direction > 180 then
player.Direction = player.Direction - 360
elsif player.Direction < -179 then
player.Direction = player.Direction + 360
end
player.xvel = player.xvel + cos(toRadians(player.Direction + 90)) * steps
player.yvel = player.yvel + sin(toRadians(player.Direction + 90)) * steps
end
update = function()
//if char.eject == 1
if keyboard.RIGHT then
char.x += 1
elsif keyboard.LEFT then
char.x -= 1
end
if player.Direction > 180 then
player.Direction = 180 - player.Direction - 179
end
camera.x = camera.following.x
camera.y = camera.following.y
camera.x = clamp(camera.x, -35, 150)
player.x = clamp(player.x, -165, 287)
char.x = clamp(char.x, -165, 287)
if player.x < -164 or player.x > 286 then
player.xvel *=0.9
end
if char.eject == 1 then
if char.y > -70 then char.yvel -= 0.05
else char.yvel = 0 end
end
if char.eject == 0 then
if player.image != "exploded" then
if keyboard.UP then
move(0.007)
player.image = "engine"
else
player.image = "rocket"
end
if keyboard.RIGHT then
player.rotvel -= 0.007
end
if keyboard.LEFT then
player.rotvel += 0.007
end
end
end
player.Direction += player.rotvel
player.x += player.xvel
player.y += player.yvel
if player.y > -65 then
player.yvel -= 0.005
else
player.yvel *= 0.6
player.xvel *= 0.6
player.rotvel *= 0.6
end
if sqrt(player.xvel * player.xvel + player.yvel * player.yvel) > 0.3 then
player.terminal = true
if player.y < -63 then
print("BOOOM")
player.boom = 1
player.boomed = 1
else
player.terminal = 0
end
end
player.speed = player.xvel + player.yvel
player.test = sqrt(player.xvel * player.xvel + player.yvel * player.yvel)
if keyboard.SPACE then
char.eject = 1
camera.following = char
char.x = player.x
char.y = player.y
end
if keyboard.SHIFT then
char.eject = 0
camera.following = player
end
char.y += char.yvel
animnum = 0
if player.Direction > 180 then
player.Direction = player.Direction - 360
elsif player.Direction < -179 then
player.Direction = player.Direction + 360
end
end
draw = function()
screen.clear()
screen.drawMap("map", 0 - camera.x, 627 - camera.y, 10062, 7000 )
screen.setDrawRotation(player.Direction)
screen.setDrawScale(player.xscale,player.yscale)
screen.drawSprite(player.image, player.x - camera.x, player.y - camera.y, player.width, player.height)
screen.setDrawRotation(0)
screen.drawSprite( "station", -22.5 - camera.x, -43.25 - camera.y, 132, 150 )
screen.drawText("Speed : " + round(abs(player.speed)*60), -110, 90, 20, "rgb(0,0,0)")
screen.drawText("Height : " + round(player.y+68), 100, 90, 20)
if player.test > 0.3 and player.yvel < 0 then
screen.drawText("WARNING : APPROACHING TERMINAL VELOCITY", 0, 77, 29, "rgb(255,0,0)")
end
if player.boomed == 1 then
screen.drawText("EXPLODED",0,60,50,"rgb(255,0,0)")
player.terminal = false
end
if player.boom == 1 then
while animnum < 15
screen.clear()
screen.drawMap("map", 0 - camera.x, 627 - camera.y, 10062, 7000 )
screen.setDrawRotation(player.Direction)
screen.setDrawScale(player.xscale,player.yscale)
screen.drawSprite(player.image, player.x - camera.x, player.y - camera.y, player.width, player.height)
screen.setDrawRotation(0)
screen.drawSprite( "station", -22.5 - camera.x, -43.25 - camera.y, 132, 150 )
screen.drawText("Speed : " + round(abs(player.speed)*60), -110, 90, 20, "rgb(0,0,0)")
screen.drawText("Height : " + round(player.y+68), 100, 90, 20)
screen.drawSprite("bum0." + animnum, player.x-camera.x, player.y-camera.y + 25, 200, 200)
player.image = "exploded"
animnum += 1
sleep 60 milliseconds
end
player.boom = 0
end
if char.eject == 1 then
screen.drawSprite(char.image, char.x - camera.x, char.y - camera.y, 20, 20)
end
end