Variable becomes nil after passing it to another function

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
ward614
Prole
Posts: 9
Joined: Sat Feb 22, 2020 7:09 pm

Variable becomes nil after passing it to another function

Post by ward614 »

Hello!

I am new to LOVE and Lua, and am in the process of trying to make a basic pong game to learn more and improve my skills. I have found myself stuck with a recent issue, however. My file is attached and you can see the whole thing at https://pastebin.com/APd0FuVz. The specific functions are below:

Code: Select all

function room:update(dt)
  
  for i = #self.game_objects, 1, -1 do
    active_object = self.game_objects[i]
    active_object:update(dt)
    
  if self.detectOutOfBounds(active_object) then active_object:collision() end
    
  end
  
end
and

Code: Select all

function room:detectOutOfBounds(active_object)

  local aw, ah = active_object:getSize()
    
  return active_object.x > (love.graphics.getWidth() + aw) and
  active_object.y > (love.graphics.getHeight() + ah) and
  active_object.x < 0 and
  active_object.y < 0
  
end
My current issue is that in the function "detectOutOfBounds" the first line returns the error that "active_object" is nil. I have been stuck on this as it appears to have value when checked in the "update" function just before "detectOutOfBounds" is called. I suspect that the issue is something really simple, but I would greatly appreciate any help or advice you could offer!

Thank you!
Attachments
room.lua
(1.19 KiB) Downloaded 185 times
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Variable becomes nil after passing it to another function

Post by raidho36 »

You didn't use the colon notation when you called the detection function.

It's a bit complicated subject but the gist of it is that colon notation definition expects colon notation usage, same with dot notation.
ward614
Prole
Posts: 9
Joined: Sat Feb 22, 2020 7:09 pm

Re: Variable becomes nil after passing it to another function

Post by ward614 »

Thank you so much! I know it was something really simple I was missing, but I just couldn't see it!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 73 guests