Difference between revisions of "* Initialisation and Core"

From GiderosMobile
m (Text replacement - "</source" to "</syntaxhighlight")
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:* Initialisation and Core -->
 
<!-- GIDEROSOBJ:* Initialisation and Core -->
'''<translate>Supported platforms</translate>:''' [[File:Platform html5.png]]<br/>
+
'''Supported platforms:''' [[File:Platform html5.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2018.3<br/>
+
'''Available since:''' Gideros 2018.3<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
You need to do two things to target Facebook Instant Games:<br /><br />
+
You need to do two things to target Facebook Instant Games:
1. Tick the Facebook Instant Game tickbox when exporting to HTML5, you can also specify the percentage indicator that the game will show it has loaded before you take control.<br />
+
 
2. Require the FBInstant library code, see the example below.<br/>
+
# Tick the Facebook Instant Game tickbox when exporting to HTML5, you can also specify the percentage indicator that the game will show it has loaded before you take control
<br />
+
# Require the FBInstant library code, see the example below
You can upload, debug and test your game by creating a player and uploading to Facebook servers as a game.   The player will interact with the Gideros Studio similar to any other player.<br />
+
 
<br />
+
You can upload, debug and test your game by creating a player and uploading to Facebook servers as a game. The player will interact with the Gideros Studio similar to any other player.
The only restriction with the player is that it only works on the computer viewing the html5 game (localhost) - this would normally rule out actual phones but there is a workaround for Android:<br />
+
 
<br />
+
The only restriction with the player is that it only works on the computer viewing the html5 game (localhost) - this would normally rule out actual phones but there is a workaround for Android:
1. Connect your Android phone to your computer using ADB.<br />
+
** Connect your Android phone to your computer using ADB
2. Type in this command in a command console shell (Windows) or terminal (Mac):     <b>adb reverse tcp:15001 tcp:15001</b><br />
+
** Type in this command in a command console shell (Windows) or terminal (Mac):
3. The Android device now will see the Gideros Studio when testing the game when a player is launched from within Facebook Messenger.<br />
+
adb reverse tcp:15001 tcp:15001
<br />
+
** The Android device now will see the Gideros Studio when testing the game when a player is launched from within Facebook Messenger
Please refer to the <a href="https://developers.facebook.com/docs/games/instant-games/getting-started/quickstart">original Facebook documentation</a> for more information about testing and uploading.<br /><br/>
+
 
Please note that the offical Facebook documentation mentions having to wait for initializeAsync, with Gideros this has already been done for you before your game starts.<br /><br />
+
Please refer to the https://developers.facebook.com/docs/games/instant-games/getting-started/quickstart original Facebook documentation for more information about testing and uploading.
It is very important that the only the following API calls are made before startGameAsync has resolved:<br />
+
 
FBInstant.getSDKVersion()<br />
+
Please note that the offical Facebook documentation mentions having to wait for initializeAsync, with Gideros this has already been done for you before your game starts.
FBInstant.initializeAsync()<br />
+
 
FBInstant.getPlatform()<br />
+
It is very important that only the following API calls are made before startGameAsync has resolved:
FBInstant.setLoadingProgress()<br />
+
*FBInstant.getSDKVersion()
FBInstant.getSupportedAPIs()<br />
+
*FBInstant.initializeAsync()
FBInstant.quit()<br />
+
*FBInstant.getPlatform()
FBInstant.onPause()<br />
+
*FBInstant.setLoadingProgress()
FBInstant.player.getID()<br /><br />
+
*FBInstant.getSupportedAPIs()
To help do this you could create a variable called FBInstantAPI and set it to true once startGameAsync has been resolved - then only call other API commands if FBInstant is true and then if FBInstantAPI is true.</translate>
+
*FBInstant.quit()
=== <translate>Examples</translate> ===
+
*FBInstant.onPause()
'''Initialisation and removal of the Facebook loading progress indicator.'''<br/>
+
*FBInstant.player.getID()
 +
 
 +
To help do this you could create a variable called FBInstantAPI and set it to true once startGameAsync has been resolved - then only call other API commands if FBInstant is true and then if FBInstantAPI is true.
 +
 
 +
=== Example ===
 +
'''Initialisation and removal of the Facebook loading progress indicator'''
 
<syntaxhighlight lang="lua">  
 
<syntaxhighlight lang="lua">  
 
pcall(function() FBInstant=require "FBInstant" end)
 
pcall(function() FBInstant=require "FBInstant" end)
Line 41: Line 45:
 
else
 
else
 
print("FBInstant not loaded")
 
print("FBInstant not loaded")
end</syntaxhighlight>
+
end
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/FBInstant.canCreateShortcutAsync|FBInstant.canCreateShortcutAsync]] ''<translate>Returns whether or not the user is eligible to have shortcut creation requested.</translate>''<br/><!-- GIDEROSMTD:FBInstant.canCreateShortcutAsync(callback) Returns whether or not the user is eligible to have shortcut creation requested. -->
+
[[FBInstant.canCreateShortcutAsync]] ''Returns whether or not the user is eligible to have shortcut creation requested.''<br/><!-- GIDEROSMTD:FBInstant.canCreateShortcutAsync(callback) Returns whether or not the user is eligible to have shortcut creation requested. -->
[[Special:MyLanguage/FBInstant.checkCanPlayerMatchAsync|FBInstant.checkCanPlayerMatchAsync]] ''<translate>Checks if the current player is eligible for the matchPlayerAsync API.</translate>''<br/><!-- GIDEROSMTD:FBInstant.checkCanPlayerMatchAsync(callback) Checks if the current player is eligible for the matchPlayerAsync API. -->
+
[[FBInstant.checkCanPlayerMatchAsync]] ''Checks if the current player is eligible for the matchPlayerAsync API.''<br/><!-- GIDEROSMTD:FBInstant.checkCanPlayerMatchAsync(callback) Checks if the current player is eligible for the matchPlayerAsync API. -->
[[Special:MyLanguage/FBInstant.createShortcutAsync|FBInstant.createShortcutAsync]] ''<translate>Prompts the user to create a shortcut to the game.</translate>''<br/><!-- GIDEROSMTD:FBInstant.createShortcutAsync(callback) Prompts the user to create a shortcut to the game. -->
+
[[FBInstant.createShortcutAsync]] ''Prompts the user to create a shortcut to the game.''<br/><!-- GIDEROSMTD:FBInstant.createShortcutAsync(callback) Prompts the user to create a shortcut to the game. -->
[[Special:MyLanguage/FBInstant.getEntryPointAsync|FBInstant.getEntryPointAsync]] ''<translate>Returns the entry point that the game was launched from.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getEntryPointAsync(callback) Returns the entry point that the game was launched from. -->
+
[[FBInstant.getEntryPointAsync]] ''Returns the entry point that the game was launched from.''<br/><!-- GIDEROSMTD:FBInstant.getEntryPointAsync(callback) Returns the entry point that the game was launched from. -->
[[Special:MyLanguage/FBInstant.getEntryPointData|FBInstant.getEntryPointData]] ''<translate>Returns any data object associated with the entry point that the game was launched from.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getEntryPointData() Returns any data object associated with the entry point that the game was launched from. -->
+
[[FBInstant.getEntryPointData]] ''Returns any data object associated with the entry point that the game was launched from.''<br/><!-- GIDEROSMTD:FBInstant.getEntryPointData() Returns any data object associated with the entry point that the game was launched from. -->
[[Special:MyLanguage/FBInstant.getInterstitialAdAsync|FBInstant.getInterstitialAdAsync]] ''<translate>Attempt to create an instance of interstitial ad.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getInterstitialAdAsync(placementID,callback) Attempt to create an instance of interstitial ad. -->
+
[[FBInstant.getInterstitialAdAsync]] ''Attempt to create an instance of interstitial ad.''<br/><!-- GIDEROSMTD:FBInstant.getInterstitialAdAsync(placementID,callback) Attempt to create an instance of interstitial ad. -->
[[Special:MyLanguage/FBInstant.getLeaderboardAsync|FBInstant.getLeaderboardAsync]] ''<translate>Fetch a specific leaderboard belonging to this Instant Game.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getLeaderboardAsync(name,callback) Fetch a specific leaderboard belonging to this Instant Game. -->
+
[[FBInstant.getLeaderboardAsync]] ''Fetch a specific leaderboard belonging to this Instant Game.''<br/><!-- GIDEROSMTD:FBInstant.getLeaderboardAsync(name,callback) Fetch a specific leaderboard belonging to this Instant Game. -->
[[Special:MyLanguage/FBInstant.getLocale|FBInstant.getLocale]] ''<translate>The current locale.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getLocale() The current locale. -->
+
[[FBInstant.getLocale]] ''The current locale.''<br/><!-- GIDEROSMTD:FBInstant.getLocale() The current locale. -->
[[Special:MyLanguage/FBInstant.getPlatform|FBInstant.getPlatform]] ''<translate>The platform on which the game is currently running.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getPlatform() The platform on which the game is currently running. -->
+
[[FBInstant.getPlatform]] ''The platform on which the game is currently running.''<br/><!-- GIDEROSMTD:FBInstant.getPlatform() The platform on which the game is currently running. -->
[[Special:MyLanguage/FBInstant.getRewardedVideoAsync|FBInstant.getRewardedVideoAsync]] ''<translate>Attempt to create an instance of rewarded video.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getRewardedVideoAsync(placementID,callback) Attempt to create an instance of rewarded video. -->
+
[[FBInstant.getRewardedVideoAsync]] ''Attempt to create an instance of rewarded video.''<br/><!-- GIDEROSMTD:FBInstant.getRewardedVideoAsync(placementID,callback) Attempt to create an instance of rewarded video. -->
[[Special:MyLanguage/FBInstant.getSDKVersion|FBInstant.getSDKVersion]] ''<translate>The string representation of this SDK version.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getSDKVersion() The string representation of this SDK version. -->
+
[[FBInstant.getSDKVersion]] ''The string representation of this SDK version.''<br/><!-- GIDEROSMTD:FBInstant.getSDKVersion() The string representation of this SDK version. -->
[[Special:MyLanguage/FBInstant.getSupportedAPIs|FBInstant.getSupportedAPIs]] ''<translate>Provides a list of API functions that are supported by the client.</translate>''<br/><!-- GIDEROSMTD:FBInstant.getSupportedAPIs() Provides a list of API functions that are supported by the client. -->
+
[[FBInstant.getSupportedAPIs]] ''Provides a list of API functions that are supported by the client.''<br/><!-- GIDEROSMTD:FBInstant.getSupportedAPIs() Provides a list of API functions that are supported by the client. -->
[[Special:MyLanguage/FBInstant.logEvent|FBInstant.logEvent]] ''<translate>Log an app event with FB Analytics.</translate>''<br/><!-- GIDEROSMTD:FBInstant.logEvent(eventName,valueToSum,parameters) Log an app event with FB Analytics. -->
+
[[FBInstant.logEvent]] ''Log an app event with FB Analytics.''<br/><!-- GIDEROSMTD:FBInstant.logEvent(eventName,valueToSum,parameters) Log an app event with FB Analytics. -->
[[Special:MyLanguage/FBInstant.matchPlayerAsync|FBInstant.matchPlayerAsync]] ''<translate>Attempts to match the current player with other users looking for people to play with.</translate>''<br/><!-- GIDEROSMTD:FBInstant.matchPlayerAsync(matchTag,switchContextWhenMatched,callback) Attempts to match the current player with other users looking for people to play with. -->
+
[[FBInstant.matchPlayerAsync]] ''Attempts to match the current player with other users looking for people to play with.''<br/><!-- GIDEROSMTD:FBInstant.matchPlayerAsync(matchTag,switchContextWhenMatched,callback) Attempts to match the current player with other users looking for people to play with. -->
[[Special:MyLanguage/FBInstant.onPause|FBInstant.onPause]] ''<translate>Set a callback to be fired when a pause event is triggered.</translate>''<br/><!-- GIDEROSMTD:FBInstant.onPause(callback) Set a callback to be fired when a pause event is triggered. -->
+
[[FBInstant.onPause]] ''Set a callback to be fired when a pause event is triggered.''<br/><!-- GIDEROSMTD:FBInstant.onPause(callback) Set a callback to be fired when a pause event is triggered. -->
[[Special:MyLanguage/FBInstant.quit|FBInstant.quit]] ''<translate>Quits the game.</translate>''<br/><!-- GIDEROSMTD:FBInstant.quit() Quits the game. -->
+
[[FBInstant.quit]] ''Quits the game.''<br/><!-- GIDEROSMTD:FBInstant.quit() Quits the game. -->
[[Special:MyLanguage/FBInstant.setLoadingProgress|FBInstant.setLoadingProgress]] ''<translate>Report the game's initial loading progress.</translate>''<br/><!-- GIDEROSMTD:FBInstant.setLoadingProgress(percentage) Report the game's initial loading progress. -->
+
[[FBInstant.setLoadingProgress]] ''Report the game's initial loading progress.''<br/><!-- GIDEROSMTD:FBInstant.setLoadingProgress(percentage) Report the game's initial loading progress. -->
[[Special:MyLanguage/FBInstant.setSessionData|FBInstant.setSessionData]] ''<translate>Sets the data associated with the individual gameplay session for the current context.</translate>''<br/><!-- GIDEROSMTD:FBInstant.setSessionData(sessionData) Sets the data associated with the individual gameplay session for the current context. -->
+
[[FBInstant.setSessionData]] ''Sets the data associated with the individual gameplay session for the current context.''<br/><!-- GIDEROSMTD:FBInstant.setSessionData(sessionData) Sets the data associated with the individual gameplay session for the current context. -->
[[Special:MyLanguage/FBInstant.shareAsync|FBInstant.shareAsync]] ''<translate>This invokes a dialog to let the user share specified content.</translate>''<br/><!-- GIDEROSMTD:FBInstant.shareAsync(payload,callback) This invokes a dialog to let the user share specified content. -->
+
[[FBInstant.shareAsync]] ''This invokes a dialog to let the user share specified content.''<br/><!-- GIDEROSMTD:FBInstant.shareAsync(payload,callback) This invokes a dialog to let the user share specified content. -->
[[Special:MyLanguage/FBInstant.startGameAsync|FBInstant.startGameAsync]] ''<translate>This indicates that the game has finished initial loading and is ready to start.</translate>''<br/><!-- GIDEROSMTD:FBInstant.startGameAsync(callback) This indicates that the game has finished initial loading and is ready to start. -->
+
[[FBInstant.startGameAsync]] ''This indicates that the game has finished initial loading and is ready to start.''<br/><!-- GIDEROSMTD:FBInstant.startGameAsync(callback) This indicates that the game has finished initial loading and is ready to start. -->
[[Special:MyLanguage/FBInstant.switchGameAsync|FBInstant.switchGameAsync]] ''<translate>Request that the client switch to a different Instant Game.</translate>''<br/><!-- GIDEROSMTD:FBInstant.switchGameAsync(appID,data,callback) Request that the client switch to a different Instant Game. -->
+
[[FBInstant.switchGameAsync]] ''Request that the client switch to a different Instant Game.''<br/><!-- GIDEROSMTD:FBInstant.switchGameAsync(appID,data,callback) Request that the client switch to a different Instant Game. -->
[[Special:MyLanguage/FBInstant.updateAsync|FBInstant.updateAsync]] ''<translate>Informs Facebook of an update that occurred in the game.</translate>''<br/><!-- GIDEROSMTD:FBInstant.updateAsync(payload,callback) Informs Facebook of an update that occurred in the game. -->
+
[[FBInstant.updateAsync]] ''Informs Facebook of an update that occurred in the game.''<br/><!-- GIDEROSMTD:FBInstant.updateAsync(payload,callback) Informs Facebook of an update that occurred in the game. -->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
 
|}
 
|}

Latest revision as of 05:01, 24 June 2024

Supported platforms: Platform html5.png
Available since: Gideros 2018.3

Description

You need to do two things to target Facebook Instant Games:

  1. Tick the Facebook Instant Game tickbox when exporting to HTML5, you can also specify the percentage indicator that the game will show it has loaded before you take control
  2. Require the FBInstant library code, see the example below

You can upload, debug and test your game by creating a player and uploading to Facebook servers as a game. The player will interact with the Gideros Studio similar to any other player.

The only restriction with the player is that it only works on the computer viewing the html5 game (localhost) - this would normally rule out actual phones but there is a workaround for Android:

    • Connect your Android phone to your computer using ADB
    • Type in this command in a command console shell (Windows) or terminal (Mac):
adb reverse tcp:15001 tcp:15001
    • The Android device now will see the Gideros Studio when testing the game when a player is launched from within Facebook Messenger

Please refer to the https://developers.facebook.com/docs/games/instant-games/getting-started/quickstart original Facebook documentation for more information about testing and uploading.

Please note that the offical Facebook documentation mentions having to wait for initializeAsync, with Gideros this has already been done for you before your game starts.

It is very important that only the following API calls are made before startGameAsync has resolved:

  • FBInstant.getSDKVersion()
  • FBInstant.initializeAsync()
  • FBInstant.getPlatform()
  • FBInstant.setLoadingProgress()
  • FBInstant.getSupportedAPIs()
  • FBInstant.quit()
  • FBInstant.onPause()
  • FBInstant.player.getID()

