ARSA Language  2.8
(Encryption, GPU and Web 3.0)
ARSA Language Quick Reference Guide.

Table of Contents

This is quick reference guide of ARSA Language.

1. How to writing an ARSA Language.

  • [Option A] Start with Photoshop layer directly.
    1. Make sure your layer is absolutely empty or a fresh new layer.
    2. Rename layer by right click or single click on a layer name.
    3. Writing a code be instread old layer name.
    4. Save and try refresh a PSD file in ARSA Studio, press F5 or Edit -> Refresh PSD.
  • [Option B] Start with any coding editor.
    1. Open you favorite editor e.g. VSCode, Edit+ or NotePad.
    2. Just writting a code and save to text file with any extension.
    3. Drag or Open directly to ARSA Studio, May you can using function psd("filename.psd") to loading a psd file.
    4. Use function arsalang("src_name.txt") in Photoshop layer.
  • Debug.
    1. Open log window in ARSA Studio: Window -> Log Window or Ctrl+L
    2. Use alog() for print text or variable on log window.
    3. Use msgbox() to popup dialog message.
    4. Debug PSD mode for checking layer bounding: Edit -> Debug PSD or Ctrl+D
  • Error Message.
    1. C0001: syntax error missing function.
    2. C0002: syntax error missing ( or )
    3. C0003: syntax error missing "
    4. C0004: syntax error missing { or }
    5. C0005: ARSA Language file not found!
    6. B0001: Built-In Script function error.

2. Main Loop.

  • Main loop is the heart of Games or App programming, every logic must embedded in there e.g. Move player, Fire missile, Collision detect and etc. This chapter will introduce basis of game loop to you.
  • Important pass have 3 sections, first is initialize second is update and last is de-initialize by following
    1. init, for allocate memory image, sound, movie or etc.
      {
      // write code here
      ...
      ...
      ...
      }function(init)
    2. update, this is a loop for update game/app logic.
      // write code anywhere and make sure outside function(init) or function(deinit)
      ...
      ...
      ...
    3. deinit, free memory after exit game/app.
      {
      // write code here
      ...
      ...
      ...
      }function(deinit)
  • Flow-chart of game/app loop (Ascii art)
    -------
    | start |
    -------
    |
    \|/
    -------
    | init |
    -------
    |
    \|/
    -------
    | update|<--------
    ------- /|\
    | |
    \|/ |
    ------- |
    | HUD | |
    ------- |
    | |
    \|/ |
    ------- No |
    | Exit? | ------->
    -------
    | Yes
    \|/
    -------
    | deinit|
    -------
    |
    \|/
    -------
    | end |
    -------

3. Hello World

  • Show text "Hello World" using text() function
    text(10,10, "Hello World") // 10, 10 is x, y axis
  • Result:
    Hello World

4. Variables

  • Variables are "containers" for storing information. In ARSA, a variable starts with the $ sign, followed by the name of the variable:
    Example: Local variables declaration.
    string( $txt, "Hello world")
    int( $x, 5)
    float( $y, 10.5)

    Example: Local variables declaration variable one time in init function.
    {
    string( $txt, "Hello world")
    int( $x, 5)
    float( $y, 10.5)
    }function(init)

    Example: Global variables declaration variable one time in init function.
    {
    gstring( $txt, "Hello world")
    gint( $x, 5)
    gfloat( $y, 10.5)
    }function(init)

  • What's diference between Local-Global variables?
    1. Local will delete by garbage collector after load a new psd file.
    2. Global will no effect with garbage collector when load a new psd file but will delete all stuff when program exit.
  • Edit variables by set() function, if variables not exist program will automaticly declaration.
    Example:
    set( $txt, "How r u?")
    set( $x, 7800)
    set( $y, 1045.54896)
  • Display variables with text() function.
    Example:
    text( 10, 40, "Show string: $txt" )
    text( 10, 70, "Show int: $x" )
    text( 10, 100, "Show float: $y" )
  • Result:
    Show string: How r u?
    Show int: 7800
    Show float: 1045.54896

More string examples: xml, json, curl command string setting.

5. Functions

  • A function is a group of statements that together perform a task. ARSA Language has all the most trivial programs can define additional functions.

5.1 Defining a Function

  • The formal form of a function declaration in ARSA programming language.
    {
    // write code here
    ...
    ...
    ...
    }function( name, parameters )
  • A function definition in ARSA programming consists of a name and codes, so, parameters is optional:
    1. name: This is the name of the function. init, deinit and Math are reserved words.
    2. parameters: User can passing variables be parameters and sending into function. Parameters are optional, function may contain no parameters.
    3. code: coding contains a collection of ARSA api that define what the function does.
  • Example:
    {
    set( $i, 10 )
    text(10, 10, "Value i: $i")
    }function(print_var)

5.2 Calling a Function

  • To use a function in ARSA, user will have to call a function to run a set of API stuff. User can call function below or above scope of function declaration.
  • Example 1:
    {
    set( $i, 10 )
    text(10, 10, "Value i: $i")
    }function(print_var)
    function(print_var) // call function below body
  • Result:
    Value i: 10
  • Example 2:
    function(print_var) // call function above body
    {
    set( $i, 10 )
    text(10, 10, "Value i: $i")
    }function(print_var)
  • Result:
    Value i: 10

5.3 Function with parameters (pass by value)

Parameters are equivalent local variables inside the function and garbage collector will destroyed them when ending up.

  • Example 1:
    {
    text(10, 10, "Value i: $i")
    }function(print_var, $i)
    function(print_var, 10) // call function and sening: 10 is parameter into $i
  • Result:
    Value i: 10
  • Example 2:
    {
    text(10, 10, "Value i: $i")
    text(10, 40, "Value j: $j")
    text(10, 70, "Value k: $k")
    }function(print_var, $i, $j, $k)
    function(print_var, 10, 20, 30) // call a function and sequentially sening values be parameters.
  • Result:
    Value i: 10
    Value j: 20
    Value k: 30

5.4 Function with return value

May funcition will return some value. In this case, return() is the API that user should call.

  • Example 1: return int
    {
    text(10, 10, "Value i: $i")
    return($i*2) // double value and return to call point
    }function(print_var, $i)
    set( $j, function(print_var, 10) ) // call and keep return value
    text(10, 40, "Return value is: $j") // show return value
  • Result:
    Value i: 10
    Return value is: 20
  • Example 2: return string
    {
    text(10, 10, "Value i: $i")
    set( $i, $i*2 )
    return("double value and return to call point: $i")
    }function(print_var, $i)
    set( $j, function(print_var, 10) ) // call and keep return value
    text(10, 40, "Return string is: $j") // show return value
  • Result:
    Value i: 10
    Return value is: double value and return to call point: 20

5.5 Function with parameters (pass by reference)

Pass by reference is tricky and fake. Actually parameters into function cannot access any pointer because garbage collector will protecting all variable stuff.

  • Example:
    {
    text(10, 10, "Value i: $i")
    add($i, 10)
    set($ri, $i)
    }function(print_var, $i)
    int($ri, 10)
    function(print_var, $ri)
    text(10, 40, "Value ri: $ri") // print a tricky value :-P
  • Result:
    Value i: 10
    Value ri: 20

6. Procedure

  • A procedure in ARSA is a scope of code in single line and use >> be a sign API separate.
    proc( ... >> ... >> ... )
  • Example:
    proc( set( $i, 10 ) >> text(10, 10, "Value i: $i") )
  • Result:
    Value i: 10

7. If..else statement

  • The expression in the if keywords must have a boolean type. If the expression get to true then the ARSA API will executed.
  • Sign to compare expression is:
    1. >
    2. <
    3. >=
    4. <=
    5. ==
    6. !=

7.1 If statement

  • This is a one expression comparison
    if( expression ) statement
  • Example:
    set( $i, 10 )
    if( $i == 10 ) text(10, 10, "i = 10")
  • Result:
    i = 10

7.2 If else statement

  • If the expression evaluates is false, then the statement2 is call, otherwise: expression is true statement1 will call.
    ifelse( expression, statement1, statement2 )
  • Example:
    set( $i, 20 )
    ifelse( $i==10, text(10,10,"Value i = 10"), text(10,10, "Value i != 10") )
  • Result:
    Value i != 10

