Page 1 of 1
Scripting: Implement 'require' module resolution
Posted: Fri Sep 05, 2025 4:42 am
by Jakob Hubbard
Currently my biggest gripe with the scripting so far is having to deal with all my scripts in one massive file, making it difficult to navigate and organize.
It's less noticeable with server-side scripting as you can just create multiple files and have them all in the server args, however it's still difficult to understand what files are dependent on each other if you don't have any module resolution for other files.
I've been doing some reading into Duktape, (for those who don't know it's the embedded Javascript engine sim uses to turn your js code into something the game can execute) and it looks like you'd have to manually implement some sort of handler for module resolution. [
Stack overflow question on the topic]
I've never personally worked with it so I'm not sure how difficult it would be but would be nice to see, especially if you plan on adding UI scripting.
Re: Scripting: Implement 'require' module resolution
Posted: Fri Sep 05, 2025 7:24 am
by ShortyMX
+1, but I feel like that would be a lot of work to get right.
Until then, you could probably write a config for
rollup, so anyone can write modern js with es6 features and then have it bundled into a single frills.js file
Re: Scripting: Implement 'require' module resolution
Posted: Sat Sep 06, 2025 2:41 am
by jlv
One file simplifies things for the checked js files. If I was doing something super complex I'd probably just use "make" and "cat" to combine the files.
Re: Scripting: Implement 'require' module resolution
Posted: Sat Sep 06, 2025 3:39 pm
by Jakob Hubbard
ShortyMX wrote: ↑Fri Sep 05, 2025 7:24 am
+1, but I feel like that would be a lot of work to get right.
Until then, you could probably write a config for
rollup, so anyone can write modern js with es6 features and then have it bundled into a single frills.js file
Rollup actually looks pretty sweet! Definitely will have a look into this!
Re: Scripting: Implement 'require' module resolution
Posted: Sat Sep 06, 2025 3:46 pm
by Jakob Hubbard
jlv wrote: ↑Sat Sep 06, 2025 2:41 am
One file simplifies things for the checked js files. If I was doing something super complex I'd probably just use "make" and "cat" to combine the files.
Is it not possible to have import logic that works relatively similar to loading a decal or statue? Something like
Code: Select all
require("@yourtrackname/files/js/othermodule.js")
Re: Scripting: Implement 'require' module resolution
Posted: Sun Sep 07, 2025 3:35 am
by jlv
Jakob Hubbard wrote: ↑Sat Sep 06, 2025 3:46 pm
Is it not possible to have import logic that works relatively similar to loading a decal or statue? Something like
Code: Select all
require("@yourtrackname/files/js/othermodule.js")
It'd be easy to do but I'd rather just have one file. I don't want to make more ways to get track mismatches.
Why not just use "cpp" or "cat" to join the files? Would "#include <something.js>" be that bad?
Re: Scripting: Implement 'require' module resolution
Posted: Mon Sep 08, 2025 2:40 pm
by Jakob Hubbard
jlv wrote: ↑Sun Sep 07, 2025 3:35 am
It'd be easy to do but I'd rather just have one file. I don't want to make more ways to get track mismatches.
Why not just use "cpp" or "cat" to join the files? Would "#include <something.js>" be that bad?
I understand your reasoning but it seems like a bit of an edge case as most people don't even use the nofrills.js file for scripting. Most just use the frills.js that isn't in the track checksum. If something fails along the way it would just halt execution of the script and wouldn't work for them.
It's not hard to concatenate the files, could write a batch script or use cpp like you said to do that. It's just something that would make the development cycle much more enjoyable for me since organizing imports and modules is something I'm very used to for work.