TIC-80
TIC-80 copied to clipboard
Moonscript modules
I have a project where I'm trying to make custom text! and textb! functions for drawing text with shadows and drawing text in boxes. I was trying to make modules for this job, researched how to make them, and then made a test module. I then made a project trying to require! the test module, but it didn't work. Here's some code overview of the problem:
File makeup:
[bunny]
...
[cart]
...
[projects]
...
[tests]
companion.tic
fruity.tic
[tic80.com]
...
demo carts...
Companion:
require "fruity"
fruity.printAFruit 3
export TIC = -> --just here for the ''function TIC...' isn't found :(' error
Fruity:
printAFruit (n) = ->
a = {"apple","pear","banana","strawberry","orange"}
a[n]--implicit return
export TIC = →
fruity = {:printAFruit}
fruity
I tried different versions of the require! function (require "fruity", require "tests.fruity", require "/tests/fruity",require "/tests/fruity.tic",require "tests/fruity", etc.), but nothing worked. It just gave this error:
[string "moonscript.lua"]:5401:attempt to index a nil value (global `io`)
Maybe it has to do with being unable to save things as .moon and only being able to save as .tic. Also, I'm on browser.
TIC doesn't support functions like require, you have to write the code in one file.
@100xCode there are also several bundling tools that you can integrate in your workflow: https://github.com/nesbox/TIC-80/wiki/tools#bundling
Closing as asked and answered by nesbox.
Worth noting this might technically be possible in Moonscript - since it's just interpreted at runtime by Lua... so you could come up with a custom build system that wrote all your source into a huge blob... and then hack moonscript to supply your own "require" function that knows how to retrieve files from your huge binary blob... but that's a bit out of scope. :-)
Your cartridge might then technically be a Lua cartridge though.