jQuery Separator Events

Because the Value Separator is a per game property, if you plan on sending/receiving values in your messages it is always a good idea for the client (not the game) to first ask the game what the correct separator is by triggering CKjsMessageSeparatorQ. The game will send the response by triggering the CKjsMessageSeparatorA event.

CKjsMessageSeparatorQ

This is a simple event that will cause the game to immediately respond with a CKjsMessageSeparatorA event (this response doesn't require any handling/configuration in the Construct 2 game). To trigger it just use the standard jQuery Trigger method like below:

$(document).trigger('CKjsMessageSeparatorQ','');

 

CKjsMessageSeparatorA

This is a simple event you will want to register a response for in order to capture the game's separator. You'll want to do this before triggering the Q event above. You can do this like so:

$(document).on('CKjsMessageSeparatorA',function(e,m){//some code here});

 

Simple Example

$(document).ready(function(){
var jsSeparator = '';

//respond to the Separator Answer
$(document).on('CKjsMessageSeparatorA',function(e,m){
jsSeparator = m;

//Send a message with values
$(document).trigger('CKjsMessageSend','MyCommand' + jsSeparator + 'Value1' + jsSeparator + 'Value2');
});

//Ask the game what the Separator is
$(document).trigger('CKjsMessageSeparatorQ','');
});

Last edited Jan 20, 2015 at 6:16 PM by theChrisKent, version 2