Difference between revisions of "HPL3/Scripting/Scripting Guide/Hello World"
(Created page with "{{wip}} {{Hpl3ScriptingGuideMenuBasic}} {{shortPageTitle}} Let’s start by writing a very simple script. Like every programming tutorial ,we will start with a “Hello World...") |
|||
Line 3: | Line 3: | ||
{{shortPageTitle}} | {{shortPageTitle}} | ||
− | Let’s start by writing a very simple script. Like every programming tutorial ,we will start with a | + | Let’s start by writing a very simple script. Like every programming tutorial, we will start with a "Hello World” message. |
− | We want the message to be displayed on the screen when we load our map, so for that, we will go to OnStart, and inside those curly brackets, add | + | We want the message to be displayed on the screen when we load our map, so for that, we will go to OnStart, and inside those curly brackets, add: <pre> |
+ | cLux_AddDebugMessage("Hello World!"); | ||
+ | </pre>Don’t worry about what it means just yet. | ||
− | cLux_AddDebugMessage( | + | The code should look something like this:<syntaxhighlight lang="c++"> |
− | + | //////////////////////////// | |
− | + | // Run first time starting map | |
− | + | void OnStart() | |
− | Let’s save our script and launch our mod via CodeLite. | + | { |
+ | cLux_AddDebugMessage("Hello World!"); | ||
+ | } | ||
+ | </syntaxhighlight>Let’s save our script and launch our mod via CodeLite. | ||
Once our map is loaded, we should get basically a black screen with a handful of text around the edges. In the lower left corner, you should see the text “Hello World!”. | Once our map is loaded, we should get basically a black screen with a handful of text around the edges. In the lower left corner, you should see the text “Hello World!”. | ||
− | If you don’t see the text, make sure the developer panel is hidden by pressing F1 again. This is because the game is effectively frozen while the panel is visible by default, so the script may not appear right away if the panel is visible. If you still do not see the text, press F5, which reloads the map and causes it to become visible again. | + | {{Note|If you don’t see the text, make sure the developer panel is hidden by pressing F1 again. This is because the game is effectively frozen while the panel is visible by default, so the script may not appear right away if the panel is visible. If you still do not see the text, press F5, which reloads the map and causes it to become visible again.}} |
+ | == Conclusion == | ||
So let’s look at what we just did in pieces: | So let’s look at what we just did in pieces: | ||
Revision as of 20:59, 9 August 2020
This article is actively undergoing a major edit. The user who added this notice will be listed in its edit history should you wish to contact them. |
Let’s start by writing a very simple script. Like every programming tutorial, we will start with a "Hello World” message.
We want the message to be displayed on the screen when we load our map, so for that, we will go to OnStart, and inside those curly brackets, add:
cLux_AddDebugMessage("Hello World!");
Don’t worry about what it means just yet. The code should look something like this:
////////////////////////////
// Run first time starting map
void OnStart()
{
cLux_AddDebugMessage("Hello World!");
}
Let’s save our script and launch our mod via CodeLite.
Once our map is loaded, we should get basically a black screen with a handful of text around the edges. In the lower left corner, you should see the text “Hello World!”.
Conclusion
So let’s look at what we just did in pieces:
First, we used the code cLux_AddDebugMessage followed by an opening and closing parentheses. This is a function call, which you will learn more about in the next video.
For now, just know that this function’s job is to print text onto the screen. Within the parentheses is some text within quotation marks, “Hello World!”. This is what is known as a “string”. The important part to note here is that it is the text that actually appeared in the game itself.