7.3 If and &&

  • If two expressions with && (and) operator
    if( expression1 ) if( expression2 ) statement
  • Example:
    set( $i, 10 )
    if( $i >= 5 ) if( $i <= 10 ) text(10, 10, "5 >= i <= 10")
  • Result:
    5 >= i <= 10

7.4 If and ||

  • If two expressions with || (or) operator
    if( expression1 ) statement
    if( expression2 ) statement
  • Example:
    set( $i, 20 )
    if( $i >= 5 ) text(10, 10, "i >= 5")
    if( $i >= 10 ) text(10, 40, "i >= 10")
  • Result:
    i >= 5
    i >= 10

7.5 If and recursive

  • If expressions can be recursive itself.
    if( expression1 ) if( expression2 ) if( expression3 ) if( expression4 ) ... if( expression N ) statement
  • Example:
    set( $i, 20 )
    set( $j, 20 )
    set( $k, 20 )
    if( $i >= 5 ) if( $j >= 10 ) if( $k >= 20 ) text(10, 10, "Bingo!")
  • Result:
    Bingo!

7.6 If else and recursive

  • If else expressions can be recursive itself.
    ifelse( expression1, statement, ifelse( expression2, statement, ifelse( expression3, statement, ifelse( expression N, statement1, statement2 ) ) ) )
  • Example:
    int( $score, 79 )
    text( 10, 10, "Score: $score" )
    ifelse( $score>=80, set($grade,"A"), ifelse( $score>=70, set($grade,"B"), ifelse( $score>=60, set($grade,"C"), ifelse( $score>=50, set($grade,"D"), set( $grade,"F" )))))
    text( 10, 40,"Grade is: $grade")
  • Result:
    Score: 79
    Grade is: B

7.7 If and function

  • If have more one statement, user can use function instead single API.
    {
    // write code here
    ...
    ...
    ...
    }function(test)
    if( expression ) function(test)
  • Example:
    {
    text(10, 10, "i = 10")
    text(10, 40, "This text print from function!")
    }function(print_text)
    set( $i, 10 )
    if( $i == 10 ) function(print_text)
  • Result:
    i = 10
    This text print from function!

8. For loop

  • Call a statement repeatedly, until the value of expression becomes false.

8.1 For with single statement

  • Single statment run under for loop
    for ( init_condition ; cond_expression ; iteration_expression ) loop_statement
    1. init_condition initial an expression or a declaration
    2. cond_expression is checking before jump to a loop statement. If the result of the expression to false, the loop statement is done.
    3. iteration_expression is run after loop statement done and may increase or decrease value inside variable.
  • Example:
    for($i = 0; $i < 10; ++$i) text( 10, 10+(30*$i), "i = $i" )
  • Result:
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 5
    i = 6
    i = 7
    i = 8
    i = 9

8.2 For with multi statements (Function)

  • Function can be a statement inside for loop and can combination many ARSA API.
  • Example:
    {
    if($i == 0) text( 10, 10, "Print text from function." )
    text( 10, 40+(30*$i), "i = $i" )
    }function(print)
    for($i = 0; $i < 10; ++$i) function(print)
  • Result:
    Print text from function.
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 5
    i = 6
    i = 7
    i = 8
    i = 9

8.3 For with break, continue or return (Function)

  • User can only SKIP for loop through break, continue or return.
  • Example: skip with break, continue or return
    {
    text( 100, 10+(30*$i), "Print text from function with break continue or return: $i" )
    if($i > 3) break() // user can change to continue() or return(), same result.
    text( 10, 10+(30*$i), "i = $i" )
    }function(print)
    for($i = 0; $i < 10; ++$i) function(print)
  • Result:
    i = 0 Print text from function with break continue or return: 0
    i = 1 Print text from function with break continue or return: 1
    i = 2 Print text from function with break continue or return: 2
    i = 3 Print text from function with break continue or return: 3
    Print text from function with break continue or return: 4
    Print text from function with break continue or return: 5
    Print text from function with break continue or return: 6
    Print text from function with break continue or return: 7
    Print text from function with break continue or return: 8
    Print text from function with break continue or return: 9

8.4 For with multi statements (Procedure)

  • Procedure is difference function when call in for loop, The pointer should stay in same heap of for loop then user can stop the loop on the fly.
  • Warning: Becareful the Bracket!!!
  • Example:
    for($i = 0; $i < 10; ++$i) proc( if($i == 0) text( 10, 10, "Print text from procedure." ) >> text( 10, 40+(30*$i), "i = $i" ) )
  • Result:
    Print text from procedure.
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 5
    i = 6
    i = 7
    i = 8
    i = 9

8.5 For with break, continue or return (Procedure)

  • User can skip, stop for loop through break, continue or return.
  • Example 1: stop with break or return (same result)
    for($i = 0; $i < 10; ++$i) proc( text( 100, 10+(30*$i), "Print text from procedure with break or return: $i" ) >> if($i > 3) break() >> text( 10, 10+(30*$i), "i = $i" ) )
  • Result:
    i = 0 Print text from function with break or return: 0
    i = 1 Print text from function with break or return: 1
    i = 2 Print text from function with break or return: 2
    i = 3 Print text from function with break or return: 3
    Print text from function with break or return: 4
  • Example 2: skip with continue
    for($i = 0; $i < 10; ++$i) proc( text( 100, 10+(30*$i), "Print text from procedure with continue: $i" ) >> if($i > 3) continue() >> text( 10, 10+(30*$i), "i = $i" ) )
  • Result:
    i = 0 Print text from function with continue: 0
    i = 1 Print text from function with continue: 1
    i = 2 Print text from function with continue: 2
    i = 3 Print text from function with continue: 3
    Print text from function with continue: 4
    Print text from function with continue: 5
    Print text from function with continue: 6
    Print text from function with continue: 7
    Print text from function with continue: 8
    Print text from function with continue: 9

9. While loop

  • Call a statement repeatedly same for loop, until the value of expression becomes false.

9.1 While with procedure statement

  • Syntax while loop
    while( cond_expression ) loop_statement
    1. cond_expression is checking before jump to a loop statement. If the result of the expression to false, the loop statement is done.
    2. iteration_expression is run after loop statement done and may increase or decrease value inside variable.
  • Example: Using together with procedure and variable.
    int($i,0)
    while($i<10) proc( text(10,($i*30)+40, "i = $i") >> add($i, 1) )
  • Result:
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 5
    i = 6
    i = 7
    i = 8
    i = 9

9.2 While with multi statements (Function)

  • Function can be a statement inside while loop and can combination many ARSA API.
  • Example:
    {
    if($i == 0) text( 10, 10, "Print text from function." )
    text( 10, 40+(30*$i), "i = $i" )
    add($i, 1)
    }function(print)
    int($i,0)
    while($i < 10) function(print)
  • Result:
    Print text from function.
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 5
    i = 6
    i = 7
    i = 8
    i = 9

9.3 For with break, continue or return (Function)

  • User can only SKIP while loop through break, continue or return.
  • Example: skip with break, continue or return
    {
    add($i,1)
    text( 100, 10+(30*$i), "Print text from function with break continue or return: $i" )
    if($i > 3) break() // user can change to continue() or return(), same result.
    text( 10, 10+(30*$i), "i = $i" )
    }function(print)
    int($i,0)
    while($i < 10) function(print)
  • Result:
    i = 1 Print text from function with break continue or return: 1
    i = 2 Print text from function with break continue or return: 2
    i = 3 Print text from function with break continue or return: 3
    Print text from function with break continue or return: 4
    Print text from function with break continue or return: 5
    Print text from function with break continue or return: 6
    Print text from function with break continue or return: 7
    Print text from function with break continue or return: 8
    Print text from function with break continue or return: 9
    Print text from function with break continue or return: 10

9.4 While with multi statements (Procedure)

  • Procedure is difference function when call in while loop, The pointer should stay in same heap of while loop then user can stop the loop on the fly.
  • Warning: Becareful the Bracket!!!
  • Example:
    int($i,0)
    while($i < 10) proc( if($i == 0) text( 10, 10, "Print text from procedure." ) >> text( 10, 40+(30*$i), "i = $i" ) >> add($i,1))
  • Result:
    Print text from procedure.
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 5
    i = 6
    i = 7
    i = 8
    i = 9

9.5 While with break, continue or return (Procedure)

  • User can skip, stop while loop through break, continue or return.
  • Example 1: stop with break or return (same result)
    int($i, 0)
    while($i < 10) proc( add($i,1) >> text( 100, 10+(30*$i), "Print text from procedure with break or return: $i" ) >> if($i > 3) break() >> text( 10, 10+(30*$i), "i = $i" ) )
  • Result:
    i = 1 Print text from function with break or return: 1
    i = 2 Print text from function with break or return: 2
    i = 3 Print text from function with break or return: 3
    Print text from function with break or return: 4
  • Example 2: skip with continue
    int($i, 0)
    while($i < 10) proc( add($i,1) >> text( 100, 10+(30*$i), "Print text from procedure with break or return: $i" ) >> if($i > 3) continue() >> text( 10, 10+(30*$i), "i = $i" ) )
  • Result:
    i = 1 Print text from function with continue: 1
    i = 2 Print text from function with continue: 2
    i = 3 Print text from function with continue: 3
    Print text from function with continue: 4
    Print text from function with continue: 5
    Print text from function with continue: 6
    Print text from function with continue: 7
    Print text from function with continue: 8
    Print text from function with continue: 9
    Print text from function with continue: 10

10. Array (Static)

  • Array is a set of data (int, float or string) in memory sequentially.
  • Array map (Ascii art)
    --- --- --- ---
    data: | A | | B | | C | | D |
    --- --- --- ---
    index: 0 1 2 3

10.1 Initialize and show data in array.

  • This section show api to allocate memory as array.
  • Example 1: Array int
    int($data[10], 0) // allocate array 10 slot and set 0 to initial value.
    for($i = 0; $i < 10; ++$i) text( 10, 10+(30*$i), "$i. data = $data[$i]" ) // print value in array
  • Result:
    data[0] = 0
    data[1] = 0
    data[2] = 0
    data[3] = 0
    data[4] = 0
    data[5] = 0
    data[6] = 0
    data[7] = 0
    data[8] = 0
    data[9] = 0
  • Example 2: Array float and string
    float($data[10], 0) // allocate array 10 slot and set 0 to initial value.
    float($data_f[10], 10.456)
    float($data_str[10], "Hello World")
    text( 10, 10, "slot int float string")
    for($i = 0; $i < 10; ++$i) text( 10, 30+(30*$i), "data[$i] $data[$i] $data_f[$i] $data_str[$i]" )
  • Result:
    slot int float string
    data[0] 0 10.456 Hello World
    data[1] 0 10.456 Hello World
    data[2] 0 10.456 Hello World
    data[3] 0 10.456 Hello World
    data[4] 0 10.456 Hello World
    data[5] 0 10.456 Hello World
    data[6] 0 10.456 Hello World
    data[7] 0 10.456 Hello World
    data[8] 0 10.456 Hello World
    data[9] 0 10.456 Hello World

10.2 Set value to array slot.

  • Array can be use same normaly variable.
  • Example:
    int($data[10], 0) // allocate array 10 slot and set 0 to initial value.
    set($data[0], 10)
    set($data[1], 20)
    set($data[2], 30)
    set($data[3], 40)
    set($data[4], 50)
    set($data[5], 60)
    set($data[6], 70)
    set($data[7], 80)
    set($data[8], 90)
    set($data[9], 100)
    for($i = 0; $i < 10; ++$i) text( 10, 10+(30*$i), "$i. data = $data[$i]" ) // print value in array
  • Result:
    data[0] = 10
    data[1] = 20
    data[2] = 30
    data[3] = 40
    data[4] = 50
    data[5] = 60
    data[6] = 70
    data[7] = 80
    data[8] = 90
    data[9] = 100

11. Array (Dynamic) - 2.3.7E above!

  • Dynamic array given a power manage a set of data to be: add, remove, get, insert, erase or clear through API.
  • Dynamic array allow using N dimension array.

11.1 Initialize, add and print data in array.

  • Example 1: Initialize, add and print data in array.
    set( $id, array() ) // init dynamic array
    // add data to tail of array
    array.push_back($id, 10)
    array.push_back($id, 20)
    array.push_back($id, 30)
    array.push_back($id, 40)
    array.push_back($id, 50)
    // print data in array
    for($i=0; $i<array.size($id); ++$i) text( 10, 10+(30*$i), array.get($id, $i) )
    // free array
    array.close($id)
  • Result:
    10
    20
    30
    40
    50
  • Example 2: Initialize, add and print data in array with array.for()
    set( $id, array() ) // init dynamic array
    // add data to tail of array
    array.push_back($id, 10)
    array.push_back($id, 20)
    array.push_back($id, 30)
    array.push_back($id, 40)
    array.push_back($id, 50)
    // print data in array with array.for()
    set($i, 0)
    array.for($id, proc( text( 10, 10+(30*$i), array.get($id, null)) >> add($i,1) ) )
    // free array
    array.close($id)
  • Result:
    10
    20
    30
    40
    50

11.2 Add data to array with push_front and insert.

  • Example: Add data to array with push_front and insert.
    set( $id, array() ) // init dynamic array
    // add data to tail of array
    array.push_back($id, 10)
    array.push_back($id, 20)
    array.push_back($id, 30)
    array.push_back($id, 40)
    array.push_back($id, 50)
    // add data to head of array
    array.push_front($id, 60)
    array.push_front($id, 70)
    // insert
    array.insert($id, 500, 1)
    array.insert($id, 1000, 5)
    // print data in array
    for($i=0; $i<array.size($id); ++$i) text( 10, 10+(30*$i), array.get($id, $i) )
    // free array
    array.close($id)
  • Result:
    70 // push_front 70
    500 // insert 1
    60 // push_front 60
    10
    20
    1000 // insert 5
    30
    40
    50

11.3 Set data in array.

  • Example: Set data in array.
    set( $id, array() ) // init dynamic array
    // add data to tail of array
    array.push_back($id, 10)
    array.push_back($id, 20)
    array.push_back($id, 30)
    array.push_back($id, 40)
    array.push_back($id, 50)
    array.set($id, 2, 1000 ) // set new data in slot 2 to 1000
    array.set($id, 4, 2000 ) // set new data in slot 4 to 2000
    // print data in array
    for($i=0; $i<array.size($id); ++$i) text( 10, 10+(30*$i), array.get($id, $i) )
    // free array
    array.close($id)
  • Result:
    10
    1000 // new data change from 30 to 1000
    40
    2000 // new data change from 50 to 2000

11.4 Erase data in array.

  • Example: Erase data in array.
    set( $id, array() ) // init dynamic array
    // add data to tail of array
    array.push_back($id, 10)
    array.push_back($id, 20)
    array.push_back($id, 30)
    array.push_back($id, 40)
    array.push_back($id, 50)
    array.erase($id, 2 ) // remove slot 2, data = 30
    // print data in array
    for($i=0; $i<array.size($id); ++$i) text( 10, 10+(30*$i), array.get($id, $i) )
    // free array
    array.close($id)
  • Result:
    10
    20
    40
    50

11.5 Search data in array.

  • Example: Search data in array.
    set( $id, array() ) // init dynamic array
    // add data to tail of array
    array.push_back($id, 10)
    array.push_back($id, 20)
    array.push_back($id, 30)
    array.push_back($id, 40)
    array.push_back($id, 50)
    set( $slot, array.search($id, 30 ) ) // search 30 in array, if found return slot of array, otherwise return -1
    ifelse($slot != -1, text(10,10,"30 is in slot: $slot"), text(10,10, "Not found!"))
    // free array
    array.close($id)
  • Result:
    30 is in slot: 2

