User Tools

Site Tools


hpl2:tutorials:script:tutorial_1

Link to this comparison view

hpl2:tutorials:script:tutorial_1 [2010/11/04 13:48]
jens created
hpl2:tutorials:script:tutorial_1 [2010/11/04 15:07] (current)
jens
Line 7: Line 7:
 In my own experience, as a non-educated fellow in the world of scripting, I think you are best of taking a look at Javascript before you try to begin scripting in HPL2. Why? Because it is easy to find Javascript tutorials and information online and all you need is a text editor and your web browser. A place to start is for example w3schools [[http://​www.w3schools.com/​js/​js_intro.asp|introduction to Javascript]]. Mainly chapters [[http://​www.w3schools.com/​js/​js_comments.asp|JS Comments]] to [[http://​www.w3schools.com/​js/​js_loop_for_in.asp|JS For...In]] touch the general subjects that are common to all syntax'​s. In my own experience, as a non-educated fellow in the world of scripting, I think you are best of taking a look at Javascript before you try to begin scripting in HPL2. Why? Because it is easy to find Javascript tutorials and information online and all you need is a text editor and your web browser. A place to start is for example w3schools [[http://​www.w3schools.com/​js/​js_intro.asp|introduction to Javascript]]. Mainly chapters [[http://​www.w3schools.com/​js/​js_comments.asp|JS Comments]] to [[http://​www.w3schools.com/​js/​js_loop_for_in.asp|JS For...In]] touch the general subjects that are common to all syntax'​s.
  
-A short version is that all that you do in HPL2 is to use functions, they are commands that you give properties and then all the magic is taken care of by the game. [[amnesia:​script_functions|Everything here]] are functions. You then decide how and when the functions are to be executed by using the common programing specific parts such as //​statements//,​ //​variables//​ and //​comparisons//​ in combination with the objects you place using the [[tools:​editors:​level_editor:​|level editor]].+A short version is that all that you do in HPL2 is to use functions, they are commands that you give properties and then all the magic is taken care of by the game. [[:hpl2:amnesia:​script_functions|Everything here]] are functions. You then decide how and when the functions are to be executed by using the common programing specific parts such as //​statements//,​ //​variables//​ and //​comparisons//​ in combination with the objects you place using the [[:hpl2:tools:​editors:​level_editor:​|level editor]].
  
 ==== Example for those with no prior experience ==== ==== Example for those with no prior experience ====
Line 42: Line 42:
 How this actually makes the rock move is not important, that is all taken care of by the game, but you have specified that you want to move a specific Rock and that is should be moved at a speed of 10 (this could be 10 m/s, but this is something you need to look up and learn and not something you specify). The only HPL2 specific thing here would be //​MoveObject//,​ which is the name of our function (word) and the //​("",​);//​ are the grammar (the syntax for C/C++ like scripts) and //Rock// is a name of an object in the level editor and //10// is a specified value. ​ How this actually makes the rock move is not important, that is all taken care of by the game, but you have specified that you want to move a specific Rock and that is should be moved at a speed of 10 (this could be 10 m/s, but this is something you need to look up and learn and not something you specify). The only HPL2 specific thing here would be //​MoveObject//,​ which is the name of our function (word) and the //​("",​);//​ are the grammar (the syntax for C/C++ like scripts) and //Rock// is a name of an object in the level editor and //10// is a specified value. ​
  
-Good luck and remember to read and learn ALL [[amnesia:​script_functions|script functions]] available, or just bookmark that page. ;)+Good luck and remember to read and learn ALL [[:hpl2:amnesia:​script_functions|script functions]] available, or just bookmark that page. ;)
  
  
 ===== Scripting with HPL2 ===== ===== Scripting with HPL2 =====
-A script file is a plain text file, with the same name as your map file. For example: my_test_level.map should have a my_test_level.hps text file in the same location. A script file can be edited using good old Notepad, if you do a lot of scripting it might be a good thing to [[third_party_tools:​text:​notepad|read about Notepad++]].+A script file is a plain text file, with the same name as your map file. For example: my_test_level.map should have a my_test_level.hps text file in the same location. A script file can be edited using good old Notepad, if you do a lot of scripting it might be a good thing to [[:hpl2:third_party_tools:​text:​notepad|read about Notepad++]].
  
-For the below to work you need a very simple test map. All you need is to make a plane to stand on, a PlayerStartArea to have a place the player will start at and a light so that you can see. In the last example you will need to add a Script Area too and naming it "​AreaTest01"​. See [[tutorials:​level_editor:​tutorial_1|this tutorial]] for map creation.+For the below to work you need a very simple test map. All you need is to make a plane to stand on, a PlayerStartArea to have a place the player will start at and a light so that you can see. In the last example you will need to add a Script Area too and naming it "​AreaTest01"​. See [[:hpl2:tutorials:​level_editor:​tutorial_1|this tutorial]] for map creation.
  
-  - The script file is quite straightforward,​ begin by copying and pasting the first example below into your text file. Then start the game with your map and you should be able to activate a lantern, if you look in the inventory you should also have 10 tinderboxes. If you do not, make sure that you have setup a [[amnesia:​devenvguide|development environment]],​ failing to do this will make all debug stuff not work.+  - The script file is quite straightforward,​ begin by copying and pasting the first example below into your text file. Then start the game with your map and you should be able to activate a lantern, if you look in the inventory you should also have 10 tinderboxes. If you do not, make sure that you have setup a [[:hpl2:amnesia:​devenvguide|development environment]],​ failing to do this will make all debug stuff not work.
   - In the second example there are two new things: A AddTimer in OnStart and a new function.   - In the second example there are two new things: A AddTimer in OnStart and a new function.
   - In the third example, an AddEntityCollideCallback was added in OnStart and a new function for it. You also add an area to your level and call it "​AreaTest01",​ placing it close to the PlayerStartArea.   - In the third example, an AddEntityCollideCallback was added in OnStart and a new function for it. You also add an area to your level and call it "​AreaTest01",​ placing it close to the PlayerStartArea.
hpl2/tutorials/script/tutorial_1.1288878532.txt.gz ยท Last modified: 2010/11/04 13:48 by jens