How to merge scripts in Adrenaline

Introduction

Delphi is a powerful and versatile programming language, widely used for developing desktop, mobile, web, and console applications. Merging scripts in Delphi can be essential for various purposes, including consolidating functionalities, improving code organization, and enhancing maintainability. This tutorial will provide you with a comprehensive guide on how to merge scripts in Delphi effectively.

Prerequisites

Before we dive into the details, ensure you have the following:

  • L2 Adrenaline (free or premium) installed on your computer. You can download Adrenaline free version with maps from our downloads section,
  • Little bit of free time…

Step #1: Create your first script

Lets say you want to create a script that prints “Hello” in the Adrenaline’s console.

This script can be written as:

				
					begin
    print('Hello');
end.
				
			

Each script should have the ‘begin’ and the ‘end.’ tag (with a dot at the end). The content inside these tags will be executed by the runtime. In this case, we are using a function named ‘print’ that takes a string variable (‘Hello’) as a parameter. Each line ends with a semicolon (not always necessary, but remember that).

Step #2: Create your second script

Now that you are proficient in creating scripts, let’s create your second script which will print the word ‘World’. As you can imagine, we can use exactly the same script but we will change the string parameter that goes directly to the function ‘print’..

				
					begin
    print('World');
end.
				
			

Step #3: Combine two scripts

As we have learned, each script should have one ‘begin’ and one ‘end.’ (with a period).

So, how can we execute both scripts? We need to combine them!

This may sound like a hard task, but actually it’s not. All you have to do is to add a new line before the ‘begin’ tag for each script. This extra line will be used to ‘define’ that it’s not the main code of our script and instead, it’s a procedure (or a function). Let’s turn our first script (‘Hello’) into a procedure:

				
					procedure sayHello;

begin
    print('Hello');
end.
				
			

Now that we have added those extra lines which declare a procedure named ‘sayHello’, we have to change the ‘end.’ to ‘end;’ with a semicolon because it will not be our ‘main’ script.

				
					procedure sayHello;

begin
    print('Hello');
end;
				
			

We are ready with the first script! Let’s do the same for the second script and name it ‘sayWorld’:

				
					procedure sayWorld;

begin
    print(' World');
end;
				
			

Our main executable block

Since our procedures are ready, we can finally create our main block as:

				
					Begin
    sayHello;
    sayWorld;
End.
				
			

That’s it! You can execute your code and see the results!

Stay tunned for the next tutorial regarding a detailed explanation of procedures and functions!