Page 1 of 1

Attempt to perform arithmetic on global?

Posted: Thu Apr 03, 2014 12:04 am
by Willham321
Attempt to perform arithmetic on global. What does this mean?

Re: Attempt to perform arithmetic on global?

Posted: Thu Apr 03, 2014 1:18 am
by davisdude
Well, I would have to get more information. Right now, I can only tell you what must be pretty obvious: it tried (and failed) to perform arithmetic (math) on a global (value). Basically, that means one of your numbers is in fact, not a number.

Re: Attempt to perform arithmetic on global?

Posted: Thu Apr 03, 2014 1:31 am
by Jasoco
What davisdude said. Also, if you're sure one of the values is a number, but is in string form, i.e. "13" instead of 13, use tonumber to convert it first.

Re: Attempt to perform arithmetic on global?

Posted: Thu Apr 03, 2014 1:53 am
by Willham321
Check this code out and see what you can figure out.

Code: Select all

function love.load()
	love.graphics.setBackgroundColor( 255, 255, 255 )
	am2 = 100
	am = 100
	xam1 = 100
	xam2 = 100
	charecter = {400,550,100}
	speed = 100
	
end

function love.draw()
	love.graphics.setColor(255,0,0,255)
love.graphics.rectangle("fill",charecter[1],charecter[2],50,50)
end

function love.update(dt)

if love.keyboard.isDown("d") then 
charecter[1] = charecter[1] + 500*dt
	end
	if love.keyboard.isDown("a") then
		charecter[2] = charecter[1] - 500*dt
	end
	if love.keyboard.isDown(" ") then
		charecter[2]=op
charecter[2]=charecter[2] - 100*dt
if charecter[2] == op+10 then
	charecter[2] = charecter[2] + 100*dt
end
end


if love.keyboard.isDown(" ")then
pics()
end
end
function love.focus(bool)
end

function love.keypressed( key, unicode )
end

function love.keyreleased( key, unicode )
end

function love.mousepressed( x, y, button )
end

function love.mousereleased( x, y, button )
end

function love.quit()
end
function pics(dt)
	--pics physics engine was made for the Rise Of The weak
	if charecter[2]<550 then
		print("Physics engine now running")
		while charecter[2]<550 do 
			charecter[2] = charecter[2] + 300*dt
		end
	end
end
function movement(key,dt)
	if key == "d" then 
charecter[2] = charecter[1] + 500*dt
	end
	if key == "a" then
		charecter[2] = charecter[1] - 500*dt
	end
	if key == "space" then
		charecter[2]=op
charecter[2]=charecter[2] - 100*dt
if charecter[2] == op+10 then
	charecter[2] = charecter[2] + 100*dt
end
end
endfunction love.load()
	love.graphics.setBackgroundColor( 255, 255, 255 )
	am2 = 100
	am = 100
	xam1 = 100
	xam2 = 100
	charecter = {400,550,100}
	speed = 100
	
end

function love.draw()
	love.graphics.setColor(255,0,0,255)
love.graphics.rectangle("fill",charecter[1],charecter[2],50,50)
end

function love.update(dt)

if love.keyboard.isDown("d") then 
charecter[1] = charecter[1] + 500*dt
	end
	if love.keyboard.isDown("a") then
		charecter[2] = charecter[1] - 500*dt
	end
	if love.keyboard.isDown(" ") then
		charecter[2]=op
charecter[2]=charecter[2] - 100*dt
if charecter[2] == op+10 then
	charecter[2] = charecter[2] + 100*dt
end
end


if love.keyboard.isDown(" ")then
pics()
end
end
function love.focus(bool)
end

function love.keypressed( key, unicode )
end

function love.keyreleased( key, unicode )
end

function love.mousepressed( x, y, button )
end

function love.mousereleased( x, y, button )
end

function love.quit()
end
function pics(dt)
	--pics physics engine was made for the Rise Of The weak
	if charecter[2]<550 then
		print("Physics engine now running")
		while charecter[2]<550 do 
			charecter[2] = charecter[2] + 300*dt
		end
	end
end
function movement(key,dt)
	if key == "d" then 
charecter[2] = charecter[1] + 500*dt
	end
	if key == "a" then
		charecter[2] = charecter[1] - 500*dt
	end
	if key == "space" then
		charecter[2]=op
charecter[2]=charecter[2] - 100*dt
if charecter[2] == op+10 then
	charecter[2] = charecter[2] + 100*dt
end
end
end

Re: Attempt to perform arithmetic on global?

Posted: Thu Apr 03, 2014 2:01 am
by Jasoco
Well first off, you don't define op. So since op is not defined, it's nil. nil is not a number. So therefore trying to add it to another number is going to fail.

By the way, if you intend on using dt in another function you need to pass it along through the function. You forgot to with the pics() function.

Re: Attempt to perform arithmetic on global?

Posted: Thu Apr 03, 2014 2:47 am
by Willham321
My whole idea on how to make a jumping function is broken any ideas/advise?