AirConsole version 1 - Little expression guide

Favourite 6 favourites
Tutorial written by Psychokiller1888Originally published on 9th, January 2017 - 4 revisions

THIS PLUGIN IS DEPRECATED AND WAS REPLACED WITH THE PLUGIN VERSION 2

New guide: https://www.scirra.com/tutorials/9473/airconsole-little-expression-guide

AirConsole plugin

Intro

Ho ho ho, welcome to this second tutorial, which is more a guide or roadmap for your creations using the AirConsole Construct 2 plugin version 1.

You will learn about the plugin's expressions and their uses

What's needed

- Construct2 obviously
- The AirConsole plugin version 1.4.8
- - Official repo: https://github.com/AirConsole/airconsole-construct2
- - My repo: https://github.com/Psychokiller1888/airconsole-construct2

Expressions listing by category

- Data
- - Message
- - MessageKey (deprecated!)
- - DeviceUID

- IDs
- - DeviceID
- - DeviceIDJoin
- - DeviceIDLeft
- - ControllerDeviceIDs
- - MasterControllerDeviceID

- Profile
- - NicknameJoin
- - Nickname
- - ProfilePicture
- - ProfilePictureJoin

- Functions
- - ConvertPlayerNumberToDeviceId
- - ConvertDeviceIdToPlayerNumber
- - GetUID
- - GetNickname
- - GetProfilePicture

- Premium
- - IsPremiumJoin
- - IsPremiumMessage
- - IsPremium

- MessageProperties
- - GetMessageProperties
- - GetMessageProperty
- - GetMessagePropertiesCount
- - IsMessagePropertySet

- Highscores data
- - Highscores

- Persistent data
- - PersistentData

(AirConsole).Message

Description: Contains a message received from a controller
Loaded by: OnMessage
Can be used after: OnMessageIs/OnMessageFrom/OnMessage
Conditions:

(AirConsole).DeviceUID

Description: Contains a deviceUid
Loaded by: OnMessage
Can be used after: OnDeviceJoin/OnPremium
Conditions: Is not set if max players exceeded

(AirConsole).DeviceID

Description: Contains the device id the last message was from
Loaded by: OnMessage/OnPremium
Can be used after: OnDeviceJoin/OnPremium/OnMessageIs/OnMessageFrom/OnMessage/OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions: Not set if it is a connection message, use DeviceIDJoin instead. Not set if it is a disconnection, use DeviceIDLeft instead

(AirConsole).DeviceIDJoin

Description: Contains the device id of the last device that joined
Loaded by: OnMessage
Can be used after: OnTooManyPlayers/OnDeviceJoin/OnPremium
Conditions:

(AirConsole).DeviceIDLeft

Description: Contains the device id of the last device that left the game
Loaded by: onDeviceStateChange
Can be used after: OnDeviceLeft/OnAnyDeviceLeft
Conditions:

(AirConsole).ControllerDeviceIDs

Description: A JSON converted array of all connected devices that have loaded your game. Use C2Dictionary.load() to grab the data
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).MasterControllerDeviceID

Description: Device ID of the master controller. It can be undefined, in that case Construct 2 will return -1
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).NicknameJoin

Description: The nickname of the device which joined in OnDeviceJoin event.
Loaded by: onMessage
Can be used after: OnDeviceJoin/OnPremium
Conditions:

(AirConsole).Nickname

Description: The nickname of the device the message is from in a message trigger.
Loaded by: onMessage
Can be used after: OnMessageIs/OnMessageFrom/OnMessage/OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions: Not set if it is a connection message, use NicknameJoin instead

(AirConsole).ProfilePicture

Description: The profile picture of the device the message is from in a message trigger.
Loaded by: OnMessage
Can be used after: OnMessageIs/OnMessageFrom/OnMessage/OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions: Not set if it is a connection message, use ProfilePictureJoin instead

(AirConsole).ProfilePictureJoin

Description: The profile picture of the device which joined in OnDeviceJoin event.
Loaded by: onMessage
Can be used after: OnDeviceJoin/OnPremium
Conditions: Not set if it is not a connection message, use ProfilePicture instead

(AirConsole).ConvertPlayerNumberToDeviceId

Description: Returns the device_id of a player, if the player is part of the active players previously set by the screen by using SetActivePlayers.
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).ConvertDeviceIdToPlayerNumber

Description: Returns the player number for a device_id, if the device_id is part of the active players previously set by the screen by using SetActivePlayers.
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).GetUID(deviceId)

Description: Returns the globally unique id of a device.
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).GetNickname(deviceId)

Description: Returns the nickname of a device.
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).GetProfilePicture(deviceId)

Description: Returns the profile picture url of a device.
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).IsPremiumJoin

Description: Returns 1 if the last device that joined is premium else 0
Loaded by: onMessage
Can be used after: OnDeviceJoin/OnPremium
Conditions: Not set if it is not a connection message, use IsPremiumMessage instead

(AirConsole).IsPremiumMessage

Description: Returns 1 if the device is premium in a message trigger else 0.
Loaded by: OnMessage
Can be used after: OnMessageIs/OnMessageFrom/OnMessage/OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions: Not set if it is a connection message, use IsPremiumJoin instead

