Hi all,
Is there any way to use in javascript resources all the exported functions created in lua resources ?
Right now i’m not able to read those functions.
LUA file:
exports('stopSound', function(arguments)
local sound = {action = 'stopSound'}
SendNUIMessage(sound)
end)
fxmanifest:
exports {… ‘stopSound’ }
Another lua resource:
exports.sl_hud:stopSound() – WORKS
Javascript resource:
exports.sl_hud.stopSound() – FAILS ( can not read property ‘stopSound’ of undefined)
i did print the exports variable and is always empty object( {} )
Thank you!
=== EDIT ===
This wasn’t really a problem, i’m using webpack to transpile ts files into js, somehow that “exports” variable is not available from these transpiled scripts, don’t know why.
My solution is this:
I created a js resource like this:
on("exports:get", (resource, func, cb) => {
let funcs = {}
if( typeof func == 'object' && func.constructor === Array) {
for (let i of func) {
funcs[i] = exports[resource][i]
}
} else if (typeof func === 'string') {
funcs[func] = exports[resource][func]
}
cb(funcs)
})
In my ts file i just do this:
emit("exports:get", "sl_hud", ["visibility", "stopSound", "playSound", "seatBeltStatus"], (exports) => {
sl_hud_exports = exports
})
this way i can get all the exported functions of the sl_hud resource in this variable sl_hud_exports
i just do this: sl_hud_exports.visibility(…)
If someone knows how to avoid this workaround, please consider helping me
---------- EDIT ----------------
I found the solution in another post,
We can use the global variable [ global ]
Example:
global.exports.resource_name.functionname()
global.exports.sl_hud.functionname(...)