question

MoonHeonYoung avatar image
MoonHeonYoung asked

ProgressiveReward sample cloud script question!

Hi While studying the ProgressiveReward cloud script,

I have a question that I do not know.

I am not good at JavaScript syntax

At line 1,

why is the tracker initialized to {}?

If you are going to assign it, do not you need to initialize it?

In step 2, does the json.parse () function create an object in parentheses in json format? (Eg test: 1> {"test": 1} ???)

3. I do not know the exact usage of json.stringify ...

The tutorial should return a serializable object. It's called In this case, is it just returning the default dummy object?

I did not understand the meaning of each line from 4 to 7 at all.

I do not know what date.now is, and I do not know what to do in the if statement.

I would really appreciate it if you give me a detailed explanation on each line.

ps. Do I need to study JavaScript to be good at cloud scripting?

1241241.png (141.5 KiB)
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

·
Seth Du avatar image
Seth Du answered

Question1, first line quesiton:

This is simply because you have to define a variable before you use it.

It actually doesn’t matter how you initialize it because the following codes will check if the player owns this property, if not, function ResetTracker() will be called to actually initiate tracker.

Question2, JSON.parse() and JSON.stringify:

Cloud Script is based on V8 JavaScript Engine for now. Json usage will be the same as JavaScript documentation, and you can refer to: JSON.parse() and JSON.stringify.

Question3, about the lines you don’t understand:

First of all, Date.now will Return the number of milliseconds since 1970/01/01, please see: JavaScript now() Method.

The main idea of this sample is that a timestamp that player last checks in will be recorded. Next time player clicked the check in button, former timestamp will be compared with current time. If it is less than 24 hours or larger than 48 hours, check-in is invalid, because you have to continuously check-in and you cannot escape any day for a week.

Anyway, you still need basic JavaScript knowledge to write Cloud Script and because it is V8 engine (it is more like a clean version), there is no 3-rd party plugins or external modules for extra learning. I think you will get used to it very soon.

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.

MoonHeonYoung avatar image MoonHeonYoung commented ·

Thanks for the answer., !!

There is one more question.

In the cloud code,

why use JSON.stringify (data) Is updating server.UpdateUserReadOnlyData ();

As shown in the screenshot, CheckInTracker stores strings.

Why is not json stored in CheckInTracker, and why is the string stored?

Is this method effective? In any document, When I receive data from a web server,

I always get it as a string, Is this the reason?

The cloud code is also an athorize server,

so is it going to work with string and parse to communicate with web server (playfab)?

I want to know the process and principle of CheckInTracker key generation.

0 Likes 0 ·
3463463463.png (42.0 KiB)
Seth Du avatar image Seth Du ♦ MoonHeonYoung commented ·

It's just a choice. ProgressiveReward is a sample to show you the usage of PlayFab, you can either store JSON object or string in the player data field. Only be aware that when you call GetUserData API, the value field of a data key will always be String, which means it will contain escape characters.

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.