Hack Wars encourages players to program to increase their skills and standing within the game. Scripts are the source of all of a players abilities and are important to succeeding in the game. They are also the main source of trade revenue as players will pay greatly for scripts with overwhelming power.
To create a new program in Hack Wars, the first step is to find the Script Editor under Applications. The Script Editor allows you to choose which type of script you’d like to create (Banking, Attack, etc.). Each type of script has various components, e.g., a Banking script has Deposit, Withdrawal, and Transfer components. These correspond with actual events that happen while playing the game. For instance, any code you write into the Deposit component will be run when a player attempts to perform a Deposit transaction with their Bank.
In the above screen shot, the three ‘events’ of a Banking program are highlighted in green. The ‘Save’ functions are highlighted in yellow—failure to save the program will result in the compiled program having the name “Untitled”. The Test Compile button is highlighted in blue, Compile in red, and in purple is the option to Run a Challenge Script (which will be discussed at another point).
Hack Wars programming is event-driven. There are limitations as to what functions can be run at any given time, depending on the type of program you are making and the ‘event’: functions called in the ‘Finalize’ portion of an Attack script must be functions that can be called when finalizing an attack.
BankingA full list of functions that can be called is given in the Hack Wars API section, listed by type of script.
Compiling a script requires that a player has attained the level required to call the functions, as listed in the API, and also that the player pays the appropriate amount of money, determined by the functions called within the program and the number of occurrences.
A program is compiled by clicking the appropriate button in the Script Editor. Prior to compiling, it is advisable to Test Compile: this gives the player the compiling cost and tests the code’s validity. If the test compile finds invalid code, the event containing the faulty code is identified. The player’s name is attached to the program upon compiling.
Compiled programs can be installed on a player’s ports in Port Management (see below, section on Installing Programs), sold in stores to other players or installed on an opponent’s port after a successful attack.
While compiling code is restricted based on level, a player of a lower level may still install a program he or she has bought or traded.
A player is allowed to de-compile programs they themselves have made by selecting the compiled file in the File Browser (System—Home) and clicking the De-compile button at the top of the window. This will return 90% of the compile cost to the player; also, 90% of the experienced gained from compiling the program will be deducted. An uncompiled version of the script will appear on the player’s hard drive, which can now be edited. This can be useful to merchants who may have a large quantity of files to which they wish to make a change.
Note that once a program has been installed, it cannot be removed, and therefore not de-compiled.
In this screen shot the de-compile option is highlighted in purple. Please note that the money returned is 90% of the compile cost, and NOT the price set by the user.
Programs are installed from within the Port Manager by right-clicking a port under the heading Type and selecting a script to install (highlighted here in red).
Programming in Hack Wars is close to a programming language called C. This is a very pervasive standard in computing. For those not familiar with this programming language, this section of the manual will give a good overview. Even for experienced programmers, it is good to read through this section to see some of the limitations presented by the Hack Wars programming language.
Types: you can use int, string, float, or boolean, variable types in Hack Wars, here’s an example of a script using all four types:
int a=10;
float b=5.5;
string message="You are being sent a message.";
boolean myBool=true;
if(myBool&&(b>5.0||a<10)){
message(getSourceIP(),message);
} If you placed this script, for instance, in the deposit entry point of a banking application, it would always send you the message “You are being sent a message.” when you attempt to deposit — the deposit would not happen, mind you, since it contains no code to perform this operation.
Assigning Values: To assign a variable to be equal to a value (as demonstrated in the previous code example) use the ‘=’ operator, e.g., int i=5. This is the only way currently available to assign values, ‘++’,'--’,'*=’, etc, are not currently supported. So, for instance, if you had a counter in a loop you would increment it using the following code:
int i=0;
while(i<10){
i=i+1;
} Logical Operators: You have access to the following logical operators in the Hack Wars scripting language:
| Meaning | Symbol |
| Greater than | > |
| Less than | < |
| Equal to | == |
| Greater than equal to | >= |
| Less than equal to | <= |
| And | && |
| Or | || |
| Equal | == |
| Not Equal | != |
Program Flow: There are two main ways to direct the logical flow of a program you are creating if statements and while statements. Using an if statement allows you to execute code if a statement evaluates to true, using else allows you to specify code that runs otherwise:
if(5>6){
message(getSourceIP(),"This should never happen!");
}else{
message(getSourceIP(),"This should always happen.");
} Using a while statement allows you to specify a block of code that will always execute until a condition evaluates to false:
int i=0;
while(i<3){
message(getSourceIP(),printf("T Minus %s",(3-i)));
i=i+1;
}
message(getSourceIP(),"Liftoff!");
For creating complex programs, such as complicated HTTP programs, one can use functions. Simply put:
#define functions
On the first line of your program. This allows you to program functions in a C-style manner:
int main(){
a(5);
}
void a(int b){
b=b*b;
}
In all your scripts you can set and maintain global variables, using the functions: setGlobal(int index,variable data), and getGlobal(int index). Where data can be a string, int, float, or boolean. There are twenty globals available to you (0-19).
Here's an example of a poll created with Globals for your Hack Wars website:
First I made a watch script for reseting the variables, I just installed it as a petty-cash watch and fire it when I want to reset the poll:
setGlobal(0,0);
setGlobal(1,0);
setGlobal(2,0);
setGlobal(3,0);
message("192.168.2.002","Poll Reset: "+getGlobal(0)+" "+getGlobal(1)+" "+getGlobal(2)+" "+getGlobal(3));
Next there is the actual HTTP script I made for allowing players to vote using my global variables, this is placed in the 'submit' event.:
string a=getParameter("a");
if(equal(a,"0")){
int i=getGlobal(0);
i=i+1;
setGlobal(0,i);
}else if(equal(a,"1")){
int i=getGlobal(1);
i=i+1;
setGlobal(1,i);
}else if(equal(a,"2")){
int i=getGlobal(2);
i=i+1;
setGlobal(2,i);
}else if(equal(a,"3")){
int i=getGlobal(3);
i=i+1;
setGlobal(3,i);
}
float a=getGlobal(0)*1.0;
float b=getGlobal(1)*1.0;
float c=getGlobal(2)*1.0;
float d=getGlobal(3)*1.0;
float total=a+b+c+d;
string message="<h1>Results</h1><p>Who is the sexiest developer of Hack Wars?</p>";
message=message+"Johnny Heart: "+(a/total*100.0)+"%<br />";
message=message+"Furrot: "+(b/total*100.0)+"%<br />";
message=message+"Alexander: "+(c/total*100.0)+"%<br />";
message=message+"Geckotoss: "+(d/total*100.0)+"%<br />";
popUp(message);
And, finally, we have the actual HTML I throw up on my page on Hack Wars. These together give my site a working poll: