Difference between revisions of "HPL2/Script Pre-Processor"

From Frictional Wiki
Jump to navigation Jump to search
(Upload from wiki)
 
(Syntax highlightin fix)
Line 1: Line 1:
= Script Pre-Processer =
+
= Script Pre-Processor =
 
+
The C pre-processor is a powerful tool that allows programers many  options when writing their code - among these options are commands such  as #include ””, which allows the user to include the contents from one  code file into another.
 
 
The C pre-processer is a powerful tool that allows programers many  options when writing their code - among these options are commands such  as #include ””, which allows the user to include the contents from one  code file into another.
 
 
 
  
 
[http://www.frictionalgames.com/forum/thread-12023.html Original Post]
 
[http://www.frictionalgames.com/forum/thread-12023.html Original Post]
  
 
== Setting Up ==
 
== Setting Up ==
 
 
 
In the below ZIP-File a copy of [http://mcpp.sourceforge.net/ MCPP  ] is included as the pre-processor. I have also written a batch script  which will call the pre-processor with the appropriate arguments as well  as a display error messages & log them into a text file.
 
In the below ZIP-File a copy of [http://mcpp.sourceforge.net/ MCPP  ] is included as the pre-processor. I have also written a batch script  which will call the pre-processor with the appropriate arguments as well  as a display error messages & log them into a text file.
 
  
 
[http://dl.dropbox.com/u/64805489/HpsPreProcessFixed.zip Zip File  Download]  
 
[http://dl.dropbox.com/u/64805489/HpsPreProcessFixed.zip Zip File  Download]  
 
  
 
The next thing to do is set up notepad++ to use the batch file and MCPP.  Extract the contents of the zip file to a safe place (For example in a  new folder in the amnesia directory). Open up notepad++ and go into  the  “run” menu and click “run” (or press F5). Into this dialogue box  put the  following:
 
The next thing to do is set up notepad++ to use the batch file and MCPP.  Extract the contents of the zip file to a safe place (For example in a  new folder in the amnesia directory). Open up notepad++ and go into  the  “run” menu and click “run” (or press F5). Into this dialogue box  put the  following:
  
 
+
<syntaxhighlight lang="batch">
<syntaxhighlight lang="">
 
 
[FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps
 
[FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 26: Line 18:
 
Replace [FOLDER] with the folder the batch file is in. For example:
 
Replace [FOLDER] with the folder the batch file is in. For example:
  
 
+
<pre>
<syntaxhighlight lang="">
 
 
C:\Program Files (x86)\Amnesia\HPS_PREPROCESSOR\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps
 
C:\Program Files (x86)\Amnesia\HPS_PREPROCESSOR\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps
</syntaxhighlight>
+
</pre>
 
 
  
 
It is recommended that you then click  save and bind the command to  something like F6 - otherwise you will have  to enter this every time  you start notepad++ .
 
It is recommended that you then click  save and bind the command to  something like F6 - otherwise you will have  to enter this every time  you start notepad++ .
 
  
 
<u>'''Warning:  Do not press “run” (or F6 if you bound  it) on a script file which ends  in ”.hps”! This will wipe the script  file!!! Give your script files  which use the pre-processor a different  extension (E.g .phps or .lhps). ''' </u>
 
<u>'''Warning:  Do not press “run” (or F6 if you bound  it) on a script file which ends  in ”.hps”! This will wipe the script  file!!! Give your script files  which use the pre-processor a different  extension (E.g .phps or .lhps). ''' </u>
  
 
== Usage ==
 
== Usage ==
 
 
 
The files that exist before pre-processing will have to have a different  extension to the one after pre-processing. The simplest way to do this  is to call your script files something like “level.phps” so that the  pre-processor writes “level.hps”. Consider the following test code:
 
The files that exist before pre-processing will have to have a different  extension to the one after pre-processing. The simplest way to do this  is to call your script files something like “level.phps” so that the  pre-processor writes “level.hps”. Consider the following test code:
  
 
+
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="">
 
 
  //level.phps//
 
  //level.phps//
 
  #include "inclusion_test.phps"
 
  #include "inclusion_test.phps"
Line 58: Line 44:
 
   }
 
   }
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
Running the script  from test.phps (F6 if you followed the instructions above) should create “test.hps”:
 
Running the script  from test.phps (F6 if you followed the instructions above) should create “test.hps”:
  
 
+
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="">
 
 
void OnStart()
 
void OnStart()
 
  {
 
  {
Line 74: Line 58:
 
  }
 
  }
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
Which is what the game will see from test.map and run. When you  distribute your custom stories only this exported file is required.  Obviously, since we are now using a C pre-processor there is a whole [http://en.wikipedia.org/wiki/C_preprocessor host of other things you can do.]  
 
Which is what the game will see from test.map and run. When you  distribute your custom stories only this exported file is required.  Obviously, since we are now using a C pre-processor there is a whole [http://en.wikipedia.org/wiki/C_preprocessor host of other things you can do.]  
 
  
 
== Reccomended Extra Installation Setup ==
 
== Reccomended Extra Installation Setup ==
 
  
 
You may notice that stuff like #include isn't color coded - and that  your new script files ”.phps” aren't automatically recognised as HPS  files! I Have updated the notepad++ files to fix this (Note that these  are updated versions of the [http://www.frictionalgames.com/forum/thread-9783.html overhauled notepad++ files], which provide a fixed function list, folding regions and a new color scheme)
 
You may notice that stuff like #include isn't color coded - and that  your new script files ”.phps” aren't automatically recognised as HPS  files! I Have updated the notepad++ files to fix this (Note that these  are updated versions of the [http://www.frictionalgames.com/forum/thread-9783.html overhauled notepad++ files], which provide a fixed function list, folding regions and a new color scheme)
 
  
 
[http://www.mediafire.com/?yx2nb2zdgdswg4e Download]  
 
[http://www.mediafire.com/?yx2nb2zdgdswg4e Download]  
 
  
 
Installation (Steps 1→4 are optional but recommended):
 
Installation (Steps 1→4 are optional but recommended):
  
 +
# Close notepad++
 +
# Go to where you installed notepad (Probably C:\Program Files\Notepad++ or C:\Program Files (X86)\Notepad++\)
 +
# Go to the folder "Plugins" Then to the folder "APIs"
 +
# Copy across the downloaded version of "hps.xml" into this folder. If you a prompted to overwrite, say yes.
  
## Close notepad++
+
# Start notepad++
## Go to where you installed notepad (Probably C:\Program Files\Notepad++ or C:\Program Files (X86)\Notepad++\)
+
# Go into view→ User-Defined Dialogue
## Go to the folder "Plugins" Then to the folder "APIs"
+
# On the drop-down box, if there is the option to select "HPS", select it and and click "Remove"
## Copy across the downloaded version of "hps.xml" into this folder. If you a prompted to overwrite, say yes.
+
# Click import, and import "UserDefinedDialogue.xml"
 
 
 
 
## Start notepad++
 
## Go into view→ User-Defined Dialogue
 
## On the drop-down box, if there is the option to select "HPS", select it and and click "Remove"
 
## Click import, and import "UserDefinedDialogue.xml"
 
 
 
  
<br /> <br />You will now a fixed functions list for amnesia (Adds missing functions  & keywords, removes non-existing ones), as well as a new color  scheme, folding regions (''+ ''- /<nowiki>*</nowiki><nowiki>*</nowiki> <nowiki>*</nowiki><nowiki>*</nowiki>/ ''Begin ''    End) etc. ”.hps,  .phps, .lhps” are now detected, and ”#…” are coloured correctly.
+
You will now a fixed functions list for amnesia (Adds missing functions  & keywords, removes non-existing ones), as well as a new color  scheme, folding regions (''+ ''- /<nowiki>*</nowiki><nowiki>*</nowiki> <nowiki>*</nowiki><nowiki>*</nowiki>/ ''Begin ''    End) etc. ”.hps,  .phps, .lhps” are now detected, and ”#…” are coloured correctly.

Revision as of 23:12, 22 July 2020

Script Pre-Processor

The C pre-processor is a powerful tool that allows programers many options when writing their code - among these options are commands such as #include ””, which allows the user to include the contents from one code file into another.

Original Post

Setting Up

In the below ZIP-File a copy of MCPP is included as the pre-processor. I have also written a batch script which will call the pre-processor with the appropriate arguments as well as a display error messages & log them into a text file.

Zip File Download

The next thing to do is set up notepad++ to use the batch file and MCPP. Extract the contents of the zip file to a safe place (For example in a new folder in the amnesia directory). Open up notepad++ and go into the “run” menu and click “run” (or press F5). Into this dialogue box put the following:

[FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps


Replace [FOLDER] with the folder the batch file is in. For example:

C:\Program Files (x86)\Amnesia\HPS_PREPROCESSOR\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps

It is recommended that you then click save and bind the command to something like F6 - otherwise you will have to enter this every time you start notepad++ .

Warning: Do not press “run” (or F6 if you bound it) on a script file which ends in ”.hps”! This will wipe the script file!!! Give your script files which use the pre-processor a different extension (E.g .phps or .lhps).

Usage

The files that exist before pre-processing will have to have a different extension to the one after pre-processing. The simplest way to do this is to call your script files something like “level.phps” so that the pre-processor writes “level.hps”. Consider the following test code:

 //level.phps//
 #include "inclusion_test.phps"
 
 void OnEnter()
  {
    AddDebugMessage("File 1",false);
  }
 
 //inclusion_test.phps//
 void OnStart()
  {
   AddDebugMessage("File 2",false);
  }

Running the script from test.phps (F6 if you followed the instructions above) should create “test.hps”:

void OnStart()
 {
 AddDebugMessage("File 2",false);
 }  
 
 void OnEnter()
 {
 AddDebugMessage("File 1",false);
 }

Which is what the game will see from test.map and run. When you distribute your custom stories only this exported file is required. Obviously, since we are now using a C pre-processor there is a whole host of other things you can do.

Reccomended Extra Installation Setup

You may notice that stuff like #include isn't color coded - and that your new script files ”.phps” aren't automatically recognised as HPS files! I Have updated the notepad++ files to fix this (Note that these are updated versions of the overhauled notepad++ files, which provide a fixed function list, folding regions and a new color scheme)

Download

Installation (Steps 1→4 are optional but recommended):

  1. Close notepad++
  2. Go to where you installed notepad (Probably C:\Program Files\Notepad++ or C:\Program Files (X86)\Notepad++\)
  3. Go to the folder "Plugins" Then to the folder "APIs"
  4. Copy across the downloaded version of "hps.xml" into this folder. If you a prompted to overwrite, say yes.
  1. Start notepad++
  2. Go into view→ User-Defined Dialogue
  3. On the drop-down box, if there is the option to select "HPS", select it and and click "Remove"
  4. Click import, and import "UserDefinedDialogue.xml"

You will now a fixed functions list for amnesia (Adds missing functions & keywords, removes non-existing ones), as well as a new color scheme, folding regions (+ - /** **/ Begin End) etc. ”.hps, .phps, .lhps” are now detected, and ”#…” are coloured correctly.