'then' expected near '=' when I am making a if statement for my game.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
BlakeBarnes00
Prole
Posts: 6
Joined: Wed Feb 10, 2016 5:05 am
Location: Conway, South Carolina
Contact:

'then' expected near '=' when I am making a if statement for my game.

Post by BlakeBarnes00 »

So I have been creating Space Invaders in the last little bit, and I came across this error: "Syntax error: enemy.lua:30: 'then' expected near '='", but I don't really understand why.. This is my code:

Code: Select all

require "player"

enemies = {}
enemy = {}

local width 	= love.graphics.getWidth()
local height 	= love.graphics.getHeight()
local scale = 4
function enemy.load( ... )
	for i=0,7 do
		enemy.image 	= love.graphics.newImage("res/Invader.png")
 		enemy.body 		= love.physics.newBody(world.world, width/2, height/4, "kinematic")
 		enemy.shape 	= love.physics.newRectangleShape(10, 10)
 		enemy.fixture	= love.physics.newFixture(enemy.body, enemy.shape)
		enemy.body:setLinearVelocity(0, 0) 

		enemy.width 	= enemy.image:getWidth()*scale
		enemy.height 	= enemy.image:getHeight()*scale
		enemy.x 		= i * (enemy.width + 10) + 1
		enemy.y 		= enemy.height + 100
		table.insert(enemies, enemy)
	end
end
function enemy.update(dt)
	for i,v in ipairs(enemies) do

    	-- let them fall down slowly
    	v.y = enemy.body:setLinearVelocity(0, 100) 

    	if v.y = player.body:getY() then
    		print("You Lose")
    	end 
	end
end

function enemy.draw( ... )
	for i,v in ipairs(enemies) do
    	love.graphics.draw(enemy.image, enemy.body:getX(), enemy.body:getY(), r, scale, scale, enemy.image:getWidth()/1.5, enemy.image:getHeight()/1.5)
	end
end
Any idea on what I am doing wrong?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: 'then' expected near '=' when I am making a if statement for my game.

Post by bobbyjones »

On line 30 use "==" instead of "=". "==" is for comparisons and "=" is for assignments.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests