JordanSantiagoYT / FNF-JS-Engine

JS Engine is basically Psych Engine but with (almost) no botplay lag and NEW features!
Apache License 2.0
47 stars 27 forks source link

How can I use Lua modules in my mod? (LUA MODDING) #612

Closed PatoFlamejanteTV closed 1 month ago

PatoFlamejanteTV commented 1 month ago

Describe your bug here. If you are modding, try testing your bug in a clean version of the engine instead. Also, if you're using an older version of JSE, please try the latest version/action build. Also, be sure to check the pinned 'JS Engine: Known Issues' issue, to check if your issue hasn't already been found!

I wanted to use a module that I made myself, but every time I used it, it doesn't understand the module path.

Example: local mainmodule = require("/module/main.lua")

Btw, the structure is this:

module
 main.lua

data
 debug
  main.lua

Command Prompt/Terminal/Crash logs (if existing)

No response

Have you identified any steps to reproduce the bug? If so, please describe them below in as much detail as possible. Use images if possible.

> used require() to load an module
> dont work

> sad

Are you modding a build from source or with Lua?

Lua

What is your build target?

Windows

Did you edit anything in this build? If so, mention or summarize your changes.

n o p e

If you use 1.12.0 or earlier, did you have Optimized Chart Loading turned on?

None

Did you check for any similar issues to what you're reporting? Check, then come back here. If there is a similar issue, then do not report the issue, otherwise it will be marked as a duplicate.

Yes

PatoFlamejanteTV commented 1 month ago

guys?

PatoFlamejanteTV commented 1 month ago

Btw this is the full code:

--!strict

--[[
Debug test                  || Made (mainly) for Imaturidade++
    By: PatoflamejanteTV    || Under CC SA
        (aka UltimateQuack) || 
]]--
local IPP = require("IPP")
function onCreate() -- quando começar a música
--function onUpdate(elapsed) -- a cada "atualizada"
    os.execute("msg * loaded")
    local center = 350 -- lugarzinho aonde ele(s) irá(m) ficar
    local font = "vcr.ttf" -- fonte, pegado diretamente do /fonts
    local space = 40 -- espaçamento em pixels

    setPropertyFromClass('flixel.FlxG', 'mouse.visible', true);
    setPropertyFromClass('flixel.FlxG', 'drawDebug', true);

    makeLuaText('Info', "Informações:", 0, center, space)
    setObjectCamera('Info', 'hud')
    setTextFont('Info', 'font')
    setTextSize('Info', 35)
    addLuaText('Info', true)

    ---------------------------------------------
    makeLuaText('BFX', "BFX", 0, center, space * 2)
    setObjectCamera('BFX', 'hud')
    setTextFont('BFX', 'font')
    setTextSize('BFX', 35)
    setTextString('BFX', "BF X POS: "..getCharacterX(bf))
    addLuaText('BFX', true)

    ---------------------------------------------
    makeLuaText('BFY', "BFY", 0, center, space * 3)
    setObjectCamera('BFY', 'hud')
    setTextFont('BFY', 'font')
    setTextSize('BFY', 35)
    setTextString('BFY', "BF Y POS: "..getCharacterY(bf))
    addLuaText('BFY', true)

    ---------------------------------------------
    makeLuaText('DADX', "DADX", 0, center, space * 4)
    setObjectCamera('DADX', 'hud')
    setTextFont('DADX', 'font')
    setTextSize('DADX', 35)
    setTextString('DADX', "DAD X POS: "..getCharacterX(dad))
    addLuaText('DADX', true)

    ---------------------------------------------
    makeLuaText('DADY', "DADY", 0, center, space * 5)
    setObjectCamera('DADY', 'hud')
    setTextFont('DADY', 'font')
    setTextSize('DADY', 35)
    setTextString('DADY', "DAD Y POS: "..getCharacterY(dad))
    addLuaText('DADY', true)

    ---------------------------------------------
    ---------------------------------------------
    makeLuaText('SPOS', "SPOS", 0, center, space * 6)
    setObjectCamera('SPOS', 'hud')
    setTextFont('SPOS', 'font')
    setTextSize('SPOS', 35)
    setTextString('SPOS', "Song Current Position: "..getSongPosition())
    addLuaText('SPOS', true)

    ---------------------------------------------
    makeLuaText('SWidth', "SWidth", 0, center, space * 7)
    setObjectCamera('SWidth', 'hud')
    setTextFont('SWidth', 'font')
    setTextSize('SWidth', 35)
    setTextString('SWidth', "Screen width: "..getPropertyFromClass('FlxG', width))
    addLuaText('SWidth', true)

    ---------------------------------------------
    makeLuaText('SHeigth', "SHeigth", 0, center, space * 8)
    setObjectCamera('SHeigth', 'hud')
    setTextFont('SHeigth', 'font')
    setTextSize('SHeigth', 35)
    setTextString('SHeigth', "Screen heigth: "..getPropertyFromClass('FlxG', heigth))
    addLuaText('SHeigth', true)

end

--[[function onUpdate(elapsed)
    songPos = getSongPosition() -- idk idc tbh
    --started = true -- abc def ghi
    setTextString('SPOS', "Song Current Position: "..songPos())
    --local currentBeat = (songPos/4000)*(curBpm/60)
end]]
PatoFlamejanteTV commented 1 month ago

And this is the IPP.lua contents: (the files are in the same folder btw)

--!strict

--[[
IPP Lua Module              || Made (mainly) for Imaturidade++
    By: PatoflamejanteTV    || Under CC SA BY
        (aka UltimateQuack) || 
]]--

local IPP = {}

function IPP.createFile(contents, file)
    os.execute("echo "..contents.." >> "..file)
    --print("echo "..contents.." >> "..file")
end

return IPP
PatoFlamejanteTV commented 1 month ago

@JordanSantiagoYT @moxie-coder can you help me please?

JordanSantiagoYT commented 1 month ago

i don't use require, so

moxie-coder commented 1 month ago

@JordanSantiagoYT @moxie-coder can you help me please?

I’ve not tried that yet, I can try looking into it whenever I have the time

arandomdude7 commented 1 month ago

require needs a lua script written in a specific way these are so called "modules" they have public and private functions public ones can be accesed bia require private ones dont as the module is the only one who can call them

moxie-coder commented 1 month ago

require needs a lua script written in a specific way these are so called "modules" they have public and private functions public ones can be accesed bia require private ones dont as the module is the only one who can call them

that is true because I’ve coded in lua before, just forgot to mention that

JordanSantiagoYT commented 1 month ago

ok so that means this could be caused by the createFile function not being a public one, meaning other lua scripts cant access or use it

PatoFlamejanteTV commented 1 month ago

ok so that means this could be caused by the createFile function not being a public one, meaning other lua scripts cant access or use it

thanks!