How to write a script

From HEWIKI
(Difference between revisions)
Jump to: navigation, search
(Overview)
Line 16: Line 16:
  
 
Scripts execute in response to external events (see [[Script entry points]]).  This may be commands from a player client, callbacks from input events, server events, or other methods.   
 
Scripts execute in response to external events (see [[Script entry points]]).  This may be commands from a player client, callbacks from input events, server events, or other methods.   
* Client scripts can also be run or CALLed manually, from the [[Console Window]]
+
* Client scripts can also be run or CALLed manually, from the Console Window
 
* Server scripts can be run manually via commands which are typed into the [[Chat panel]].
 
* Server scripts can be run manually via commands which are typed into the [[Chat panel]].
  
 
=== Create and run a client-side script ===
 
=== Create and run a client-side script ===
  
Client-side scripts run only on the [[client]].  They can be run manually by using the [[CALL]] command in the [[Console window]].
+
Client-side scripts run only on the [[client]].  They can be run manually by using the [[CALL]] command in the Console window.
  
 
[[Image:HeroBladeInvokeHeroScriptEditor.png|right]]
 
[[Image:HeroBladeInvokeHeroScriptEditor.png|right]]
 
* Open [[HeroBlade]]
 
* Open [[HeroBlade]]
** Ensure that the [[Console window]] is open, since you'll need to type a command into it later to run the script. If it is not open, ensure that it is checked in the [[Tools Menu]].
+
** Ensure that the Console window is open, since you'll need to type a command into it later to run the script. If it is not open, ensure that it is checked in the [[Tools Menu]].
  
 
* Open the [[Script Editor|HeroScript Editor]] with CTRL+H, or go to the [[HeroScript menu]] and choose "HeroScript Editor (HSE)".
 
* Open the [[Script Editor|HeroScript Editor]] with CTRL+H, or go to the [[HeroScript menu]] and choose "HeroScript Editor (HSE)".
Line 53: Line 53:
 
* Switch back to the game window.
 
* Switch back to the game window.
  
* Run the script, by typing into the input box of the [[Console window]], with the following syntax:
+
* Run the script, by typing into the input box of the Console window, with the following syntax:
 
  call <scriptname> <functionname>
 
  call <scriptname> <functionname>
 
:*Example: <code> call chiv HelloWorld </code>
 
:*Example: <code> call chiv HelloWorld </code>

Revision as of 19:14, 9 November 2012

He beginner.png This is an easy-level tutorial on how to edit, save, and run a (client-side) HSL script. For server-side scripts, see Creating server scripts, and for quickref expert instructions, see HSL for programmers.

Overview

The first thing to understand about writing scripts in HeroEngine, is that there are two different types of scripts:

For more on this, see Client-Server architecture.

The language for both sides, client and server, is the same, but each works with its own DOM database, and the scripts are stored and compiled separately.

When accessing a script via the Script Editor, it is necessary to specify client-side or server-side at the beginning. Also, when browsing a directory of scripts, you will be browsing only one side or the other at a time.

As a reminder of which type of script you are currently editing, a "C" or "S" will appear at the top of the Editor.
HeroScriptEditor2ClientServerScripts.png

Scripts execute in response to external events (see Script entry points). This may be commands from a player client, callbacks from input events, server events, or other methods.

Create and run a client-side script

Client-side scripts run only on the client. They can be run manually by using the CALL command in the Console window.

HeroBladeInvokeHeroScriptEditor.png

function HelloWorld()
  SendChat(SYSTEM.EXEC.THISSCRIPT + " Hello world! Or at least Hello Area!", "game")
.
  • At this point, in the bottom part of the editor, you will see either Compile succeeded, or an error. If there's an error, it will tell you which line number and what type of error. Fix it, and compile again, and repeat, until you get a successful compile.
  • Even with a successful compile though, the script still isn't ready to run yet, because it hasn't been submitted to HeroEngine.
  • This will bring up a "comments" box. Enter something into the box that gives a rough summary of what you've done, like "Created new script" or "fixed a typo", etc.
  • At the bottom of the editor window, should now be a message: SUBMIT of <script name> succeeded. New version number: <##>
call <scriptname> <functionname>
  • Example: call chiv HelloWorld
[<Your name>] [<Your script name>]Hello world!  Or at least,  Hello Area!

Note: The reason that your name is prepended to the beginning of the message, is because this is automatically done by the SendChat() function. This function was used, since it was the easiest way to get a message from the Client to show up. To generate a message that does not use this format, it will be necessary to use a server-side script.

For your next trick, please continue to Creating Server Scripts.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox