Difference between revisions of "Game Cloud"

From Virtual World Web Wiki
Jump to: navigation, search
Line 38: Line 38:
 
Your scripts must first set their application context, and then can query these values like so:
 
Your scripts must first set their application context, and then can query these values like so:
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
Cloud.SetApplication("vww.apps.example");
+
Cloud.SetApplication("vww.apps.reference");
  
 
var message = Cloud.GetMetadata("StartupMessage");
 
var message = Cloud.GetMetadata("StartupMessage");
Line 50: Line 50:
 
=== Data Storage ===
 
=== Data Storage ===
 
Application Data Storage allows your scripts to store and retrieve key / value pairs associated with different objects. There are three different stores of application data:
 
Application Data Storage allows your scripts to store and retrieve key / value pairs associated with different objects. There are three different stores of application data:
:***Application Global Data***: These key / value pairs are stored globally for your entire application. Their keys must be unique within the scope of your entire application.
+
:'''Application Global Data''': Stored globally for your entire application. Their keys must be unique within the scope of your entire application. Use the <code>HasData</code>, <code>GetData</code>, <code>SetData</code> and <code>DeleteData</code> methods on the [[Cloud Global]] object.
:***Account Scoped Data***: These key / value pairs are stored for each user account. This allows your application to store some value shared among all Personae (avatars) of a user, so no matter which avatar they're logged in as, these values will be available. Their keys must be unique withing the scope of a single user account.
+
:'''Persona Scoped Data''': Stored for each Persona (avatar). This allows you to store information on a specific character in the game world. Their keys must be unique withing the scope of a single persona. Use the <code>HasData</code>, <code>GetData</code>, <code>SetData</code> and <code>DeleteData</code> methods on any [[ParticipantExtended]] object.
:***Persona Scoped Data***: These key / value pairs are stored for each Persona (avatar). This allows you to store information on a specific character in the game world. Their keys must be unique withing the scope of a single persona.
+
:'''Account Scoped Data''': Stored for each user account. This allows your application to store some value shared among all Personae (avatars) of a user, so no matter which avatar they're logged in as, these values will be available. Their keys must be unique withing the scope of a single user account. Use the <code>HasAccountData</code>, <code>GetAccountData</code>, <code>SetAccountData</code> and <code>DeleteAccountData</code> methods on any [[ParticipantExtended]] object.
  
 
Your scripts must first set their application context, and then can work with these values like so:
 
Your scripts must first set their application context, and then can work with these values like so:
  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
Cloud.SetApplication("vww.apps.example"); // set your application context
+
Cloud.SetApplication("vww.apps.reference"); // set your application context
  
 +
var maxPlayers = Number(Cloud.GetMetadata("MaxPlayers"));
 +
Log.WriteDebug("Starting up. Maximum Players: " + maxPlayers);
  
 +
Instance.OnEnter = function(/*ParticipantExtended*/ part){
 +
    // A new participant has joined the scene
 +
    if(Cloud.DataExists("PlayerCount")){
 +
        var count = Number(Cloud.GetData("PlayerCount")) + 1;
 +
        if(count >= maxPlayers) {
 +
            part.SendChatMessage("Sorry, only " + maxPlayers + " players allowed.");
 +
            return;
 +
        }
 +
        Cloud.SetData("PlayerCount", String(count));
 +
        part.SendChatMessage("Welcome, there are " + count + " players.");
 +
    }else{
 +
        Cloud.SetData("PlayerCount", "1");
 +
        part.SendChatMessage("Welcome, you are the only player.");
 +
    }
  
 +
    part.SetData("Playing", true);
 +
    Chat.GetLocalChannel().Broadcast(part.Name + " joined the game!");
 +
 +
    if(part.DataExists("PlayCount")){
 +
        var plays = Number(part.GetData("PlayCount")) + 1;
 +
        part.SetData("PlayCount", String(plays));
 +
        part.SendChatMessage("You have played before.");
 +
    }else{
 +
        part.SetData("PlayCount", "1");
 +
        part.SendChatMessage("This is your first play.");
 +
    }
 +
};
 +
