Using a Lua module in a custom renderer

I would like to store information like render.get_window_width() so that scripts outside of the render script can access it. There are a few posts that suggest using a Lua module to hold this information. I’m trying to do this using the following line (which works in my other scripts):

require "scripts.renderer_helper";

The error I’m getting back is:

ERROR:SCRIPT: custom_render/custom.render_script:1: module 'renderer_helper' not found: no file 'renderer_helper'

How do I load a module in the render script? Or am I going about this the wrong way?

Can you double check that you have a file called renderer_helper.lua in the folder named scripts?

Below is a picture of my project structure:

I know Defold can see the renderer_helper.lua script because my input_test script is able to load and access the information inside. It seems like something different about the custom.render script works with require.

Could you please try and remove the semi-colon at the end of that line?

Darn it! My day job is C# coding so semicolons are transparent to me. Thanks for the help with catching that stupid mistake.

2 Likes

It’s actually not stupid. Semi-colons are not forbidden. In Lua you can use semi-colons to have multiple statements on a single line. On the other hand I wouldn’t say that it is encouraged and you will rarely see it used.

During our build process we scan all script files for require() statements to get a list of all *.lua files to include in the build, and it seems like that semi-colon confused our build tool.

2 Likes