Page 1 of 1

Error: attempt to index field 'connected_sticks' (a nil value)

Posted: Wed Mar 27, 2019 5:52 am
by sadsadpartydad
Hi guys, first post jitters. I'm preparing to start designing my own game but to start I figured a refresher on the framework of LOVE and Lua syntax was was a definite need. So I started following a tutorial by recursor: https://www.youtube.com/watch?v=EQL6HZm ... B&index=13

I have my tutorial.love file attached, and as you can see, I followed his tutorial almost identically. His code for the episode is on hit github here: https://github.com/bncastle/love2d-tuto ... /Episode12

Note: His video is from May of 2017, which is quite a few versions behind what I am using. I am using Love2d 11.2. I have worked around this for the most part.

In my GamepadManager.lua file, I have an empty table called self.connected_sticks, which holds the key as joystick:getID() and the value as the joystick object itself. The class uses functions which check if the joystick with the given ID in the table presses buttons, exists, etc.

I am using a SNES gamepad from INEXXT for input, so to make sure the SDL mappings are correct and the program recognizes the button presses, I have the following line in main.lua > function love.draw()

Code: Select all

love.graphics.print(tostring(GPM:button(1, "a"),70,10))
The error I receive from the compiler is here:

Code: Select all

Error

lib/GamepadManager.lua:93: attempt to index field 'connected_sticks' (a nil value)


Traceback

lib/GamepadManager.lua:93: in function 'button'
main.lua:84: in function 'draw'
[C]: in function 'xpcall'
I tried to print to console print(type(gpm.connected_sticks)) immediately after it was initialized both in GamepadManager.lua and after gpm was initialized in main.lua which both return "table". The value of the variable itself is replaced with nil sometime from initialization and calling the method. I don't think it is the garbage collector, because the table is still being referenced by the pointer.

Any help will be useful. I plan to use the forums and the rest of the tutorials to make my own library and 2d Smash Bros. style game for Love on the RetroPie. Cheers.
tutorial.love
(1.72 MiB) Downloaded 138 times

Re: Error: attempt to index field 'connected_sticks' (a nil value)

Posted: Wed Mar 27, 2019 11:09 am
by grump
Welcome!

main.lua line 84 says GPM:button, but you probably meant to write gpm:button.