defold / extension-iac

Inter-app communication extension for Defold
MIT License
5 stars 7 forks source link

Can't get IAC started? #8

Closed dmathijs closed 1 year ago

dmathijs commented 1 year ago

Hey,

I'm currently trying out defold & lua for the first time. I'm planning on building a project and wanted to give defold a try. Before doing anything I wanted to validate that I could get IAC working. However, as a total noob, I can't get it to work although I feel like I've followed the docs.

Currently I've imported the zip as a dependency and it shows up in my Asset tree, when I set the main.script code to

local function iac_listener(self, payload, type)
    if type == iac.TYPE_INVOCATION then
        -- This was an invocation
        print(payload.origin) -- origin may be empty string if it could not be resolved
        print(payload.url)
    end
end

function init(self)
    iac.set_listener(iac_listener)
end

I get an exception

ERROR:SCRIPT: main/main.script:10: attempt to index global 'iac' (a nil value)
stack traceback:
  main/main.script:10: in function <main/main.script:9>

Again, this is probably because I am a starter but could anyone give me a pointer how to get this working? I would also like to update the documentation so that it is a little friendlier to other starters like me.

JCash commented 1 year ago

attempt to index global 'iac' (a nil value)

This likely means you're trying to 1) run it using a platform that doesn't support it, or 2) running a vanilla engine.

The iacmodule is currently only supported on iOS and Android. In your case, I suspect you're running it on a desktop platform?

You can check for the availability at runtime like so:

if iac then
    ... do stuff with iac
end
dmathijs commented 1 year ago

Thank you, that makes a lot of sense. I wasn't aware that running it in the desktop version would throw this error. Would you like me to open a PR with an addition to the docs to note this, or is it intrinsically implied?

JCash commented 1 year ago

I think there's no need, as it's implied as you mention, since many of these platform specific extensions simply doesn't work on the "wrong platform".

Checking for nil is our recommended way of checking for availability.