(AirConsole).IsPremium(deviceId)

Description: Returns 1 if the specified device id is premium else 0.
Loaded by: None, only loaded on call
Can be used after: Anytime after the game has loaded
Conditions:

(AirConsole).GetMessageProperties

Description: Returns a recursive C2 dictionary of the keys with values sent in the last message. Use C2Dictionary.Load to grab/traverse the data
Loaded by: OnMessage
Can be used after: OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions:

(AirConsole).GetMessageProperty

Description: Returns the value of the specified key sent in the last message.
Loaded by: OnMessage
Can be used after: OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions: Returns null if the specified property is not set in the last received message

(AirConsole).GetMessagePropertiesCount

Description: Returns how many properties were declared in the last message
Loaded by: OnMessage
Can be used after: OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions:

(AirConsole).IsMessagePropertySet

Description: Returns 1 if the specified property was declared in the last message.
Loaded by: OnMessage
Can be used after: OnMessageKey/OnMessageKeyIs/OnMessageKeyContains
Conditions:

(AirConsole).Highscores

Description: Returns a JSON string representation of the highscores loaded by the last requestHighScores. Use C2Dictionary.Load to grab/traverse the data
Loaded by: onHighScores
Can be used after: OnHighScores
Conditions:

(AirConsole).PersistentData

Description: Returns a JSON string representation of the persistent data loaded by the last requestPersistentData. Use C2Dictionary.Load to grab/traverse the data
Loaded by: onPersistentDataLoaded
Can be used after: OnPersistentDataLoaded
Conditions:

Special cases, important

Message, keys, properties, value etc etc... It's just a mix of a lot of words and that needs to be made clear. When I started to update the plugin there was already stuffs existing, in a more basic way, authorising controller message only these two ways:

Formerly captured by OnMessage

    var airConsole = new AirConsole({"orientation": "landscape"});
    airConsole.message(AirConsole.SCREEN, {
      message: value
    });

OR

Formerly captured by OnMessageKey

    var airConsole = new AirConsole({"orientation": "landscape"});
    airConsole.message(AirConsole.SCREEN, {
      key: value
    });

So technically, we send an object in a JSON format to Construct 2. An object is made of properties having declared values. Exemple

    message: value

In this exemple, the property is "message" and the value is "value"

    key: value

In this exemple the property is "key" and the value is "value"

You cannot use the property name "key" anymore, because of the backward compatibility, this name is reserved for people that may have used the old "OnMessageKey". But this little inconvenience comes with a great plus... You can specify as many properties as your want in your message, and even specify sub properties!

    var airConsole = new AirConsole({"orientation": "landscape"});
    airConsole.message(AirConsole.SCREEN, {
      room: "room1",
      temperature: "22",
      partner: {
        name: "Psycho",
    	room: "room2"
      }

});

Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

View deals

Plus, it's got a lot of additional features that will help you save time and make more impressive games!

Congratulations on finishing this tutorial!

Did you learn a lot from it? Share it now with your friends!

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

1
cjbruce 19.3k rep

Nice work! Not having to send a C2Dictionary makes things so much cleaner!

Monday, January 09, 2017 at 9:16:32 PM
0
anthonykojima 10.1k rep

This is fantastic!
Thanks for writing this. I have the feeling that you'll end up updating this a lot since the plugin is still evolving.
I understand now the problem of backward compatibiliry with the "key" keyword for messages.

Wednesday, January 11, 2017 at 1:50:03 PM
0
Psychokiller1888 4,612 rep

Sure still evolves, I do update it :) I'll keep it updated as long as I update the plugin or AirConsole team does, sure. But there's not much more missing from the API, a few functions maybe, I'll implement them soon anyway

Wednesday, January 11, 2017 at 9:13:24 PM
0
Psychokiller1888 4,612 rep

Updated to plugin 1.4.8

Tuesday, January 31, 2017 at 9:37:23 AM
0
iceangel 33.4k rep

Thanks for sharing!

Saturday, February 04, 2017 at 8:55:25 AM
0
cjbruce 19.3k rep

@Psychokiller1888 put this in another thread, but it is important here:

If you are using the new version of the official V2 AirConsole Controller Generator, you need to use OnMessageKey as a trigger, and load the resulting message into a C2Dictionary with (AirConsole).GetMessageProperty. You should then be able to read the contents of the message.

In order to test what you are receiving from the controller, add a browser.alert() with the following:

Browser -> alert(JSON.stringify(AirConsole.GetMessageProperty))

This will let you see the messages coming in from the controller as a string.

Wednesday, February 08, 2017 at 6:22:17 PM
0
Psychokiller1888 4,612 rep

@cjbruce Thanks for calarification. It's not only for the V2 controller generator, it's true for the old one too. It's important to understand the messaging system, that part: www.scirra.com/tutorials/9415/airconsole-little-expression-guide#h2a29

If you understand that, the whole thing makes sense. In the plugin version 2 that should be coming soon (sorry, no time yet to finalise), I have gotten rid of these "weirdness" and the whole will be easier to implement

Friday, February 17, 2017 at 9:45:22 AM
0
Psychokiller1888 4,612 rep
Thursday, March 30, 2017 at 8:43:07 PM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.