Importing Lua modules in TPT

  • zicronium42
    10th April Member 0 Permalink

    I've been trying to do this stuff for a while now...but no use. The only thing it shows when trying to import another module is:

    lua/<import_module>.lua:4: attempt to index local '<export_module>' (a boolean value)


    Any suggestions on how to fix this??

  • LBPHacker
    10th April Developer 0 Permalink
    If it's not failing inside require, then your module is returning a boolean instead of something indexable. Most likely it returns nothing, in which case Lua defaults its return value to true.
    Edited once by LBPHacker. Last: 10th April
  • zicronium42
    10th April Member 0 Permalink

    @LBPHacker (View Post)

     



    _G.interf = {}
    local testWindow = Window:new(-1, -1, 100, 100)

    local currentY = 10


    local box = function(px, py, length, breadth)
        sim.createWallLine(px, py, px + breadth, py, 1)
        sim.createWallLine(px, py, px, py + length, 1)
        sim.createWallLine(px + breadth, py, px + breadth, py + length, 1)
        sim.createWallLine(px, py + length, px + breadth, py + length, 1)
    end
    local wx, wy

    local testTextbox1 = Textbox:new(10, currentY, (select(1, testWindow:size()) / 2) - 20, 16, "", "[place text here]")
    testTextbox1:onTextChanged(
        function(sender)
            wx = tonumber(sender:text())
        end
    )
    currentY = currentY + 20
    local testTextbox2 = Textbox:new(10, currentY + 20, (select(1, testWindow:size()) / 2) - 20, 16, "", "[place text here]")
    testTextbox2:onTextChanged(
        function(sender)
            wy = tonumber(sender:text())
        end
    )


    local enter = Button:new(10, select(2, testWindow:size()) - 26, 100, 16, "Enter")

    enter:action(function()
        box(50, 50, wx, wy)
        interface.closeWindow(testWindow)
    end)

    return interf
     
    This is the code I'm tryina run, basically it's functions from another module which goes like this:
     
    local interf = require "interface"

    for key, value in pairs(interf) do
        print(key .. value)
    end
     

    But prints nothing... :/
    Edited once by zicronium42. Last: 10th April
  • LBPHacker
    10th April Developer 0 Permalink
    "prints nothing" is not the same as "lua/.lua:4: attempt to index local '' (a boolean value)". Please try to be consistent. The code prints nothing because you put nothing in that table.

    Also, please don't crap all over _G. Use a local and return it.
    Edited once by LBPHacker. Last: 10th April
  • zicronium42
    10th April Member 0 Permalink

    @LBPHacker (View Post)

     Alright...thank you