Share dynamic, procedurally generated or player generated game levels between users.



Sharing of game levels between users - for GameSalad®

Prerequisite: The Basics & Extended Setup X


Saving the player's game level to the back-end.


Step 1.

Create an empty Table, calling it game.T_LevelData_Shared, with the same type and number of columns as the table you wish to share.

You will be storing a temporary copy of your actual game table into this for use during network communications.




Step 2.

Add four new game level attributes as below:

game.send_savedatarequest_URL (of type text) : https://www.appformative.com/gs/send_savedatarequest.mox
game.get_savedatatoken_URL (of type text) : https://www.appformative.com/gs/get_savedatatoken.mox?ID=YOUR-APPID
game.send_savedatacommit_URL (of type text) : https://www.appformative.com/gs/send_savedatacommit.mox
game.get_savedatatable_URL (of type text) : https://www.appformative.com/gs/get_savedatatable.mox?ID=YOUR-APPID




Step 3.

In the actor to be used for the network behaviors, create three integer callback attributes, as well as attributes for a Private and Public Token-ID:

self.callback1 (of type integer)
self.callback2 (of type integer)
self.callback3 (of type integer)

self.PrivateTokenID (of type text)
self.PublicTokenID (of type text)




Step 4.

Now create a "Timer (After 0 seconds, Run to completion)" behavior. All the subsequent steps, 5 to 10, will be created inside the body of this Timer.




Step 5.

Fill the private Token-ID with 8 randomly created alphanumerical characters, for communication purposes with the back-end, e.g.

self.PrivateTokenID = random(10000000,99999999)




Step 6.

Fill the first row of the T_Analytics table with the following values:

Column1 : self.PrivateTokenID the Private Token-ID created in step 2
Column2 : a name for the level to be sent. Make the column blank if no name is required.
Column3 : a description of the level to be sent. Make the column blank if no description is required.




Step 7.

Now use the "Send Table To URL" network behavior to inform the back-end that level data will be sent, using the following values:

URL : game.send_savedatarequest_URL
Table : game.T_Analytics
Callback Attribute : self.callback1




Step 8.

Follow this by a Rule, to trigger on a successful callback from the previous network behavior:

when self.callback1 = 1

In the body of the Rule behavior, enter the following:

  • A "Get Table From URL" behavior with the following values:

    URL : game.get_savedatatoken_URL..game.UserID.."&TK="..self.PrivateTokenID
    Table : game.T_Analytics
    Callback Attribute : self.callback2



Step 9.

Create another Rule, to trigger on a successful callback from the previous network behavior:

when self.callback2 = 1

In the body of the Rule behavior, enter all of the following:

  • A "Change Attribute" behavior to store the Public Token-ID just received:

    self.PublicTokenID = tableCellValue(game.T_Analytics,1,1)

  • A "Copy Table" behavior to make a temporary copy of your game data:

    Copy : game.T_LevelData (This is the table containing your current game level which you wish to share.)
    To : game.T_LevelData_Shared

  • Now use a "Add/Remove Row" behavior to add a row at the beginning of the temporary table. This will contain the Public Token-ID:

    Table : game.T_Analytics
    Action : Add Row, At Beginning

  • Call a "Change Table Vlaue" behavior to fill the first row with the Public Token-ID. Please note, this value can be placed into any column on the first row, but needs to be placed in a column of type "Text". This is for sake of flexability.

    Table : game.T_LevelData_Shared
    Row : 1
    Column : 1 (as mentioned above, this may be any column of type "text")
    Value : "(AFUPT)"..self.PublicTokenID



Step 10.

Lastly, use a "Send Table To URL" network behavior to send the level data to the back-end:

URL : game.send_savedatacommit_URL
Table : game.T_LevelData_Shared
Callback Attribute : self.callback3

Finally, check self.callback3 for a success state of 1.

Your level data has now been saved to the back-end server and you have received a Public Token-ID (self.PublicTokenID) which may be shared with other players. Display this Public Token-ID to the user, or give him/her the facility to share it via social media.





Retrieving a Public Game Level from the back-end server.


Step 11.

In the actor to be used for the following network behaviors, create one networking callback attribute, as well as a Public Token-ID attribute which should contain the Public Token-ID of the level you will wish to retrieve from the server:

self.callback1 (of type integer)
self.PublicTokenID (of type text)




Step 12.

Now create a "Timer (After 0 seconds, Run to completion)" behavior. The next step will be created inside the body of this Timer.




Step 13.

Add a "Get Table From URL" behavior with the following values:

URL : game.get_savedatatable_URL.."&TK="..self.PublicTokenID
Table : game.T_LevelData_Shared
Callback Attribute : self.callback1


A success flag of 1 in the self.callback1 attribute will let you know that the level has been retrieved from the server. You may now move the contents of the game.T_LevelData_Shared table to the main game level table as needed.

Please be aware that the first row of the game.T_LevelData_Shared table still contained the Public Token-ID. That means that your game level data only starts at row 2 in the table.