fix typo in comments and improved examples for the foreach function

This commit is contained in:
walterhiggins 2013-08-03 13:50:06 +01:00
parent df56b53593
commit c7b2786a8a
2 changed files with 26 additions and 8 deletions

View file

@ -1312,10 +1312,19 @@ Example
The following example illustrates how to use foreach for immediate processing of an array...
var players = ["moe", "larry", "curly"];
foreach (players, function(item){
utils.foreach (players, function(item){
server.getPlayer(item).sendMessage("Hi " + item);
});
... The `utils.foreach()` function can work with Arrays or any Java-style collection. This is important
because many objects in the Bukkit API use Java-style collections...
utils.foreach( server.onlinePlayers, function(player){
player.chat("Hello!");
});
... the above code sends a "Hello!" to every online player.
The following example is a more complex use case - The need to build an enormous structure
without hogging CPU usage...
@ -1335,7 +1344,7 @@ without hogging CPU usage...
var onDone = function(){
player.sendMessage("Job Done!");
};
foreach (a, processItem, null, 10, onDone);
utils.foreach (a, processItem, null, 10, onDone);
utils.nicely() function
=======================
@ -1379,9 +1388,9 @@ Example
To warn players when night is approaching...
utils.at( "19:00", function(){
utils.at( "19:00", function() {
/* it's 7 in the evening so warn all players that night is coming ! */
utils.foreach(server.onlinePlayers, function(player){
utils.foreach( server.onlinePlayers, function(player){
player.chat("The night is dark and full of terrors!");
});
}, self.world);

View file

@ -71,10 +71,19 @@ Example
The following example illustrates how to use foreach for immediate processing of an array...
var players = ["moe", "larry", "curly"];
foreach (players, function(item){
utils.foreach (players, function(item){
server.getPlayer(item).sendMessage("Hi " + item);
});
... The `utils.foreach()` function can work with Arrays or any Java-style collection. This is important
because many objects in the Bukkit API use Java-style collections...
utils.foreach( server.onlinePlayers, function(player){
player.chat("Hello!");
});
... the above code sends a "Hello!" to every online player.
The following example is a more complex use case - The need to build an enormous structure
without hogging CPU usage...
@ -94,7 +103,7 @@ without hogging CPU usage...
var onDone = function(){
player.sendMessage("Job Done!");
};
foreach (a, processItem, null, 10, onDone);
utils.foreach (a, processItem, null, 10, onDone);
***/
foreach: function(array, callback, object, delay, onCompletion) {