question

Kim Strasser avatar image
Kim Strasser asked

Rule is not correctly executed when I use a condition

I want to execute a Cloud Script function after the player purchased a certain item in my shop. I created a rule and I use the event type com.playfab.player_inventory_item_added. But the rule is only applied correctly when I don't use conditions. When I use conditions in my rule, then my Cloud Script function is never executed.

I have tried it with the conditions 0 and "0" for CustomTags.

In my shop, I purchase this item and the tag value is 0.

When I purchase this item, then my Cloud Script function is not executed when I use the condition 0 for CustomTags in my rule. What am I doing wrong? Why is my rule not executed when I use a condition?

I only want that the Cloud Script function is executed when an items tag is 0 or 1. How can I do that?

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

·
Sarah Zhang avatar image
Sarah Zhang answered

The CustomTags aren’t the item’s tags, they mean the tags of PlayStream Events. For your case, it’s the property of player_inventory_item_added event. Please refer to this documentation for more info about it. If you didn’t define the CustomTags of the event when you call the API PurchaseItem, the CustomTags would be null, the corresponding actions won’t be triggered.

If you want to execute the CloudScript function when the added item’s tag is 0 or 1, you can add the judgement for item’s tag in the CloudScript function directly.

2 comments
10 |1200

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

Kim Strasser avatar image Kim Strasser commented ·

1) I have tried to use CustomTags but my CloudScript function is not executed when I use "Playertag": "0". I don't know how to set the condition correctly. I use the following custom tags:

"EventName": "player_inventory_item_added",

"CustomTags": {
        "Playertag": "0"
    },

I have tried it with string value is 0, Playertag and Playertag: 0. But none of these conditions are working, my CloudScript function is never executed.

What should I enter in the conditions text box so that my condition is true when CustomTags is Playertag: 0 ?

2) If you want to execute the CloudScript function when the added item’s tag is 0 or 1, you can add the judgement for item’s tag in the CloudScript function directly.

I don't know how to get the item's tag in CloudScript. I created a rule without conditions and my CloudScript function is executed but context.playStreamEvent.Tags is always undefined. But I need to find out if the item's tag is 0 or 1.

handlers.AddTicketPlayerTag = function (args, context)
{
    var itemtag = context.playStreamEvent.Tags;
    log.info("tags :" + itemtag);

}

How can I get the item's tag in my CloudScript function?

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Kim Strasser commented ·

Please refer to the following code to get the item's tag.

handlers.retreiveItemTags = function (args, context) {

    var playstreamEvent = context.playStreamEvent;
    var itemId = playstreamEvent.ItemId;
    var request = {
        CatalogVersion: "Main"
    };
    var result = server.GetCatalogItems(request);
    var itemObj = result.Catalog.find(function (obj) {
        return obj.ItemId === itemId
    });

    var tags = itemObj.Tags;
    if (tags[0] === "0") {
        //grant reward
        return { tags: tags, reault: "granted" };
    } else {
        return { tags: tags, reault: "tags don't meet the condition" };
    }
};
0 Likes 0 ·

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.