Sign In Register

How can we help you today?

Start a new topic

Challenge takeTurn is not firing ChallengeTurnTakenMessage to user


I have problem testing new features which I am trying to implement to our game. The problem is in Preview Mode.

Basically I've setup bots for my game and the problem happens while playing with bot user.

Some info about my projects:

I've created a module which have some calculations depending on game board and decides which position to play for bot user. The thing is that I want to create some delay before sending the bot's move to the other player. So I decided to use scheduler for that purpose and here is what I am doing.

In my main module where goes all the calculations I have this:


var position = choice;
    if(position !== undefined){
        var delaySeconds =  Math.floor((Math.random() * 5) + 2);
        scheduler.inSeconds("botMove", delaySeconds, 
        {"botId" : botId, "challengeId":challengeId, "position": position, "botSign":botSign, "playerId": Spark.getPlayer().getPlayerId()  }, botId);


This code is working correctly, it starts botMove after delaySeconds, where I am doing this:


var botId = Spark.getData().botId;
var challengeId = Spark.getData().challengeId;
var position = Spark.getData().position;
var botSign = Spark.getData().botSign;
var playerId = Spark.getData().playerId;

Spark.logEvent("takeTurn", {"playerSign" : botSign, "position": position});
var challenge = Spark.getChallenge(challengeId);
challenge.setScriptData("position", position);
challenge.setScriptData("playerSign", botSign);

var runtimeCollection = Spark.runtimeCollection(challengeId);{"_id": position, "position": position, "playerSign": botSign});


If I put some logs in botsMove I can see that this script is called by my main module, but  the user never receives ChallengeTurnTakenMessage event so it can see the move.


Are you invoking a Log Challenge Event or just a normal log event?



I am using 


 I've tried using this


var request = new SparkRequests.LogChallengeEventRequest();
request.challengeInstanceId = ...;
request.eventKey = ...;
var response = request.Send();

var scriptData = response.scriptData;

 , but it's not firing ChallengeTurnTakenMessage too.

Hi Illiq,


If the SparkRequest LogChallengeEventRequest is for the bot to take their turn in Cloud Code you need to use the following.


var response = request.SendAs(botId); //botId = the userId of the bot. 


You'll also need to make sure that the takeTurn event is set up as the turn consumer in the challenge and that you are supplying a valid challengeInstanceId. Try that and let us know if you require any further assistance.




Have you set Turn / Attempt Consumers in your Challenge configuration screen?


Yes, everything is set up properly. If I remove the scheduler part and use the code directly to send the event without any delays it is working. The problem is that when the event is sent inside module which is called by the scheduler. In that case ChallengeTurnTakenMessage is not received by the user.

Right now the problem is that it is still not working. Doesn't matter if I use 



 as you suggested. The event and challenges are configured properly, but trying make a move from cloud code doesn't send  ChallengeTurnTakenMessage to the user.

Is there anything which I can do to fix this issue?

Hi Illiq, 

I see you've marked this as solved. May I ask what the issue was in the end ?



Login to post a comment