Im trying to use a export for seeing if the interaction menu is open on client side from a different resource but no matter what I do nothing is working for the export to be defined. I mostly code in js for everything but i was thinking the client side exports weren’t working for some reason so I made a export in my lua resource that I have to convert some lua resources to js and the export still isn’t working
//The error im getting
TypeError: Cannot read properties of undefined (reading 'checkNativeUiOpen')
//Here is the place where im trying to use the checking
if (IsControlJustPressed(0, 244) && exports.lua2js.checkNativeUiOpen() == true) {
//Here is what I was trying to do on js
global.exports('checkNativeUiOpen', () => { // Added global to see if it would work but didnt
if (varObj.nativeui.intmenuOpened || varObj.nativeui.outfitCreatorOpened) {
return true;
} else {
return false;
}
});
The lua export I also tried
exports("checkNativeUiOpen", function()
if varObj.nativeui.intmenuOpened or varObj.nativeui.outfitCreatorOpened then
return true
else
return false
end
end)
Note that these exports will only be available after the first scheduler tick.
(Scripting in Lua - Cfx.re Docs)
This is probably why they don’t work, idk how they are handled in the js runtime.
Thanks but i got it figured out this morning. Turns out it was just the way i was compiling my typescript and it was using export as a variable
I was just having a very similar issue.
I’m building my resources in TS and bundling them with webpack. It turns out Webpack does treat exports as an object, which it declares when it compiles. I found a workaround tho, and I hope this helps to anyone looking for asnwers:
It’s as simple, as instead of using exports("name", function)
, to use global.exports("name", function)
.
Same applies for the resource accesing the export, where you can call it by using global.exports.resourceName.function()
.
As an accesory to this, for anyone wondering how to type them and share types between resources, just create a types folder (I recommend at the root of resources), name it index.d.ts, and add it to the types array of the tsconfig.json.
It’s here that you can also add the following lines to type your exports:
interface CitizenExports {
(exportKey: string | number, exportFunction: Function): void;
[resourceName: string]: {
[exportKey: string | number]: Function;
};
yourResourceName: {
yourExportedFunction: (example: number) => string;
};
}
declare var exports: CitizenExports;
Sadly, for this to work you need to commit a crime:
Go to node_modules/@citizenfx/[client and server]/index.d.td and remove the lines you just saw from the files.