Updated section on booleans. Added subheading on booleans and javabeans.

This commit is contained in:
walterhiggins 2015-04-04 11:27:00 +01:00
parent f97fdc33b5
commit 241c19f640
2 changed files with 96 additions and 50 deletions

View file

@ -28,6 +28,8 @@ If you would like to make changes, change file src/docs/templates/ypgpm.md inste
* [Parameters](#parameters) * [Parameters](#parameters)
* [true or false](#true-or-false) * [true or false](#true-or-false)
* [More fun with `true` or `false`](#more-fun-with-true-or-false) * [More fun with `true` or `false`](#more-fun-with-true-or-false)
* [Booleans and JavaBeans](#booleans-and-javabeans)
* [SIDENOTE](#sidenote)
* [...and Again, and Again, and Again,...](#and-again-and-again-and-again) * [...and Again, and Again, and Again,...](#and-again-and-again-and-again)
* [Counting to 100](#counting-to-100) * [Counting to 100](#counting-to-100)
* [Saying "Hi!" to every player](#saying-hi-to-every-player) * [Saying "Hi!" to every player](#saying-hi-to-every-player)
@ -674,48 +676,70 @@ You can find out if you can Fly in minecraft by typing the following statement .
fly or not. You can turn on and off your ability to fly by setting fly or not. You can turn on and off your ability to fly by setting
your `mayFly` property to `true` or `false`. Try it ... your `mayFly` property to `true` or `false`. Try it ...
/js self.getCapabilities().setMayFly(true) /js self.capabilities.flying = true
/js self.updateCapabilities() /js self.updateCapabilities()
... Now you can fly! To turn off flight ... ... Now you can fly! Double-press the space bar key to start flying. To turn off flight ...
/js self.getCapabilities().setMayFly(false) /js self.capabilities.flying = false;
/js self.setFlying(false)
/js self.updateCapabilities() /js self.updateCapabilities()
... and you come crashing down to earth. This is just one example of ... and you come crashing down to earth. This is just one example of
how `true` and `false` are used throughout ScriptCraft – these are how `true` and `false` are used throughout ScriptCraft – these are
called `boolean` values – named after [George Boole][boole], a 19th Century called `boolean` values – named after [George Boole][boole], a 19th Century
Maths Professor at University College Cork. There are plenty more Maths Professor at University College Cork. There are plenty more
examples of boolean values in Minecraft. You can find out if monsters examples of boolean values in Minecraft. You can find out if it's
are allowed in your minecraft world by typing the following raining in your minecraft world by typing the following statement ...
statement ...
/js self.location.world.allowMonsters /js self.world.raining
... The result of this statement will be either `false` (Phew!) or ... The result of this statement will be either `false` (if it's not raining) or
`true` (Yikes!) depending on how your server has been `true` (if it *is* raining). If it's raining, you can make it stop raining typing the following command:
configured. However, typing the following statement doesn't work as
expected...
/js self.location.world.allowMonsters = true /js self.world.raining = false
... This statement won't work as expected - it will give an Error ... Similarly, to make it start raining you can issue the following command:
message. This is because sometimes we can read variables but we can't
change them the same way we read them (this is because of how
Javascript, Java and the CanaryMod API work together). To turn on or
off the spawning of monsters, type the following...
/js self.location.world.setSpawnFlags(false, true) /js self.world.raining = true
... the `setSpawnFlags()` method takes 2 parameters, the first ### Booleans and JavaBeans
parameter says whether or not monsters can spawn, and the 2nd says
whether or not Animals can spawn. (SIDENOTE: You may be wondering how There are many *boolean* properties you can use to turn on or off
to change other aspects of the Minecraft game - pretty much all certain game behaviours. For example, the *raining* behavior is turned
on or off using the World's `raining` property. The World object's
properties and methods are [documented on the CanaryMod JavaDocs World
page][cmworld]. When browsing the CanaryMod JavaDoc pages, whenever
you see a method whose name begins with `is` such as `isRaining()` and
a companion method `setRaining()`, these methods are called *JavaBean*
methods - the *raining* property is a *JavaBean* property and there
are two ways you can use JavaBean properties in Javascript. You can
*get* and *set* the property using the methods provided by Java. To
*get* the raining property you can call the JavaBean Method:
/js self.world.isRaining()
... or you can get the property like this:
/js self.world.raining
To *set* the raining property, you can call the JavaBean method:
/js self.world.setRaining( true )
... or you can set the property like this:
/js self.world.raining = true
Whatever approach you use, the result will be the same.
[cmworld]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/world/World.html
### SIDENOTE
You may be wondering how to change other aspects of the Minecraft game - pretty much all
aspects of the game can be changed. Changes are made using what are aspects of the game can be changed. Changes are made using what are
called `API` calls - these are calls to functions and methods in called `API` calls - these are calls to functions and methods in
Minecraft - you can read more about these on the [CanaryMod API Minecraft - you can read more about these on the [CanaryMod API
Reference][cmapi].) Reference][cmapi].
## ...and Again, and Again, and Again,... ## ...and Again, and Again, and Again,...
@ -901,7 +925,7 @@ utils.foreach() function...
var utils = require('utils'); var utils = require('utils');
var players = utils.players(); var players = utils.players();
utils.foreach( players, function( player ) { utils.foreach( players, function( player ) {
player.capabilities.setMayFly(true); player.capabilities.flying = true;
player.updateCapabilities(); player.updateCapabilities();
} ); } );
``` ```

View file

@ -631,48 +631,70 @@ You can find out if you can Fly in minecraft by typing the following statement .
fly or not. You can turn on and off your ability to fly by setting fly or not. You can turn on and off your ability to fly by setting
your `mayFly` property to `true` or `false`. Try it ... your `mayFly` property to `true` or `false`. Try it ...
/js self.getCapabilities().setMayFly(true) /js self.capabilities.flying = true
/js self.updateCapabilities() /js self.updateCapabilities()
... Now you can fly! To turn off flight ... ... Now you can fly! Double-press the space bar key to start flying. To turn off flight ...
/js self.getCapabilities().setMayFly(false) /js self.capabilities.flying = false;
/js self.setFlying(false)
/js self.updateCapabilities() /js self.updateCapabilities()
... and you come crashing down to earth. This is just one example of ... and you come crashing down to earth. This is just one example of
how `true` and `false` are used throughout ScriptCraft – these are how `true` and `false` are used throughout ScriptCraft – these are
called `boolean` values – named after [George Boole][boole], a 19th Century called `boolean` values – named after [George Boole][boole], a 19th Century
Maths Professor at University College Cork. There are plenty more Maths Professor at University College Cork. There are plenty more
examples of boolean values in Minecraft. You can find out if monsters examples of boolean values in Minecraft. You can find out if it's
are allowed in your minecraft world by typing the following raining in your minecraft world by typing the following statement ...
statement ...
/js self.location.world.allowMonsters /js self.world.raining
... The result of this statement will be either `false` (Phew!) or ... The result of this statement will be either `false` (if it's not raining) or
`true` (Yikes!) depending on how your server has been `true` (if it *is* raining). If it's raining, you can make it stop raining typing the following command:
configured. However, typing the following statement doesn't work as
expected...
/js self.location.world.allowMonsters = true /js self.world.raining = false
... This statement won't work as expected - it will give an Error ... Similarly, to make it start raining you can issue the following command:
message. This is because sometimes we can read variables but we can't
change them the same way we read them (this is because of how
Javascript, Java and the CanaryMod API work together). To turn on or
off the spawning of monsters, type the following...
/js self.location.world.setSpawnFlags(false, true) /js self.world.raining = true
... the `setSpawnFlags()` method takes 2 parameters, the first ### Booleans and JavaBeans
parameter says whether or not monsters can spawn, and the 2nd says
whether or not Animals can spawn. (SIDENOTE: You may be wondering how There are many *boolean* properties you can use to turn on or off
to change other aspects of the Minecraft game - pretty much all certain game behaviours. For example, the *raining* behavior is turned
on or off using the World's `raining` property. The World object's
properties and methods are [documented on the CanaryMod JavaDocs World
page][cmworld]. When browsing the CanaryMod JavaDoc pages, whenever
you see a method whose name begins with `is` such as `isRaining()` and
a companion method `setRaining()`, these methods are called *JavaBean*
methods - the *raining* property is a *JavaBean* property and there
are two ways you can use JavaBean properties in Javascript. You can
*get* and *set* the property using the methods provided by Java. To
*get* the raining property you can call the JavaBean Method:
/js self.world.isRaining()
... or you can get the property like this:
/js self.world.raining
To *set* the raining property, you can call the JavaBean method:
/js self.world.setRaining( true )
... or you can set the property like this:
/js self.world.raining = true
Whatever approach you use, the result will be the same.
[cmworld]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/world/World.html
### SIDENOTE
You may be wondering how to change other aspects of the Minecraft game - pretty much all
aspects of the game can be changed. Changes are made using what are aspects of the game can be changed. Changes are made using what are
called `API` calls - these are calls to functions and methods in called `API` calls - these are calls to functions and methods in
Minecraft - you can read more about these on the [CanaryMod API Minecraft - you can read more about these on the [CanaryMod API
Reference][cmapi].) Reference][cmapi].
## ...and Again, and Again, and Again,... ## ...and Again, and Again, and Again,...
@ -858,7 +880,7 @@ utils.foreach() function...
var utils = require('utils'); var utils = require('utils');
var players = utils.players(); var players = utils.players();
utils.foreach( players, function( player ) { utils.foreach( players, function( player ) {
player.capabilities.setMayFly(true); player.capabilities.flying = true;
player.updateCapabilities(); player.updateCapabilities();
} ); } );
``` ```