Firebase Realtime Database Documentation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

 

Overview

The Firebase Realtime Database is a cloud-hosted database. Data in the Realtime


Database is stored as JSON and synchronized in real time to every connected client. When
you build cross-platform apps with the iOS, Android, and JavaScript SDKs, all of your
clients share one Realtime Database instance and automatically receive updates with the
newest data.

Check the official page for more information.

Setup

Before starting to use any Firebase extensions, you are required to follow some initial
configuration steps.

NOTE  The SDK version is only available for the Android, iOS and Web targets; if you're
targeting other devices, please follow the steps for REST API.

• Create Project (skip this if you already have a project)

• Firebase Console (enabling Firebase Realtime Database)

• Platform Setup (configuring SDKs or REST API)

Functions

The Firebase Realtime Database extension was implemented using a fluent-API (method


chaining) approach and the entry point for interacting with the database is using the
function FirebaseRealTime, which will return a <dbEntryRef>  of the database.

The following functions are given for working with Firebase Firestore extension:
 
• FirebaseRealTime (entry point)

• <dbEntryRef>.Child

• <dbEntryRef>.Delete

• <dbEntryRef>.Exists

• <dbEntryRef>.Listener

• <dbEntryRef>.ListenerRemove

• <dbEntryRef>.ListenerRemoveAll

• <dbEntryRef>.Parent

• <dbEntryRef>.Path

• <dbEntryRef>.Push

• <dbEntryRef>.Set

• <dbEntryRef>.Read

• The functions given below should only be used for filtering data when
reading from the database using the Read() function given above.

• <dbEntryRef>.EndAt

• <dbEntryRef>.EqualTo

• <dbEntryRef>.LimitToFirst

• <dbEntryRef>.LimitToLast

• <dbEntryRef>.OrderByChild

• <dbEntryRef>.OrderByKey

• <dbEntryRef>.OrderByValue

• <dbEntryRef>.StartAt

 
Create
  Project
Before working with any Firebase functions, you must set up your Firebase project:

1. Go to the Firebase Console web site.

2. Click on Add Project to create your new project.

3. Enter a name for your project and click on the Continue button.


 

4. On the next page, make sure that Enable Google Analytics for this project is
enabled and then click the Continue button:
  5. Select your account and click the Create project button:

6. Wait a moment until you project is created; after a few moments you should see
the page shown below:
  7. You will now be taken to your new project's home page:

8. Continue your adventure with the Firebase extensions provided for GameMaker


Studio 2!

 
Firebase
  Console
Before being able to use the Firebase Realtime Database extension we need to configure a
new database to work with in the Firebase Console. Follow the steps below to get your
first database set up.

1. On your Firebase project, click on Realtime Database and select Create Database.

2. Select your database location and click on Next.

3. Select Start in test mode (otherwise you will need add your own rules for
production mode) and click on Next.
 

4. You are now ready to start using Firebase Realtime Database extension.

 
Platform
  Setup
Firebase Realtime Database implementation uses both SDK (working on Android, iOS and
Web) and also REST API that allows it to work on any other platform. In this section we will
cover the steps necessary to start using the Firebase Realtime Database extension on your
game.

Select your target platform below and follow the simple steps to get your project up and
running:

• Android Setup (once per project)

• iOS Setup (once per project)

• Web Setup (once per project)

• REST API Setup

Advanced Configuration

The Firebase Realtime Database extension by default uses SDKs on Android, iOS and Web


targets and uses REST API on all other exports, but you can change this behavior (e.g.:
forcing REST API to be used even on SDK enabled platforms) by changing the macro
FirebaseRealTime_Library to any one of the following constants:

• FirebaseRealTime_LibraryOptions_SDKOnly : Always use SDK

• FirebaseRealTime_LibraryOptions_SDKWhenAvailable : Use SDK when available, otherwise


use REST

• FirebaseRealTime_LibraryOptions_RESTOnly : Always use REST

 
Android
  Setup
This setup is necessary for all the Firebase modules using Android and needs to be done
once per project, and basically involves importing the google-services.json file into your
project.

IMPORTANT Please refer to this Helpdesk article for instructions on setting up an


Android project.

1. Click the Settings icon (next to Project Overview) and select Project settings:

2. Now go to the Your apps section and click on the Android button:


  3. On this screen you need enter your Package name (required), App nickname
(optional) and Debug signing certificate SHA-1 (required if you are using Firebase
Authentication).

You can get your package name from the Android Game Options, and your Debug
signing certificate SHA-1 from the Android Preferences (under Keystore):

4. Click on Download google-services.json (make sure to save this file as we will need


it in subsequent steps).
 

5. Ignore this screen, as this is already done in the extension.


  6. Click on the Continue to console button.

7. Now go into GameMaker Studio 2, right click on your Firebase extension asset and
click on Open In Explorer / Show In Finder.
  NOTE You only need to perform this set-up using one of your Firebase
extensions (per project); for this example we'll be using the Firebase
Analytics extension.

8.
Open the AndroidSource folder.

9. If the ProjectFiles folder does not exist, please create it.

10.
Open ProjectFiles folder and place your downloaded google-services.json file
inside it.

11. You have now finished the main setup for all Firebase Android modules!
 

 
iOS Setup
 

This setup is necessary for all the Firebase modules using iOS and needs to be done once
per project, and basically involves importing the GoogleServices-Info.plist file into your
project.

IMPORTANT Please refer to this Helpdesk article for instructions on setting up an iOS


project.

1. Click the Settings icon (next to Project Overview) and select Project settings:

2. Now go to the Your apps section and click on the iOS button:


  3. Fill the form with your iOS Bundle ID, App nickname and AppStore ID (last two are
optional).

4. Click on Download GoogleService-info.plist (make sure to save this file as we will


need it in subsequent steps).
 

5. Ignore this screen, as this is already done in the extension.

6. Ignore this screen as well, as this is also done in the extension.


 

7. Click on the Continue to console button:


  8. Now go into GameMaker Studio 2, right click on your Firebase extension asset and
click on Open In Explorer / Show In Finder.

NOTE  You only need to perform this set-up using one of your Firebase
extensions (per project); for this example we'll be using the Firebase
Analytics extension.

9. If the iOSProjectFiles folder does not exist, please create it.

10. Open the iOSProjectFiles folder and place your GoogleService-Info.plist file


inside it.
 

11. Make sure to set up CocoaPods for your project unless you are only using the
REST API in an extension (if one is provided -- not all extensions provide a REST
API) or the Firebase Cloud Functions extension (which only uses a REST API).

12. You have now finished the main setup for all Firebase iOS modules!

 
Web
  Setup
This setup is necessary for all the Firebase modules using Web export and needs to be
done once per project, and basically involves adding Firebase libraries and your Firebase
values to the index.html file in your project.

1. Click the Settings icon (next to Project Overview) and then Project settings:

2. Now go to the Your apps section and click on the Web ( </> ) button:

3. Enter your App nickname (required):


 

4. On this screen, just copy the firebaseConfig struct:

5. Now go back into GameMaker Studio 2 and build your project.


  6. Choose the Package As Zip option:

7. Locate the created package and extract it into a folder.

8. Open the extracted folder and look for an index.html file.

9. Open the index.html file in Notepad++ or Visual Studio Code (or any other text
editor you prefer).
 

10. Now we need to add the following code between the </head> and <body>  tags (line
72 in the html.index image above):

<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-
app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-
analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-
auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-
database.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-
firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.9.1/firebase-remote-
config.js"></script>

<script>
  const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: "",
    measurementId: ""
  };
  firebase.initializeApp(firebaseConfig);
  
</script>

11. Replace the const firebaseConfig part with the one copied in step 4:


 

12. Go back into GameMaker and open your Included Files folder.

13. Press the Open in Explorer button:


 

14. Place your index.html file inside the folder that opens (/datafiles).

15. Back in GameMaker, click on the Game Options button.

16. Go into the HTML5 platform settings


 

17. In the Advanced section go to the "Include file as index.html" dropdown and select


the index.html option (this is the file we have just added to the included files).

18. Press Apply and the main setup for all Firebase Web modules is finished!

 
 

 
REST
  API Setup
This setup is necessary for syncing the Firebase Realtime Database console with the REST
API implementation. 

1. On your Firebase project's dashboard, click on Realtime Database and copy your


database's link.

2. In your GameMaker project, open the script FirebaseRealTime_Init and paste your


link in the Firebase_ProjectID macro (keep it inside the quotes).

3. You now have the Firebase Realtime extension configured to use the REST API.

 
FirebaseRealTime
 

This function is the entry point for database interactions using the Firebase Realtime
Database extension.  It returns a <dbEntryRef> that can be further modified and
configured using chained methods.

NOTE  The Firebase Realtime Database implements a fluent-API meaning almost all


functions return self allowing them to be chained and for you to build complex database
interactions while keeping the code clean and easy to follow. Entries in the database are
structs and are referred to in this documentation as <dbEntryRef>. These, under the
hood, are structs that point to a specific path in the database (they are NOT the actual
entry). 

Syntax:

FirebaseRealTime([database])

Argument Description
database OPTIONAL Overwrite the default database

Returns:

dbEntryRef Struct

Example:

// 1) This will use the default database


FirebaseRealTime().Path("players/hero/hp").Set(100);

// 2) This will use a custom database url


FirebaseRealTime(dbUrl).Path("players/hero/hp").Set(100);

Above we have two database interaction examples. In the first one we create a reference
to a database entry ( "players/hero/hp" , using the chained method Path) and afterwards we
set that entry to the value  100  (using the method Set). The second example is very similar
but
  we pass in a specific database URL ( dbUrl ) to the main function call; this is very
powerful and allows the developer to have access as many different databases as needed.

 
<dbEntryRef>.Child
 

This method appends the given relatives path to the current path of a Realtime
Database <dbEntryRef> struct.

Syntax:

<dbEntryRef>.Child(path)

Argument Description
path Relative child path

Returns:

dbEntryRef Struct

Example:

var parentNode = "characters/player";
var nodeRef = FirebaseRealTime().Path(parentNode).Child("heath");

The code sample above will create a <dbNodeRef> to the "characters/player" path (using
the Path method) and afterwards append the relative path "health" to it, meaning the
resulting reference ( nodeRef ) now points to the "characters/player/health"  path.

 
<dbEntryRef>.Delete
 

This method deletes a reference on the database and returns a listener identifier for
tracking purposes.

This is an asynchronous function that will trigger the Async Social event when the task
is finished.

Syntax:

<dbEntryRef>.Delete()

Returns:

Real (Asynchronous Listener ID)

Triggers:

Asynchronous Social Event

Key Type Description


type string The string  "FirebaseRealTime_Delete"

listener real The asynchronous listener ID.


path string The path of the database reference.
The HTTP status response code (see
status real
reference)
errorMessage string The readable error message  OPTIONAL

Example:

listenerId = FirebaseRealTime().Path("myCollection/oldDoc").Delete();
I n the code above we first get the reference to a database path ( "myCollection/oldDoc" ,
using the method Path) and then delete that entry. The function call will then return a
listener ID ( listenerId ) that can be used inside an Async Social event.

if (async_load[? "type"] == "FirebaseRealTime_Delete")


{
    if (async_load[? "status"] == 200)
    {
        show_debug_message("Database entry was successfully deleted.");
    }
    else
    {
        var errorMessage = async_load[?"errorMessage"];
    }
}

The code above matches the response against the correct event type, providing a
success message if status is valid.

 
<dbEntryRef>.Exists
 

This method checks if a reference exists on the database and returns a listener identifier
for tracking purposes.

This is an asynchronous function that will trigger the Async Social event when the task
is finished.

Syntax:

<dbEntryRef>.Exists()

Returns:

Real (Asynchronous Listener ID)

Triggers:

Asynchronous Social Event

Key Type Description


type string The string  "FirebaseRealTime_Exists"

listener real The asynchronous listener ID.


path string The path of the database reference.
The HTTP status response code (see
status real
reference)
Whether or not the database path exists.
values boolean
OPTIONAL

errorMessage string The readable error message.  OPTIONAL

Example:

listenerId = FirebaseRealTime().Path("myCollection/oldDoc").Exists()
I n the code above we first get the reference to a database path ( "myCollection/oldDoc" ,
using the function Path) and check if that entry exists in our database. The function call
will then return a listener ID ( listenerId ) that can be used inside an Async Social event.

if (async_load[? "type"] == "FirebaseRealTime_Exists")


{
    if (async_load[? "status"] == 200 && async_load[? "values"])
    {
        show_debug_message("Database entry exists.");
    }
    else
    {
        var errorMessage = async_load[?"errorMessage"]
    }
}

The code above matches the response against the correct event type, providing a
success message if the entry exists in the database.

 
<dbEntryRef>.Listener
 

The method listens for changes to a given entry in the database. If you need to stop
listening to changes you can use ListenerRemove for a specific database reference
or ListenerRemoveAll to remove all listeners.

This is an asynchronous function that will trigger the Async Social event each time there is
a change to the document.

IMPORTANT  When you no longer need to listen to changes make sure to remove the
listeners, as not doing so can lead to memory leaks.

Syntax:

<dbEntryRef>.Listener()

Returns:

Real (Asynchronous Listener ID)

Triggers:

Asynchronous Social Event

Key Type Description


type string The string  "FirebaseRealTime_Listener"

listener real The asynchronous listener ID.


path string The path of the database reference.
The HTTP status response code (see
status real
reference)
real/
value string/ The new value of the entry  OPTIONAL
struct
errorMessage string The readable error message  OPTIONAL
 

Example:

listenerId = FirebaseRealTime("players/hero").Listener();

The code above starts listening for updates on the database entry ( "player/hero" ). If this
reference gets updated, set or deleted an async event will be triggered. The function call
will return a listener ID ( listenerId ) that can be used inside an Async Social event.

if (async_load[? "type"] == "FirebaseRealTime_Listener")


{
    if (async_load[? "status"] == 200)
    {
        show_debug_message("Changes were made to this entry");
    }
    else
    {
        var errorMessage = async_load[? "errorMessage"];
    }
}

The code above matches the response against the correct event type and logs when
changes are made to the database reference being listened to.

 
<dbEntryRef>.ListenerRemove
 

This method removes a previously created listener (that was created using the function
Listener).

TIP  If you wish to remove all created listeners use


the function ListenerRemoveAll instead.

Syntax:

<dbEntryRef>.ListenerRemove()

Argument Type Description


listenerId real The listener Id to be removed.

Returns:

N/A

Example:

listenerId = FirebaseRealTime("players/hero").Listener();

// Some time later

FirebaseRealTime().ListenerRemove(listenerId);

The code sample above starts by creating a listener to a database entry reference (using
the Listener method). This function returns a listener ID ( listenerId ) and at a later stage
we use that ID to remove the listener.

 
<dbEntryRef>.ListenerRemoveAll
 

This method removes all previously created listeners (that were created using the function
Listener).

TIP  If you wish to remove a specific listener use the function ListenerRemove instead.

Syntax:

<dbEntryRef>.ListenerRemoveAll()

Returns:

N/A

Example:

listenerId1 = FirebaseRealTime().Path("players/hero").Listener();
listenerId2 = FirebaseRealTime().Path("players/knight").Listener();

// Some time later


FirebaseRealTime().ListenerRemoveAll()

The code above creates two listeners (using the Listener function) on different database
entries (using the Path method) and after some time it removes them all.
<dbEntryRef>.Parent
 

This method goes up the hierarchy to the parent path of the current <dbEntryRef> struct.

Syntax:

<dbEntryRef>.Parent()

Returns:

dbEntryRef Struct

Example:

var dbPath = "players/hero/name";
var dbEntryRef = FirebaseRealTime().Path(dbPath).Parent().Child("magic").Set(99);

The code above creates a <dbEntryRef> to the "players/hero/name" path (using the
Path function) and afterwards goes up to the parent path meaning the resulting reference
( dbEntryRef ) now points to the "players/hero"  path. We then go into the child database
entry (using the Child method) and finally set this new reference ( "players/hero/magic" ) to
the value 99  (using the Set method).

 
<dbEntryRef>.Path
 

This method attaches a path reference to the current database's <dbEntryRef>. 

NOTE  Paths are a representation of references in the database (i.e.: the path to get
"Opera X YoYoGames" is "Testing/String" ).

Syntax:

<dbEntryRef>.Path(path)

Argument Description
path The path reference to the database entry.

Returns:

dbEntryRef Struct

Example:

FirebaseRealTime().Path("Testing/String").Read();
  he code above first creates the reference to a database entry (
T "Testing/String" ) and then
reads that entry (using the Read method).

 
<dbEntryRef>.Push
 

This method is useful for storing arrays inside the database. Database elements can be of
type string, real or struct, meaning that arrays are not a valid type within a Firebase
Realtime Database. This method attaches an auto-generated child location to the current
database entry reference.

In this image below we can see the auto-generated keys in "Testing/List".

Syntax:

<dbEntryRef>.Push()

Returns:

dbEntryRef Struct

Example:

var data = { health: 100, magic: 99 };
var jsonData = json_stringify(data);
  FirebaseRealTime().Path("Enemies/List").Push().Set(jsonData);

The code above first creates the reference to a database entry ( "Enemies/List" , using


the Path method) and then pushes a new auto-generated key into that reference (this is
what emulates arrays/collections). Finally it sets that database entry with the previously
created data (using the Set method).

 
<dbEntryRef>.Set
 

This method creates or overwrites a database entry value of type real, string,


or struct (arrays are not a valid type) and returns a listener ID to be used for tracking
purposes.

This is an asynchronous function that will trigger the Async Social event when the task
is finished.

TIP  It's also possible to add a time-stamp value to the database entry if you set it to
{ .sv: "timestamp" } (example below).

Syntax:

<dbReference>.Set(value)

Argument Type Description


real/string/ The data to be set within the current database
value
struct entry.

Returns:

Real (Asynchronous Listener ID)

Triggers:

Asynchronous Social Event

Key Type Description


type string The string  "FirebaseRealTime_Set"

listener real The asynchronous listener ID.


path string The path of the database reference.
The HTTP status response code (see
status real
reference)
  errorMessage string The readable error message  OPTIONAL

Example:

// (1) Set value using a real


listenerId = FirebaseRealTime().Path("enemies/bat/health").Set(999);

// (2) Set value using a string


listenerId = FirebaseRealTime().Path("enemies/bat/name").Set("Monster");

// (3) Set value using a struct


var data = { health: 100, magic: 99 };
listenerId = FirebaseRealTime().Path("enemies/bat").Set(data);

// (4) Time stamps


var data = {};
data[$ ".sv"] = "timestamp";
listenerId = FirebaseRealTime().Path("enemies/bat/timestamp").Set(data);

The code sample above provides three example for setting values in a database entry
using a real, a string and a struct (a timestamp example is also provided). The function call
will then return a listener ID ( listenerId ) that can be used inside an Async Social event.

if (async_load[? "type"] == "FirebaseRealTime_Set")


{
    if (async_load[? "status"] == 200)
    {
        show_debug_message(".Set() function call succeeded!");
    }
    else
    {
        var errorMessage = async_load[? "errorMessage"]
    }
}

The code above matches the response against the correct event type and logs the success
of the task.

 
<dbEntryRef>.Read
 

This method reads the current database reference and returns a listener identifier.

This is an asynchronous function that will trigger the Async Social event when the task
is finished.

Syntax:

<dbEntryRef>.Read()

Returns:

Real (Asynchronous Listener ID)

Triggers:

Asynchronous Social Event

Key Type Description


type string The string  "FirebaseRealTime_Read"

listener real The asynchronous listener ID.


path string The path of the database reference.
The HTTP status response code (see
status real
reference)
real/
value string/ The value being read  OPTIONAL
struct
errorMessage string The readable error message  OPTIONAL

Example:

listenerId = FirebaseRealTime().Path("players/hero").Read()
  he code above first gets the reference to a database entry ( "players/hero" , using the
T
Path method) and then reads that entry. The function call will then return a listener ID
( listenerId ) that can be used inside an Async Social event.

if (async_load[? "type"] == "FirebaseRealTime_Read")


{
    if (async_load[? "status"] == 200)
    {
        show_debug_message("The entry data is: " + async_load[? "value"]);
    }
    else
    {
        var errorMessage = async_load[?"errorMessage"]
    }
}

The code above matches the response against the correct event type, providing the
document data if the task succeeded.

 
<dbEntryRef>.EndAt
 

This function is a filter that should be used when preforming a Read operation or


creating Listener that is ordered in some way (see OrderByChild,
OrderByKey and OrderByValue). The filter assures that the returned results stop at a
specific value.

Syntax:

<dbEntryRef>.EndAt(value)

Argument Type Description


value real/string The value to stop the query at.

Returns:

dbEntryRef Struct

Example:

