question

Kim Strasser avatar image
Kim Strasser asked

I have some issues with creating rules

I get this error message. What is wrong with my rule? Title is over the limit of 3 for ActionTriggerCount. No more can be created until some are deleted.

It's the first time that I create a rule. I want to create a rule that checks if the player has finished the current level the very first time. I f yes, then create a rating based on his score and add 100 gold coins to his account.

https://api.playfab.com/docs/tutorials/landing-automation/using-cloud-script-actions-with-playstream

I followed this tutorial but I'm not sure if my CloudScript is correct.

What are the last two lines doing? Are they necessary?

var content = JSON.stringify({user: profile.PlayerId, event: psEvent.EventName});
var response = http.request('https://httpbin.org/status/200', 'post', content, 'application/json', null, true);

Is it possible to get the rating somehow displayed in the client or is it not possible to return something from the function handlePlayStreamEventFirstTimeLevelFinished in my game?

CloudScript:

handlers.UpdateLeaderboard = function (args, context)
{
    ...
    var isfirsttime = true;
    var resultevent = server.WritePlayerEvent({
                                      PlayFabId: currentPlayerId,
                                      EventName: "player_finished_level_first_time",
                                      Body: {
                                      "IsFirstTime": isfirsttime.toString(),
                                      "Comment": "The player finished this level the first time.",
                                      "Level": args.Level.toString(),
                                      "Playerscore": args.Playerscore.toString()
                                      }
                                      });
                                      
    if (resultevent.Error == null)
        log.info("Writing player_finished_level_first_time event successful.");
    else
        log.info("Writing player_finished_level_first_time event not successful.");
}


handlers.handlePlayStreamEventFirstTimeLevelFinished = function (args, context)
{
    // The event that triggered the action
    // (https://api.playfab.com/playstream/docs/PlayStreamEventModels)
    var psEvent = context.playStreamEvent;
	
    // The profile data of the player associated with the event
    // (https://api.playfab.com/playstream/docs/PlayStreamProfileModels)
    var profile = context.playerProfile;
    
    var level = context.Level;
    var playerscore = context.Playerscore;
    var rating = "";
    
    if (Number(playerscore) < 50)
    {
        rating = "Not bad for your first time.";
        server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GO", Amount: "100"});
    }
    if ((Number(playerscore) >= 50) && (Number(playerscore) < 150))
    {
        rating = "The first time and already a professional.";
        server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GO", Amount: "100"});
    }
    if (Number(playerscore) >= 150)
    {
        rating = "Is this the first time you played this level? This was amazing!";
        server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GO", Amount: "100"});
    }
    
    log.info("Level: " + level + "Your highscore: " + playerscore + " " + rating);
    log.info("Congratulations! You just got 100 gold coins for finishing " + level + " the first time.");
	
    // Post data about the event to an external API
    var content = JSON.stringify({user: profile.PlayerId, event: psEvent.EventName});
    var response = http.request('https://httpbin.org/status/200', 'post', content, 'application/json', null, true);
	
    return { externalAPIResponse: response };
}
CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

All PlayStream Actions count against that limit. That includes the "Entered segment" and "Left segment" Actions in your segment definitions. Right now, you have three Actions defined in your player segments.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.