attempt to index global 'inputTimer' (a number value)

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
onedaysnotice
Citizen
Posts: 63
Joined: Sun May 13, 2012 2:49 am

attempt to index global 'inputTimer' (a number value)

Post by onedaysnotice »

I don't get what i did wrong, or how its different from what i did with the player table.. :S

this is the line:
inputTimer.r = inputTimer.r + dt

and the entire code:

Code: Select all

debug = true

function love.load()

   ground = {}
   ground.y = 550
   ground.w = love.graphics.getWidth()
   ground.h = love.graphics.getHeight() - ground.y

   player = {}
   player.y = 500
   player.x = 100
   player.w = 50
   player.h = 50
   player.b = player.y + player.h
   player.r = player.x + player.w
   player.y_vel_base = -(ground.y + player.h) 
   player.y_vel = player.y_vel_base
   player.x_vel = 200
   player.x_vel2 = player.x_vel*3
   player.state = {
      jumping = false,
      facing = "right",
      running = false,
   }

   gravity = 1000
   releasekey = "none"

   inputTimer = {
      l = 0,
      r = 0,
   }

   combo = {
      l = "false",
      r = "false",
   }

end

function love.update(dt)

   if love.keyboard.isDown("up") and player.state == "idle" then
      player.state.jumping = true
   end

   if player.state.jumping then
      player.y = player.y + player.y_vel * dt
      player.y_vel = player.y_vel + gravity * dt
      if player.y + player.h > ground.y then
         player.y = ground.y - player.h
         player.y_vel = player.y_vel_base
         player.state = "idle"
      end
   end

   if releasekey == "right" then
      inputTimer.r = inputTimer.r + dt
      if inputTimer.r < 0.3 then
         combo.r = "true"
      else 
         inputTimer = 0
         releasekey = "none"
         combo.r = "false"
      end
   end

   if love.keyboard.isDown("right") then
      player.x = player.x + player.x_vel * dt
      if combo.r == "true" and love.keyboard.isDown("right") then
         player.x = player.x + player.x_vel2 * dt
      else
         inputTimer = 0
      end
   end

   if releasekey == "left" then
      inputTimer.l = inputTimer.l + dt
      if inputTimer.l < 0.3 then
         combo.l = "true"
      else 
         inputTimer.l = 0
         releasekey = "none"
         combo.l = "false"
      end
   end

   if love.keyboard.isDown("left") then
      player.x = player.x - player.x_vel * dt
      if combo.l == "true" and love.keyboard.isDown("left") then
         player.x = player.x - player.x_vel2 * dt
      else
         inputTimer.l = 0
      end
   end

end

function love.draw()
   love.graphics.rectangle("fill",player.x,player.y,player.w,player.h)
   love.graphics.rectangle("fill",0,ground.y,ground.w,ground.h)
   if debug then
      --love.graphics.print("player state: " ..player.state,50,50,0,1,1)
      love.graphics.print("y: " ..player.y,200,50,0,1,1)
      love.graphics.print("x: " ..player.x,200,65,0,1,1)
      love.graphics.print("last key release: " ..releasekey,50,65,0,1,1)
      love.graphics.print("combo (r): " ..combo.r, 50,80,0,1,1)
      love.graphics.print("combo (l): " ..combo.l, 50,90,0,1,1)
   end
end

function love.keypressed(key)

end

function love.keyreleased(key)
   if key == "tab" then
      debug = not debug
   end

   if key == "right" then
      releasekey = "right"
   end

   if key == "left" then
      releasekey = "left"
   end

end
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: attempt to index global 'inputTimer' (a number value)

Post by Nixola »

You set several time "inputTimer" to 0, once in that same if and once in the if below
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Lynesth
Prole
Posts: 30
Joined: Sun May 16, 2010 8:47 am

Re: attempt to index global 'inputTimer' (a number value)

Post by Lynesth »

Hi :)

It seems that, at first glance, those lines are missing a little something that I'm sure you'll find :

Code: Select all

inputTimer = 0
;)

Edit : ninjaed :d
I'm always happy to be corrected if needed. I still have a lot to learn.
By the way, excuse my english.
onedaysnotice
Citizen
Posts: 63
Joined: Sun May 13, 2012 2:49 am

Re: attempt to index global 'inputTimer' (a number value)

Post by onedaysnotice »

@Nixola
Sorry, I didn't understand what you meant :S

@Lynesth
I tried adding inputTimer = 0 as well just in case but it didn't work

This issue only arises if make inputTimer a table, that is inputTimer = {l=0,r=0}. If i make it just a variable (inputTimer = 0) then it works fine :S
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: attempt to index global 'inputTimer' (a number value)

Post by Nixola »

The fact is, you're already setting inputTimer to 0 twice, once 4 lines below "inputTimer.r = iputTimer.r + dt", once 14 lines below the same line
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
onedaysnotice
Citizen
Posts: 63
Joined: Sun May 13, 2012 2:49 am

Re: attempt to index global 'inputTimer' (a number value)

Post by onedaysnotice »

Nixola wrote:The fact is, you're already setting inputTimer to 0 twice, once 4 lines below "inputTimer.r = iputTimer.r + dt", once 14 lines below the same line
oh I just realized what I did...=_= thank so much! xD added the .r's now :D
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests