Attempt to perform arithmetic on global?

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
Willham321
Prole
Posts: 3
Joined: Thu Apr 03, 2014 12:01 am

Attempt to perform arithmetic on global?

Post by Willham321 »

Attempt to perform arithmetic on global. What does this mean?
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Attempt to perform arithmetic on global?

Post 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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Attempt to perform arithmetic on global?

Post 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.
Willham321
Prole
Posts: 3
Joined: Thu Apr 03, 2014 12:01 am

Re: Attempt to perform arithmetic on global?

Post 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
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Attempt to perform arithmetic on global?

Post 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.
Willham321
Prole
Posts: 3
Joined: Thu Apr 03, 2014 12:01 am

Re: Attempt to perform arithmetic on global?

Post by Willham321 »

My whole idea on how to make a jumping function is broken any ideas/advise?
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 4 guests