Programming in Hack WarsHack Wars encourages players to program to increase their skills and standing within the game. Script EditorTo 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 banking script has three ‘events’:
An attack script has three ‘events’:
A full list of functions that can be called is given in the Hack Wars API section, listed by type of script. Compiled ProgramsCompiling 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. De-compiling programsA 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.
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. Installing ProgramsPrograms 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).
|
| 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!");