This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/js/plugins/examples/example-5-hello-using-module.js

42 lines
1.3 KiB
JavaScript

/*************************************************************************
## Example Plugin #5 - Re-use - Using your own and others modules.
A simple minecraft plugin. Using Modules.
### Usage:
At the in-game prompt type ...
/jsp hello-module
... and a message `Hello {player-name}` will appear (where {player-name} is
replaced by your own name).
This example demonstrates the use of modules. In
example-1-hello-module.js we created a new javascript module. In
this example, we use that module...
* We load the module using the `require()` function. Because this
module and the module we require are n the same directory, we
specify `'./example-1-hello-module'` as the path (when loading a
module from the same directory, `./` at the start of the path
indicates that the file should be searched for in the same
directory.
* We assign the loaded module to a variable (`greetings`) and then
use the module's `hello` method to display the message.
Source Code...
var greetings = require('./example-1-hello-module');
command( 'hello-module', function( parameters, player ) {
greetings.hello( player );
});
***/
var greetings = require('./example-1-hello-module');
command( 'hello-module', function( parameters, player ) {
greetings.hello( player );
});