ents.Create problem main.lua:11: attempt to index global 'ents' (a nill value)

Issue #1067 invalid
Naythan Ramos
created an issue

I'm new to lua and really just game development in general and so I was making a box entity and the command that I put into the function love.load () ,which was ents.Create, to spawn the entity into the game. However, when I then try to load it it says: Error main.lua:11: attempt to index global 'ents' (a nill value)

traceback

main.lua:11: in function 'load' [C]: in function 'xpcall'

Comments (4)

  1. Denis Karabaza

    This is not an issue with love, so you should close this.

    There's so much wrong with the attached files it's even hard to find where to start from. I suggest you to start over and take small steps, making sure that on every step your code compiles and works as expected. Also you should probably use forum for asking questions, and not the issue tracker.

    1. Make sure there's only one definition for every function. In your code love.load is defined two times, so second time overrides the first one, which causes entities.lua to never be required.
    2. It's recommended against to use global variables. Globals are convenient at first, but they will bite you in the butt in a long run. In Lua you can return value from a module (lua file), and this value will be returned as result of require(...).
    3. In Lua tables are defined as { ... } and not ( ... ).
    4. You should indent your code, it will help you to locate logical errors. Specifically, conditional statements inside ents.create in the entities.lua are not closed properly, and probably don't do what you think they do.
    5. Lua (as most of other programming languages) is case sensitive. This means that startup is different from Startup.
  2. Log in to comment