A - What can I display?
Goal: Dump the contents of the gmcp to the screen.
Create an Alias that will output the information to screen
- Click on Settings button in lower right corner
Click on the Aliases tab
Click on the Add new alias button in the lower left corner
In the Command text box type: showgmcp
Under the Script Type, select Javascript
Add the below code to the script body
Click save
Code: Select all
gwc.output.append('gmcp: ' + JSON.stringify(gwc.gmcp.data));
What can this data do for us?
We could create another alias that moves us a random direction but not take the 'out' exit
Code: Select all
var room = gwc.gmcp.data.room;
var index = Math.floor(Math.random() * (room.exits.length));
var nextRoom = room.exits[index];
if (nextRoom && nextRoom != 'out')
{
gwc.connection.send(nextRoom);
}
Goal: Reference data from another Alias or Trigger
Create an alias that modifies the behavior of a trigger passing information with the gwc.userdata
- Click on Settings
Click on Alias Tab
Click on Add new alias
Enter the Command Name: enable_scavaging
Enter the Code
Code: Select all
if (args['*'] == 'on') {
gwc.userdata.scavaging = true;
} else {
gwc.userdata.scavaging = false;
}
- Click Save
Click on Triggers Tab
Add new trigger
Enter Patter: You killed
Code: Select all
if (gwc.userdata.scavaging)
{
gwc.connection.send('get all from corpse');
}
Now while the above only uses a Boolean you can hold objects in the userdata dictionary. What name can you select? Any. As a javascript object, just make up a name and stick it on the end of userdata. One thing you must keep in mind, is that it is send back to the server between requests. It is best to keep this light.
Alternative storage methods to be investigated.
HTML5 Web DB
Web Service on http://localhost/
C - How can I count to ten with a delay when no messages arrive to be triggered upon?
Goal: Perform a series of steps with a time delay
Create an alias that gets your character to count to ten slowly
- Click on Settings
Click on Alias Tab
Click on Add new alias
Enter the Command Name: count_to_ten
Enter the below code
Click Save
Code: Select all
var Counter = function()
{
var self = this;
self.count = 0;
self.IncrementCount = function()
{
self.count++;
if (self.count <= 10)
{
gwc.connection.send('\'' + self.count + ' mississippi');
setTimeout(self.IncrementCount, 2000);
}
else
{
gwc.connection.send('\'Over 10');
}
};
};
var c = new Counter();
setTimeout(c.IncrementCount, 2000);