defold / extension-fbinstant

Facebook Instant Games extension for the Defold game engine
https://defold.com/extension-fbinstant/
MIT License
38 stars 20 forks source link

fbinstant.log_event() fails if optional value(s) are omitted #76

Closed totebo closed 4 years ago

totebo commented 4 years ago

If "value_to_sum" or "parameters" are omitted the operation fails.

These parameters are optional in the JavaScript version of the API: https://developers.facebook.com/docs/games/instant-games/sdk/fbinstant6.0

britzl commented 4 years ago

Here's a PR that handles if value_to_sum is nil: https://github.com/defold/extension-fbinstant/pull/78

Please give it a try and let me know if it works as expected!

totebo commented 4 years ago

Both valueToSum and parameters can be omitted in the Facebook API. It looks like 0 is sent if valueToSum is nil now? Would be good to just be able to go:

fbinstant.log_event( "Kick" )

And the only thing sent is the "Kick" event id?

totebo commented 4 years ago

Back on this, and can confirm it still fails silently if "value_to_sum" or "parameters" are omitted:

fbinstant.log_event("event_name", 0, '{"parameter":0}') -- Works

fbinstant.log_event("event_name", 0, nil) -- Fails silently
fbinstant.log_event("event_name", nil, '{"parameter":0}') -- Fails silently
fbinstant.log_event("event_name", nil, nil) -- Fails silently

Expected behaviour: If one or both of the optional values are nil the call should not fail.

britzl commented 4 years ago

I've added a check if value_to_sum is a number or not. Anything other than a number will be treated as 0. Would you mind testing this branch:

https://github.com/defold/extension-fbinstant/archive/dev-valuetosum_nil.zip

totebo commented 4 years ago

All of the examples above now work. Great job, thanks!