To help do this you could create a variable called FBInstantAPI and set it to true once startGameAsync has been resolved - then only call other API commands if FBInstant is true and then if FBInstantAPI is true.

Example

Initialisation and removal of the Facebook loading progress indicator

 
pcall(function() FBInstant=require "FBInstant" end)
if FBInstant then
	FBInstant.startGameAsync(function() 
		print("Loading screen removed")
		FBInstantAPI=true
	end)
else
	print("FBInstant not loaded")
end

Methods

FBInstant.canCreateShortcutAsync Returns whether or not the user is eligible to have shortcut creation requested.
FBInstant.checkCanPlayerMatchAsync Checks if the current player is eligible for the matchPlayerAsync API.
FBInstant.createShortcutAsync Prompts the user to create a shortcut to the game.
FBInstant.getEntryPointAsync Returns the entry point that the game was launched from.
FBInstant.getEntryPointData Returns any data object associated with the entry point that the game was launched from.
FBInstant.getInterstitialAdAsync Attempt to create an instance of interstitial ad.
FBInstant.getLeaderboardAsync Fetch a specific leaderboard belonging to this Instant Game.
FBInstant.getLocale The current locale.
FBInstant.getPlatform The platform on which the game is currently running.
FBInstant.getRewardedVideoAsync Attempt to create an instance of rewarded video.
FBInstant.getSDKVersion The string representation of this SDK version.
FBInstant.getSupportedAPIs Provides a list of API functions that are supported by the client.
FBInstant.logEvent Log an app event with FB Analytics.
FBInstant.matchPlayerAsync Attempts to match the current player with other users looking for people to play with.
FBInstant.onPause Set a callback to be fired when a pause event is triggered.
FBInstant.quit Quits the game.
FBInstant.setLoadingProgress Report the game's initial loading progress.
FBInstant.setSessionData Sets the data associated with the individual gameplay session for the current context.
FBInstant.shareAsync This invokes a dialog to let the user share specified content.
FBInstant.startGameAsync This indicates that the game has finished initial loading and is ready to start.
FBInstant.switchGameAsync Request that the client switch to a different Instant Game.
FBInstant.updateAsync Informs Facebook of an update that occurred in the game.

Events

Constants