Sorry, the script was missing some lines!
var myChallenge = Spark.getChallenge( Spark.data.challengeInstanceId ); Spark.lock( myChallenge ); // Log. if ( Spark.getPlayer().getPlayerId() == myChallenge.getChallengedPlayerIds()[ 0 ] ) Spark.getLog().debug( "I'm Player A" ); else Spark.getLog().debug( "I'm Player B" ); // Save this player's actions. var playerActions = Spark.getData().PLAYER_ACTIONS; myChallenge .setPrivateData( Spark.getPlayer().getPlayerId(), playerActions ); // Log. var playerA_actions = myChallenge .getPrivateData( myChallenge .getChallengedPlayerIds()[ 0 ] ); var playerB_actions = myChallenge .getPrivateData( myChallenge .getChallengerId() ); if ( playerA_actions == null ) Spark.getLog().debug( "Player A actions = NULL" ); if ( playerB_actions == null ) Spark.getLog().debug( "Player B actions = NULL" ); if ( playerA_actions != null && playerB_actions != null ) { // TODO: If both player actions are present, send the actions to each player. myChallenge.removePrivateData( myChallenge.getChallengedPlayerIds()[ 0 ] ); myChallenge.removePrivateData( myChallenge.getChallengerId() ); } Spark.unlock( myChallenge );
Hi Jon,
We have recently identified an issue with Spark.lock. We're currently working on a fix and will be addressing it in an upcoming release. You can keep an eye on the announcement page here for any updates relating to this. I'll also update this thread when it has been addressed.
Thanks,
Liam
Has this issue been resolved? We too are seeing unexpected results during concurrency testing.
Jon Alonso
Hello,
I'm getting some unexpected results when 2 clients ( A and B ) try to execute the same script at approximately the same time:
If A gets the lock first, I'd expect to obtain the following output on the log:
I'm Player A
Player B actions = NULL
I'm Player B
But instead of that, sometimes (not most of the time) I get the following output:
I'm Player A
Player B actions = NULL
I'm Player B
Player A actions = NULL
What do you think might me causing this behaviour?
Thanks for your help!
Jon