On_build_started hook errors (SOLVED)

I’m trying to write an editor hook for the on_build_started event.

The code from https://defold.com/manuals/editor-scripts/ gives an error:

/hooks.editor_script
hook "on_build_started" in /hooks.editor_script failed:

Wrong number of args (1) passed to: editor.editor-extensions/do-ext-get

I’ve only been able to find a couple of other examples and they also get this error.

I tried looking at the editor source but I’m not familiar with Clojure.

This is in version 1.2.180 of the editor. Any assistance would be greatly appreciated!

I tried this myself. I created a hooks.editor_script in the project root with this content:

local M = {}

local function write(filename, data)
    local file = io.open(filename, "a")
    file:write(data .. "\n")
    file:flush()
    file:close()
end

function M.on_build_started(opts)
    write("build.txt", "on_build_started")
end

function M.on_build_finished(opts)
    write("build.txt", "on_build_finished")
end

function M.on_bundle_started(opts)
    write("build.txt", "on_bundle_started")
end

function M.on_bundle_finished(opts)
    write("build.txt", "on_bundle_finished")
end

function M.on_target_launched(opts)
    write("build.txt", "on_target_launched")
end

function M.on_target_terminated(opts)
    write("build.txt", "on_target_terminated")
end

return M

I then chose Project->Reload Editor Scripts and did Project->Build. After the project was started and then shut down I inspected the created build.txt:

on_build_started
on_build_finished
on_target_launched
on_target_terminated

As far as I can tell it all checks out, at least on macOS. Can you try to follow my steps described above?

So this is odd. I started up the editor this morning, pasted in your script and it worked! huzzah! Then I pasted in the sample code from the docs, and it also worked.

I think the error I was seeing was a stale error message related to an earlier experiment with the on_build_started method where I was incorrectly calling editor.get with a single parameter.

Thanks for your help!

1 Like