causes error (a nil value) (SOLVED)


Maybe someone can help me.

It’s strange, but when u try to run even simple code from example in manual, i have this error:
ERROR:SCRIPT: /main/ui.gui_script:3: attempt to index global ‘html5’ (a nil value)

in my file ui.gui_script i just call like this:

function init(self)
self.score = 0
local res =“10 + 20”)

Have I forgotten to include some library or something like this?

(i program it all on MacOS)



The module “Html5” works only if you build for Html5 target (“Build and run Html5” or bundle Html5)
Also, it’s useful to check availability none-cross-platform modules before using:

if html5 then
1 Like


Thank you, when i do “Build HTML” it goes without errors. but i still can’t get it, how i see the result of that code from example:

I understand that i can make javascript alert or something like that and see alert (i’ll still have to add in HTML after bulding from Defold).
But how does code from example shows result?



You are able to write javascript code as a string and call this code using

Executes the supplied string as JavaScript inside the browser. A call to this function is blocking, the result is returned as-is, as a string. (Internally this will execute the string using the eval() JavaScript function.)

For example:

	local result ="var a = 2+5; b = a + 2; b")

Also, it’s possible to write a javascript code right into index.html temlate in Module.
For example:
index.html template:


	Module["my_prefix_myCustomFunction"] = function(num)
		var a = num+5;
		b = a + num;
		return b;

Your lua codeLua:

	local num = 4
	local result ="Module.my_prefix_myCustomFunction("..num..")")


Thank you, now it looks clear. I’ll try this variant with javascript function, it should help.