<Newbie> Error when using IF statement.

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
Mapyo
Prole
Posts: 3
Joined: Sun Jan 29, 2017 7:29 am

<Newbie> Error when using IF statement.

Post by Mapyo »

I cannot figure this out... Am I blind?



Code:

Code: Select all

function love.load()
	pj = 0
	px = 30 -- Start Pos
	py = 60 -- Start Pos
	phygrav = 0.50  -- Gravity Pull
	phyground = 61  -- Ground Location
	pgraphic = love.graphics.newImage("p_graphic.bmp")

end

function love.update(dt)
	if love.keyboard.isDown("a") then
	px = px - 0.70
	elseif love.keyboard.isDown("d") then
	px = px + 0.70
	elseif love.keyboard.isDown("w") then
	print "jump attempt"
		if pj = 0 then   <------------ Problem Starts Here
			py = py - 6
			pj = 1
		end
	end
	
	if py < 60 then
		py = py - phygrav
	elseif py >= 60 then
		pj = 0
	end
	
	
end

function love.draw()
love.graphics.draw(pgraphic, px, py)
end




Error: Syntax error: main.lua:20: 'then' expected near '='

stack traceback:
[C]: at 0x7ff82aed3af0
[C]: in function 'require'
[string "boot.lua"]:429: in function <[string "boot.lua"]:275>
[C]: in function 'xpcall'
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: <Newbie> Error when using IF statement.

Post by Positive07 »

= is meant for assignment, use == for comparison

Code: Select all

function love.load()
   pj = 0
   px = 30 -- Start Pos
   py = 60 -- Start Pos
   phygrav = 0.50  -- Gravity Pull
   phyground = 61  -- Ground Location
   pgraphic = love.graphics.newImage("p_graphic.bmp")

end

function love.update(dt)
   if love.keyboard.isDown("a") then
   px = px - 0.70
   elseif love.keyboard.isDown("d") then
   px = px + 0.70
   elseif love.keyboard.isDown("w") then
   print "jump attempt"
      if pj == 0 then   <------------ Solution Here
         py = py - 6
         pj = 1
      end
   end
   
   if py < 60 then
      py = py - phygrav
   elseif py >= 60 then
      pj = 0
   end
   
   
end

function love.draw()
love.graphics.draw(pgraphic, px, py)
end
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Mapyo
Prole
Posts: 3
Joined: Sun Jan 29, 2017 7:29 am

Re: <Newbie> Error when using IF statement.

Post by Mapyo »

Thank's so much!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests