Attempt to perform arithmetic on global?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 3
- Joined: Thu Apr 03, 2014 12:01 am
Attempt to perform arithmetic on global?
Attempt to perform arithmetic on global. What does this mean?
Re: Attempt to perform arithmetic on global?
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
- 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?
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.
-
- Prole
- Posts: 3
- Joined: Thu Apr 03, 2014 12:01 am
Re: Attempt to perform arithmetic on global?
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
- 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?
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.
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.
-
- Prole
- Posts: 3
- Joined: Thu Apr 03, 2014 12:01 am
Re: Attempt to perform arithmetic on global?
My whole idea on how to make a jumping function is broken any ideas/advise?
Who is online
Users browsing this forum: Bing [Bot] and 8 guests