Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:30:13+00:00 2026-06-01T20:30:13+00:00

Edit I got this working, I’m not sure if this is the right way

  • 0

Edit I got this working, I’m not sure if this is the right way to do it, but this is what works right now

I just started learning Lua, and I’m trying to figure out how to pass tables between files so that I can have a more organized codespace. I have read through the book Programming in Lua, and for some reason, I can’t figure out what i’m doing wrong.

The problem i’m getting is this error:

lua: Test2.lua:3: attempt to call method ‘New’ (a nil value)

From this code:

--Test.lua----------------
module("Test", package.seeall)
vector = require "./Hump/vector"

Bot = {}

Bot.position  =  vector.new(0,0)

function Bot:New(object)
    object = object or {}
    setmetatable(object, self)
    self.__index = self
    return object
end


--Test2.lua------------------
require "Test"

Bot1 = Test.Bot:New()

print(Bot1.position)

As far as I understand it, this error means that it cannot find the method new, it is effectively undefined. I thought that require imports the file in the path?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:30:15+00:00Added an answer on June 1, 2026 at 8:30 pm

    Bot is an empty table.

    local B = {} -- initialize local B with new table
    Bot = B -- Bot now references the same table as B
    
    B = { position = vector.new(0,0) } -- here you create a NEW table, B ~= Bot now
    
    function B:New(object) -- store New function in B table, Bot still empty
    

    So you’re returning an empty table.

    No need for two variables here at all.

    local Bot = {
        -- stuff
    }
    
    function Bot:New(object)
        -- stuff
    end
    
    return Bot
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I got this working now. I have updated the code: I've looked at
I got this article for doing this but i found that this is not
EDIT: I got it working it just won't download anything... So here is my
I've finally got this PHP email script working (didn't work on localhost…), but my
EDIT: This got way too complicated, I will migrate this question to another question
I've got to edit an XSLT stylesheet, but I'm flying blind because the XML
Could someone point me in the right direction here? Basically, I've got this jQuery
So, I got this error Couldn't find MenuBar with ID=add_page_to_menu But my code for
I had this working to spec, until the specs changed. This function is now
ok so i've nearly got this. But it seems there is some logic error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.