Cloud Scripting
Learn how to use Cloud Scripting to run custom server-side logic in Cratebytes.
Cloud Scripting Documentation
Cloud Scripting in Cratebytes enables developers to execute server-side JavaScript code to manage and validate data dynamically. This feature can be utilized across different gameplay events, providing flexibility and control over player data. Please note that, currently, custom npm packages cannot be used within Cloud Scripting, though support for this is coming soon.
Custom npm packages are not yet supported but will be available in future updates.
Supported Events
Cloud Scripting currently supports the following events:
- GameplayStart: Triggered when a gameplay session starts.
- GameplayEnd: Triggered when a gameplay session ends.
- LeaderboardSubmit: Triggered when a player submits a score to a leaderboard.
- MetadataAdd: Triggered when metadata is added or updated for a player.
- MetadataDelete: Triggered when metadata is deleted for a player.
Example Usage
Each event comes with predefined script templates to guide you in implementing custom logic.
Event: Gameplay Start
The Gameplay Start event triggers when a player begins a gameplay session. This event allows developers to execute custom logic that can validate player information, initialize session data, or apply other rules at the beginning of a session.
Use Cases
- Ensuring player eligibility: Check if the player meets certain criteria to start the session, like account status or minimum required playtime.
- Dynamic adjustments: Modify gameplay parameters dynamically, such as adjusting difficulty based on the player’s previous performance.
Sample Input:
Event: Gameplay End
The Gameplay End event triggers when a player completes a gameplay session. This event offers developers an opportunity to validate the session, analyze player behavior, and decide whether or not to save the session’s data. It’s useful for performing various post-gameplay tasks that can enhance player experience, support data tracking, and improve gameplay analytics.
Use Cases
- Session Validation
Use this event to verify the integrity of the gameplay session. For instance, if the session duration (gameplayDuration
) is unusually short or suspiciously long, you may want to log these anomalies or flag them for further investigation. By validating gameplay data at this point, you can help maintain accurate session records and prevent misuse.
Sample Input:
Event: Leaderboard Submit
The Leaderboard Submit event triggers when a player submits a score to a leaderboard. This event enables developers to validate, adjust, or selectively save leaderboard scores based on specific conditions, enhancing the fairness and functionality of leaderboard systems.
Use Cases
-
Validating Score Integrity Ensure the submitted score meets certain criteria, such as a minimum score threshold or a maximum allowable score. This helps prevent artificially inflated or unrealistic scores from being posted to leaderboards, maintaining a fair competitive environment.
-
Guest Player Restrictions Restrict guest players from submitting scores to certain leaderboards, or apply different scoring logic for guest accounts. By filtering out or limiting guest scores, developers can encourage account creation while ensuring leaderboard authenticity.
-
Dynamic Score Adjustments Adjust the score before submission based on the player’s session details or historical performance. For example, you could apply bonuses to frequent players or introduce penalties based on recent gameplay metrics, providing an additional layer of engagement and competitiveness.
Sample Input:
Event: Metadata Add
Runs when metadata is added or updated for a player.
Sample Input:
Event: Metadata Delete
Runs when metadata is deleted for a player.
Sample Input: