DASIC - PieKing1215/HackerTyperNeoNeo GitHub Wiki

DASIC

DASIC is a programming language built specifically for HTNN. It is the primary(only) way to automate tasks and create programs within the game. DASIC is an extension of Jasic, which itself is a dialect of BASIC. While DASIC resembles BASIC, it is likely that programs written in BASIC will need modification in order to function with DASIC, due to differences in commands and syntax. Programs written in DASIC are written in plain text and stored in .jas files.

Running a DASIC program

Once you have written code in your text editor of choice (or the ingame one), make sure to save it as something.jas, so the game recognizes it. Place it anywhere in the game's /filesystem folder and use the run command to run it. If you want to force exit the program, press CTRL-T to terminate it.

Variables

Variables are somewhat simple to use in DASIC. You can create one by simply assigning a value to it. This is done in the format varName = value, where varName is the name of the variable and value is the initial value of the variable. Variable names are alphanumeric, but cannot start with a number. To reference a variable, simply use its name.

Data types

There are 3 basic data types that a value can have:

  • Number - A number, surprisingly. Numbers are stored as signed doubles, but can only be typed as positive integers due to the limitations of Jasic. In order to get a decimal, one must divide (Ex. 1/2), and in order to get a negative, one must subtract (Ex. 0-2).
  • Strings - A string or value representing text. Strings are typed inside quotes (Ex. "hello").
  • Arrays - An array of values, which can be any of the available data types. To type an array, one can either create a blank array of a set length by surrounding a number by square brackets (Ex. [6]), or create an array with values already inside of it by surrounding a comma-seperated list of values with curly brackets (Ex. {5,2,6,hi,there}). (Note that array literals cannot be typed directly into another array literal - {1,2,{hello,6},world} and {1,2,[3],world} will not work. In order to use nested arrays, the inside array must be stored in a variable, then put in the array literal) (Also notice that inside array literals, any text that is not a number is automatically turned into a string, so quotes are not used.). To access values from an array, one must use the name of the array followed by the index of the value surrounded by square brackets (Ex. myValues[2] gets the value at index 2 in myValues).

Statements

  • Comment ('any text) - A comment which is not run as part of the program. Any text on the same line and after a ' is ignored.
  • Assign (varName = value) - Assign a value to a variable. If the variable does not exist, it is created.
  • Print (print value) - Print a value to the console.
  • Run (run value) - Make the console run a command (Ex. run "cls" will clear the screen).
  • Int (int value varName) - Rounds value down (casts to int) and stores the result in a variable.
  • Rnd (rnd mode varName) - Stores a random number and stores it in a variable. The way the number is generated depends on the mode. If mode is less than 0, a number is generated using a new RNG with mode as the seed. If mode is equal to 0, the last generated number is returned and no new number is generated. Otherwise, the next number is generated using the global RNG.
  • Input (input varName) - Prompts the user for input and stores it in a variable.
  • Remove (remove arrayVarName index) - Removes the value at an index in an array. If index is ?, the last element in the array is removed.
  • Sleep (sleep milliseconds) - Delays for a time in milliseconds.
  • Label (labelName:) - Marks a position in the code that can be jumped to.
  • Goto (goto label) - Immediately jumps code execution to a label.
  • Sub (sub label) - Same to goto, but stores the sub statement's location internally for returns to use
  • Return (return) - Immediately jumps code execution to after the last sub statement.
  • If then (if value then label) - Immediately jumps code execution to a label if value is 1.

Operators

Operators compare or perform a mathematic operation on two values or variables. Please note that as in Jasic, numerical operators all have the same precedence, and are processed left to right. This means that something like 1 + 2 * 3 will be interpreted as (1 + 2) * 3. In order to get the desired effect, make use of parentheses (Ex. 1 + (2 * 3)).

  • = - Test if two values are equal (used in if then statements). If the values are equal, returns 1. Otherwise returns 0. Works on both strings and numbers. Should not be confused with the assign statement.
  • # - Test if two values are not equal (used in if then statements). If the values are not equal, returns 1. Otherwise returns 0. Works on both strings and numbers.
  • + - Add two values. For numbers*, this performs mathematical addition and returns the result. For Strings, this performs concatenation and returns the result.
  • - - Subtract one value from another. Only works for numbers*.
  • * - Multiply value from another. Only works for numbers*.
  • / - Divide one value by another. Only works for numbers*.
    * For mathematical operations, any non-numeric values are transformed into numbers. For strings, any numeric strings (Like "14" or "2.5") will be transformed into the corresponding number. Any non-numeric strings will be transformed into -1. For arrays, the resulting number will be the length of the array. (See the examples section for some uses of these properties)

Things that aren't in DASIC

  • For loops - When needed, for loops can be recreated using the following setup. If nested for loops are required, be sure to use different names for the label for each different simultaneous loop.
    I = 0
    ITER = 10
    loop:
    ' do stuff
    I = I + 1
    if I<ITER then loop
    
  • While loops - When needed, while loops can be recreated using the following setup. If nested for loops are required, be sure to use different names for the label for each different simultaneous loop.
    loop:
    ' do stuff
    if condition then loop
    

Examples

Get array size

This works because during mathematical operations, arrays are transformed into the number of values in them.

myArray = {a,b,c,1,2,3}
arraySize = 0+myArray
' arraySize will be 6

Test if string is numeric / turn string into number

This works because during mathematical operations, numeric strings are transformed into their corresponding number, but -1 if they are not numeric.


myString1 = "14" ' a number
myString2 = "hello" ' not a number

' convert string to number string1Number = 0+myString1 ' will be 14 string2Number = 0+myString2 ' will be -1
' test for not -1 if string1Number # (0-1) then ' do whatever (will occur) if string2Number # (0-1) then ' do whatever (will not occur)

Passing arguments to subroutines and returning values

' make some numbers
number1 = 6
number2 = 2

' set the arguments
arg_num1 = number1
arg_num2 = number2

' call the subroutine
sub minMax

' print the result
print "Min = " + ret_min
print "Max = " + ret_max

' skip over the subroutines so they aren't called on their own
goto exit

minMax: ' finds the minimum and maximum number
  ' default return
  ret_min = arg_num1
  ret_max = arg_num2

  if ret_min < ret_max then noSwap ' if the min and max are not reversed then don't swap them
    ' if the min and max are reversed then swap them
    ret_min = arg_num2
    ret_max = arg_num1
  noSwap: 
return 

exit:

Downloads

Programs:
Hello World! (from Jasic)
Mandelbrot (modified from Jasic)
Hunt the Wumpus (port of original)
Undertale in Text (by me (parody of Undertale))
Other:
Notepad++ Syntax Highlighting

⚠️ **GitHub.com Fallback** ⚠️