listenerId = FirebaseRealTime().Path("players/
healthList").OrderByValue().EndAt(99).Read();

The code above performs a read operation (using the Read method) on the


database reference "players/healthList"  (using the Path method) ordered by the value
(using the OrderByValue method), returning only values below or equal to  99 .

 
<dbEntryRef>.EqualTo
 

This function is a filter that should be used when preforming a Read operation or


creating Listener that is ordered in some way (see OrderByChild,
OrderByKey and OrderByValue). The filter assures that the returned results have a specific
value.

Syntax:

<dbEntryRef>.EqualTo(value)

Argument Type Description


value real/string The value to equal to.

Returns:

dbEntryRef Struct

Example:

listenerId = FirebaseRealTime().Path("players/
healthList").OrderByValue().EqualTo(77).Read();

The code above performs a read operation (using the Read method) on the


database reference "players/healthList"  (using the Path method) ordered by the value
(using the OrderByValue method), returning only values that are equal to  77 .
<dbEntryRef>.LimitToFirst
 

This function is a filter that should be used when preforming a Read operation or


creating Listener that is ordered in some way (see OrderByChild,
OrderByKey and OrderByValue). The filter assures that the returned results stop after the
first amount elements.

INFO  This method will filter elements from the start of the ordered group; if you want to
read from the end, use LimitToLast instead.

Syntax:

<dbEntryRef>.LimitToFirst(amount)

Argument Type Description


amount real The number of results to read (from the start)

Returns:

dbEntryRef Struct

Example:

listenerId = FirebaseRealTime().Path("players/
healthList").OrderByValue().LimitToFirst(5).Read();

The code above performs a read operation (using the Read method) on the


database reference "players/healthList"  (using the Path method) ordered by the value
(using the OrderByValue method), returning only the first 5 results.

 
<dbEntryRef>.LimitToLast
 

This function is a filter that should be used when preforming a Read operation or


creating Listener that is ordered in some way (see OrderByChild,
OrderByKey and OrderByValue). The filter assures that the returned results are the
last  amount  of elements.

INFO  This method will filter elements from the end of the ordered group; if you want to
read from the start, use LimitToFirst instead.

Syntax:

<dbEntryRef>.LimitToLast(amount)

Argument Type Description


amount real The number of results to read (from the end)

Returns:

dbEntryRef Struct

Example:

listenerId = FirebaseRealTime().Path("players/
healthList").OrderByValue().LimitToLast(5).Read()

The code above performs a read operation (using the Read method) on the


database reference "players/healthList"  (using the Path method) ordered by the value
(using the OrderByValue method), returning only the last  5 results.

 
<dbEntryRef>.OrderByChild
 

This method should be used when performing a Read operation or creating a Listener,


and orders the returned results by a child field  path so they can be then filtered using one
of the filtering methods (see StartAt, EndAt, EqualTo, LimitToFirst and LimitToLast).

NOTE  The final result from the Read()  call will not be sorted; the sort order is only used
by any filter methods chained after this.

Syntax:

<dbEntryRef>.OrderByChild(path)

Argument Type Description


path real The path to the specified field to sort the values by.

Returns:

dbEntryRef Struct

Example:

listenerId =
FirebaseRealTime().Path("enemies").OrderByChild("points").LimitToLast(5).Read();

The code above performs a read operation (using the Read method) on the


database reference "enemies"  (using the Path method) ordered by the children
"points" , returning only the last  5 results (using the LimitToLast method).

 
<dbEntryRef>.OrderByKey
 

This method should be used when performing a Read operation or creating a Listener,


and orders the returned results by key so they can be then filtered using one of the
filtering methods (see StartAt, EndAt, EqualTo, LimitToFirst and LimitToLast).

NOTE  The final result from the Read()  call will not be sorted; the sort order is only used
by any filter methods chained after this.

Syntax:

<dbEntryRef>.OrderByKey()

Returns:

dbEntryRef Struct

Example:

listenerId = FirebaseRealTime().Path("enemies/
names").OrderByKey().LimitToFirst(5).Read();

The code above performs a read operation (using the Read method) on the


database reference "enemies/names"  (using the Path method) ordering the results by
key and returning only the first  5 elements (using the LimitToFirst method).

 
<dbEntryRef>.OrderByValue
 

This method should be used when performing a Read operation or creating a Listener,


and orders the returned results by value so they can be then filtered using one of the
filtering methods (see StartAt, EndAt, EqualTo, LimitToFirst and LimitToLast).

NOTE  The final result from the Read()  call will not be sorted; the sort order is only used
by any filter methods chained after this.

Syntax:

<dbEntryRef>.OrderByValue()

Returns:

dbEntryRef Struct

Example:

listenerId = FirebaseRealTime().Path("enemies/
names").OrderByValue().LimitToFirst(5).Read();

The code above performs a read operation (using the Read method) on the


database reference "enemies/names"  (using the Path method) ordering the results by value
and returning only the first  5 elements (using the LimitToFirst method).

 
<dbEntryRef>.StartAt
 

This function is a filter that should be used when preforming a Read operation or creating
a Listener that is ordered in some way (see OrderByChild,
OrderByKey and OrderByValue). The filter assures that the returned results start at a
specific value.

Syntax:

<dbEntryRef>.StartAt(value)

Argument Type Description


value real/string The value to start the query at.

Returns:

dbEntryRef Struct

Example:

listenerId = FirebaseRealTime().Path("players/
healthList").OrderByValue().StartAt(10).Read();

The code above performs a read operation (using the Read method) on the


database reference "players/healthList"  (using the Path method) ordered by the
value (using the OrderByValue method), returning only those values that are above or
equal to  10 .

 
REST
  API Setup
This setup is necessary for syncing the Firebase console with the REST API implementation
of the extension.

1. On your Firebase console, click on the Settings icon (next to Project Overview) and


then on Project settings.

2. Copy the Project ID.

3. In your GameMaker Studio project, open the FirebaseFirestore_Init script and


paste your Project ID in the macro Firebase_ProjectID (keep it inside the quotes).
 

4. The extension should now work on all your REST API exports!

You might also like