11.6 2 dimensions array.

  • Example: 2 dimensions array.
    set( $id, array() ) // init first dynamic array
    array.push_back($id, array()) // add second array to first array
    array.push_back($id, array()) // add third array to first array
    array.push_back($id, array()) // add forth array to first array
    // add element to sub array
    for($i=0; $i<array.size($id); ++$i) for($j=0; $j<5; ++$j) array.push_back(array.get($id,$i), ($i+1)*($j+1))
    // print element in sub array
    text(10, 10, "slot0 slot1 slot2")
    for($i=0; $i<array.size($id); ++$i) for($j=0; $j<array.size(array.get($id,$i)); ++$j) text( 10+(100*$i), 30+(30*$j), array.get(array.get($id,$i), $j) )
    // free sub array
    array.for($id, array.close(array.get($id, null)) )
    // free array
    array.close($id)
  • Result:
    slot0 slot1 slot2
    1 2 3
    2 4 6
    3 6 9
    4 8 12
    5 10 15

12. Structure (Static)

  • Type data in memory, user can define member and combine them to a superset through alias name.
  • Structure allow using static array.
  • Structure map (Ascii art)
    ---------------------
    alias: | name |
    --- --- --- ---
    elements:| A | | B | | C | | D |
    --- --- --- ---

12.1 Initialize, set value and print data in structure.

  • Example: Initialize, set value and print data in structure.
    // allocate structure given name is $Player
    struct($Player,Name,Hp,Att,Def,Int)
    // set
    set($Player.Name, "Saros")
    set($Player.Hp, 1000)
    set($Player.Att, 58)
    set($Player.Def, 45)
    set($Player.Int, 60)
    // print
    text(10, 40, "Name: $Player.Name")
    text(10, 70, "ATT: $Player.Att")
    text(10, 100, "DEF: $Player.Def")
    text(10, 130, "INT: $Player.Int")
  • Result:
    Name: Saros
    ATT: 58
    DEF: 45
    INT: 60

12.2 Static array of structure.

  • Example: Static array of structure.
    // allocate 3 slot of structure array
    struct($Player[3],Name,Hp, Att, Def, Int)
    // set data slot 1
    setstring($Player[0].Name,"Jerido")
    set($Player[0].Hp,500)
    set($Player[0].Att,75)
    set($Player[0].Def,22)
    set($Player[0].Int,50)
    // set data slot 2
    setstring($Player[1].Name,"Mu")
    set($Player[1].Hp,550)
    set($Player[1].Att,60)
    set($Player[1].Def,25)
    set($Player[1].Int,45)
    // set data slot 3
    setstring($Player[2].Name,"Exact")
    set($Player[2].Hp,600)
    set($Player[2].Att,70)
    set($Player[2].Def,30)
    set($Player[2].Int,50)
    // print data with for loop and procedure
    for($i=0; $i<3; ++$i) proc( text(10+($i*200), 40, "Name: $Player[$i].Name") >> text(10+($i*200), 70, "ATT: $Player[$i].Att") >> text(10+($i*200), 100, "DEF: $Player[$i].Def") >> text(10+($i*200), 130, "INT: $Player[$i].Int") )
  • Result:
    Name: Jerido Name: Mu Name: Exact
    ATT: 75 ATT: 60 ATT: 70
    DEF: 22 DEF: 25 DEF: 30
    INT: 50 INT: 45 INT: 50

13. File

  • File operation in ARSA language allow read, write text file and add/remove archive through the API.
  • File map (Ascii art)
    ----------------------------
    | FILE |
    ----------------------------
    | read | | write | | archive |
    ----------------------------
    | text | | zip |
    | ascii | | gzip |
    | utf8 | | pak |
    | | | tar |
    ----------------------------

13.1 Write file

  • Example: Write file
    {
    set( $fp, fopen("test.txt", "w") ) // open write file
    // write text to file
    fprintf( $fp, "Hello World\n") // with line break
    fprintf( $fp, "How are you?\n") // with line break
    fprintf( $fp, "I'm good.")
    fclose($fp, "w") // close write file
    }function(init)
  • Result: User got a new file name is: test.txt ->
    Hello World
    How are you?
    I'm good.

13.2 Read file

  • Example 1: Read file with fgets()
    set( $fp, fopen("test.txt", "r") ) // open read file
    // read and print text on screen
    text(10, 10, fgets($fp) ) // Hello World
    text(10, 40, fgets($fp) ) // How are you?
    text(10, 70, fgets($fp) ) // I'm good.
    fclose($fp, "r") // close read file
  • Result:
    Hello World
    How are you?
    I'm good.
  • Example 2: Read file and end of file.
    set( $fp, fopen("test.txt", "r") ) // open read file
    // read until end of file using: feof() and fgets()
    set($i, 0)
    while(1) proc( if(feof($fp)==true) break() >> text(10, 10+($i*30),fgets($fp)) >> add($i, 1) )
    fclose($fp, "r") // close read file
  • Result:
    Hello World
    How are you?
    I'm good.

13.3 Add and remove archive.

  • Add and remove zip archive file and load psd inside zip.
  • fremove() is optional, if program code inside body need file from zip then you not remove this because garbage collector will remove when program exit automatically.
  • Example:
    {
    fadd("animate.zip", "r") // add zip to filesystem.
    psd("animate.psd") // change to psd, load from zip file.
    // fremove("animate.zip") // optional, remove zip from filesystem.
    }function(init)

13.4 Add and remove archive with password.

  • Add and remove zip archive file with password and load psd inside zip.
  • fremove() is optional, if program code inside body need file from zip then you not remove this because garbage collector will remove when program exit automatically.
  • Example:
    {
    fadd("animate_pw.zip", "r", true, "", "zip", "helloworld") // add zip to filesystem.
    psd("animate.psd") // change to psd, load from zip file.
    // fremove("animate_pw.zip") // optional, remove zip from filesystem.
    }function(init)

13.5 Add and remove archive with google drive.

  • Add and remove gzip archive file with google drive and load psd inside gzip.
  • Using gzip instead zip
  • Google drive url should:
    1. Share to public, anyone has link can view
    2. Generate Google Drive Direct Link and copy to filename
    3. Given alias filename for remove from filesystem.
  • Download from google drive is synchronous in main thread, now loading screen is good way to notify user before call fadd()
  • Set cache to false in fadd(), that mean is download done then program will save file from google drive to storage disk with alise name given.
  • fremove() is optional, if program code inside body need file from zip then you not remove this because garbage collector will remove when program exit automatically.
  • Example:
    {
    psd("nowloading.psd") // show now loading screen
    drawonce() // drawing screen immediately
    // load from google drive and add to filesystem be name is animate_temp_gz
    fadd("https://drive.google.com/uc?export=download&id=1voNuYzWzUYPPog0SHj--RWcf7O5mTyhJ", "r", false, "animate_temp_gz")
    psd("animate.psd") // change to psd, load from gzip file.
    // optional, remove zip from filesystem.
    // fremove("animate_temp_gz") // remove gzip from filesystem.
    }function(init)

14. Random

15. Timer

  • Timer can get from system and 3 difference type are Virtualtime, Realtime and Deltatime.
  • Virtualtime is synchronous time generate from main loop, if pause main loop then virtualtime should stop too, Value is millisecond.
  • Realltime is a synchronous time generate from system, pause main loop no effect this, Value is millisecond.
  • Deltatime is time difference from previous frame, Value is float.
  • Example:
    {
    set( $t0, gettime() ) // get virtual time
    set( $t1, getrealtime() ) // get real time
    set( $dt, getdeltatime() ) // get delta time
    set( $second, $t0/1000 ) // get second
    }function(init)
    // display text
    text(10, 10, "virtualtime: $t0" )
    text(10, 30, "realtime: $t1" )
    text(10, 50, "deltatime: $dt" )
    text(10, 70, "second: $second" )
  • Result
    virtualtime: 195274
    realtime: 9798375
    deltatime: 0.018000
    second: 195.274

16. Frame per Second (FPS)

  • Frame per Second (FPS) is speed of frame flip in a second.
  • 60 FPS is default, 30 FPS is a half speed.
  • User can set limit FPS through API.
  • Example:
    {
    }function(init)
    text(10,10, getcurrentfps()) // current fps
    text(10,30, getgamefps()) // value from setgamefps()
    -Result:
    31
    30