Facebook instant games function
fbinstant.get_context()
allways returns nil.
Is it bug or I do something wrong?
Facebook instant games function
fbinstant.get_context()
allways returns nil.
Is it bug or I do something wrong?
fbinstant.get_context() will get the current context.
If the context id (string) or context type (string) does not exist, it will return nil.
Maybe share some code so we can see what’s going on?
Have you called fbinstant.start_game() before calling fbinstant.get_context()?
Also, the Facebook Instant Games documentation mentions this in regard to the context:
“A unique identifier for the current game context. This represents a specific context that the game is being played in (for example, a particular messenger conversation or facebook post). The identifier will be null if game is being played in a solo context. This function should not be called until FBInstant.startGameAsync has resolved.”
Looks like my case, my context is solo.
Many thanks.
You should still get type “SOLO”:
local context_id, context_type = fbinstant.get_context()
print(context_id) -- nil if SOLO
print(context_type) -- should be fbinstant.CONTEXT_SOLO, ie string "SOLO"
In my case
local context_id, context_type = fbinstant.get_context()
print(context_id) -- nil
print(context_type) -- nil
Is something wrong?
Can you please share your code? And please ensure that you’ve called fbinstant.initialize() and fbinstant.start_game() before calling fbinstant.get_context().
JavaScript code for html page:
// Set up a progress listener and feed progress to FBInstant
Progress.updateProgress = function (percentage, text) {
FBInstant.setLoadingProgress(percentage);
}
FBInstant.initializeAsync().then(function()
{
FBInstant.startGameAsync().then(function()
{
var playerID = FBInstant.player.getID();
var playerName = FBInstant.player.getName();
// This will be checked by the FBInstant Defold extension
Module._fbinstant_inited = true;
});
// Start the instant game
var extra_params = {
archive_location_filter: function( path ) {
return ("archive" + path + "");
},
engine_arguments: ["--verify-graphics-calls=false"],
splash_image: "splash_image.png",
custom_heap_size: 268435456
}
Module.runApp("canvas", extra_params);
});
Lua code
function init(self)
-- ...
check_context(self)
end
function check_context(self)
-- check game state
fbinstant.start_game(function (self, success)
if success then
local context_id, context_type = fbinstant.get_context()
print(context_id)
print(context_type)
end
end)
end
Hmm, could you try this index.html:
And then this snippet of code in your script:
Can you help with the same problem?
Can you share the code where you initialise the sdk, call start and then get the context?
index.html is the same. Just copied from github
and in my script
fbinstant.initialize(function(self, success)
fbinstant.start_game(function(self, success)
local player_id = fbinstant.get_player().id
local player_name = fbinstant.get_player().name
local context_id, context_type = fbinstant.get_context()
print(context_type)
end)
end)
Do you see any errors in the console? Is the success variable true?
Sorry for waiting. Success is true, there is no errors
Type isn’t nil when i launch game from messenger.
Oh, you didn’t mention this before. So when is it nil? When you test locally? And if so, how exactly do you test?
Nil from main page of instant games
Well, that’s not very surprising. If you’re in no chat context at all then it should return nil. But now that I think of it the type should be SOLO. There’s probably a bug there. Let me take a look.
I’ve released a new version where get_context() returns a type (SOLO) in those instances when context is nil (typically when launching game from facebook.com/instantgames before changing into a chat context.