Instance.OnLeave = function(/*ParticipantExtended*/ part){
 +
    if(!part.DataExists("Playing"))
 +
        return;
 +
    part.DeleteData("Playing");
 +
    Cloud.SetData("PlayerCount", String(Number(Cloud.GetData("PlayerCount")) - 1));
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 15:35, 23 August 2019

The Game Cloud is a Layer Two component that extends your server to add many common massively multiplayer role playing game (MMORPG) features as well as a suite of server world scripting extensions that simplify game programming.

Game Cloud Scripting

The Game Cloud offers a large extension to the server JavaScript environment. The main API access points are through the two global objects Cloud and Bot. I will provide scripting examples throughout this document. For more information about writing scripts for use in the world see Scripts and the World Scripting Reference.

Game Cloud Applications

The Game Cloud groups configuration and data storage into containers called Applications. An application can be developed, configured, and tested on your development server, and then published to your live server when you're ready. All of the application's associated objects move with the application as a single unit when transferred.

Developing an Application

Game Cloud applications are created and configured mostly through the Admin Web. Expand Game Cloud on the left navigation menu, and select Applications. Create a test application to get started. See Identifiers and Scope below for advice on selecting a good identifier for your application.

Once created, you can begin creating other Game Cloud objects (features) that will become part of your application. The objects you create will then be available for your world scripts to interact with. More complete examples of how this works will be given below.

Identifiers and Scope

The Game Cloud makes heavy use Identifiers which are strings of text that uniquely identify some object within a scope. Your application will have an identifier, as will most of the things you create within your application.

Good identifiers should use namespacing to help ensure they are unique. Identifiers should not contain spaces. I recommend you use a format like this:

company.feature.name

For Example

vww.quests.firstquest

This helps ensure that things created by different companies or teams don't interfere with each other.

Generally speaking, identifiers are global in scope. This means they should be unique across all applications on your server. This is because an application groups objects for transfer, but does not provide a naming container. This is so that scripts and features from one application can interact with scripts and features from another application.

Data Storage and Scope

The Game Cloud offers several ways for your scripts to store and retrieve data. These are explained in Metadata and Data Storage sections. Data storage is always associated with (scoped to) an application. When a script wants to work with application data, it must first set an application context like so:

Cloud.SetApplication("vww.apps.example");

Generally, application data is considered to be "server local". This means that your application's stored data is not transferred between servers with the application. This is because the data stored by your scripts represents the runtime state of your world. What is transferred is the ``configuration`` of your Game Cloud features and also any Metadata stored with your application.

Application Features

Metadata

Application Metadata is a simple way for you to set some key / value pairs in the admin that will be available to your script at run-time. These values cannot be changed by your scripts. You can think of these as configuration values. They are configured on your application's Summary tab.

Your scripts must first set their application context, and then can query these values like so:

Cloud.SetApplication("vww.apps.reference");
 
var message = Cloud.GetMetadata("StartupMessage");
 
Debug.Log("Starting up with message: " + message);
Chat.GetLocalChannel().Broadcast(message);

The example above shows how the value of the StartupMessage metadata item can be retrieved and used to broadcast a chat message into the instance local chat. For more information see Cloud Global, Chat Global, ChatChannelExtended and Debug Global in the World Scripting Reference.

Data Storage

Application Data Storage allows your scripts to store and retrieve key / value pairs associated with different objects. There are three different stores of application data:

Application Global Data: Stored globally for your entire application. Their keys must be unique within the scope of your entire application. Use the HasData, GetData, SetData and DeleteData methods on the Cloud Global object.
Persona Scoped Data: Stored for each Persona (avatar). This allows you to store information on a specific character in the game world. Their keys must be unique withing the scope of a single persona. Use the HasData, GetData, SetData and DeleteData methods on any ParticipantExtended object.
Account Scoped Data: Stored for each user account. This allows your application to store some value shared among all Personae (avatars) of a user, so no matter which avatar they're logged in as, these values will be available. Their keys must be unique withing the scope of a single user account. Use the HasAccountData, GetAccountData, SetAccountData and DeleteAccountData methods on any ParticipantExtended object.

Your scripts must first set their application context, and then can work with these values like so:

Cloud.SetApplication("vww.apps.reference"); // set your application context
 
var maxPlayers = Number(Cloud.GetMetadata("MaxPlayers"));
Log.WriteDebug("Starting up. Maximum Players: " + maxPlayers);
 
Instance.OnEnter = function(/*ParticipantExtended*/ part){
    // A new participant has joined the scene
    if(Cloud.DataExists("PlayerCount")){
        var count = Number(Cloud.GetData("PlayerCount")) + 1;
        if(count >= maxPlayers) {
            part.SendChatMessage("Sorry, only " + maxPlayers + " players allowed.");
            return;
        }
        Cloud.SetData("PlayerCount", String(count));
        part.SendChatMessage("Welcome, there are " + count + " players.");
    }else{
        Cloud.SetData("PlayerCount", "1");
        part.SendChatMessage("Welcome, you are the only player.");
    }
 
    part.SetData("Playing", true);
    Chat.GetLocalChannel().Broadcast(part.Name + " joined the game!");
 
    if(part.DataExists("PlayCount")){
        var plays = Number(part.GetData("PlayCount")) + 1;
        part.SetData("PlayCount", String(plays));
        part.SendChatMessage("You have played before.");
    }else{
        part.SetData("PlayCount", "1");
        part.SendChatMessage("This is your first play.");
    }
};
Instance.OnLeave = function(/*ParticipantExtended*/ part){
    if(!part.DataExists("Playing"))
        return;
    part.DeleteData("Playing");
    Cloud.SetData("PlayerCount", String(Number(Cloud.GetData("PlayerCount")) - 1));
}

Dependencies

Groups

Abilities

Tokens

Quests

Achievements

Dialogs

Locks

Avatar System

Engagement System

Other Helpful Utilities

Bound Objects