This is quick reference guide of ARSA Language.
1. How to writing an ARSA Language.
- [Option A] Start with Photoshop layer directly.
- Make sure your layer is absolutely empty or a fresh new layer.
- Rename layer by right click or single click on a layer name.
- Writing a code be instread old layer name.
- Save and try refresh a PSD file in ARSA Studio, press F5 or Edit -> Refresh PSD.
- [Option B] Start with any coding editor.
- Open you favorite editor e.g. VSCode, Edit+ or NotePad.
- Just writting a code and save to text file with any extension.
- Drag or Open directly to ARSA Studio, May you can using function psd("filename.psd") to loading a psd file.
- Use function arsalang("src_name.txt") in Photoshop layer.
- Debug.
- Open log window in ARSA Studio: Window -> Log Window or Ctrl+L
- Use alog() for print text or variable on log window.
- Use msgbox() to popup dialog message.
- Debug PSD mode for checking layer bounding: Edit -> Debug PSD or Ctrl+D
- Error Message.
- C0001: syntax error missing function.
- C0002: syntax error missing ( or )
- C0003: syntax error missing "
- C0004: syntax error missing { or }
- C0005: ARSA Language file not found!
- 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
- init, for allocate memory image, sound, movie or etc.
{
...
...
...
}function(init)
- update, this is a loop for update game/app logic.
- deinit, free memory after exit game/app.
{
...
...
...
}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")
- Result:
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.
Example: Local variables declaration variable one time in init function.
Example: Global variables declaration variable one time in init function.
- What's diference between Local-Global variables?
- Local will delete by garbage collector after load a new psd file.
- 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:
- 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:
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.
{
...
...
...
}function( name, parameters )
- A function definition in ARSA programming consists of a name and codes, so, parameters is optional:
- name: This is the name of the function. init, deinit and Math are reserved words.
- parameters: User can passing variables be parameters and sending into function. Parameters are optional, function may contain no parameters.
- code: coding contains a collection of ARSA api that define what the function does.
- Example:
{
text(10, 10, "Value i: $i")
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:
{
text(10, 10, "Value i: $i")
- Result:
- Example 2:
function(print_var)
{
text(10, 10, "Value i: $i")
- Result:
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)
- Result:
- Example 2:
{
text(10, 10,
"Value i: $i")
text(10, 40, "Value j: $j")
text(10, 70, "Value k: $k")
- 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")
text(10, 40, "Return value is: $j")
- Result:
Value i: 10
Return value is: 20
- Example 2: return string
{
text(10, 10,
"Value i: $i")
text(10, 40, "Return
string is: $j")
- 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")
int($ri, 10)
text(10, 40, "Value ri: $ri")
- Result:
6. Procedure
- A procedure in ARSA is a scope of code in single line and use >> be a sign API separate.
proc( ... >> ... >> ... )
- Example:
- Result:
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:
- >
- <
- >=
- <=
- ==
- !=
7.1 If statement
- This is a one expression comparison
if( expression ) statement
- Example:
if( $i == 10 )
text(10, 10, "i = 10")
- Result:
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:
ifelse( $i==10,
text(10,10,"Value i = 10"),
text(10,10, "Value i != 10") )
- Result:
7.3 If and &&
- If two expressions with && (and) operator
if( expression1 ) if( expression2 ) statement
- Example:
if( $i >= 5 )
if( $i <= 10 )
text(10, 10, "5 >= i <= 10")
- Result:
7.4 If and ||
- If two expressions with || (or) operator
if( expression1 ) statement
if( expression2 ) statement
- Example:
if( $i >= 5 )
text(10, 10, "i >= 5")
if( $i >= 10 )
text(10, 40, "i >= 10")
- Result:
7.5 If and recursive
- If expressions can be recursive itself.
if( expression1 ) if( expression2 ) if( expression3 ) if( expression4 ) ... if( expression N ) statement
- Example:
if( $i >= 5 )
if( $j >= 10 )
if( $k >= 20 )
text(10, 10, "Bingo!")
- Result:
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:
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:
7.7 If and function
- If have more one statement, user can use function instead single API.
{
...
...
...
}function(test)
if( expression ) function(test)
- Example:
- 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
- init_condition initial an expression or a declaration
- cond_expression is checking before jump to a loop statement. If the result of the expression to false, the loop statement is done.
- 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" )
- 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" )
text( 10, 10+(30*$i), "i = $i" )
- 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:
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
- cond_expression is checking before jump to a loop statement. If the result of the expression to false, the loop statement is done.
- iteration_expression is run after loop statement done and may increase or decrease value inside variable.
- Example: Using together with procedure and variable.
- 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" )
int($i,0)
- 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
{
text( 10, 10+(30*$i), "i = $i" )
int($i,0)
- 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:
- Result:
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)
- 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
- 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
for($i = 0; $i < 10; ++$i)
text( 10, 10+(30*$i), "$i. data = $data[$i]" )
- 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_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:
for($i = 0; $i < 10; ++$i)
text( 10, 10+(30*$i), "$i. data = $data[$i]" )
- 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.
- Result:
- Example 2: Initialize, add and print data in array with array.for()
- Result:
11.2 Add data to array with push_front and insert.
- Example: Add data to array with push_front and insert.
array.push_front($id, 60)
array.push_front($id, 70)
array.insert($id, 500, 1)
array.insert($id, 1000, 5)
- Result:
70
500
60
10
20
1000
30
40
50
11.3 Set data in array.
- Example: Set data in array.
- Result:
11.4 Erase data in array.
- Example: Erase data in array.
- Result:
11.5 Search data in array.
- Example: Search data in array.
ifelse($slot != -1,
text(10,10,"30 is in slot: $slot"),
text(10,10, "Not found!"))
- Result:
11.6 2 dimensions array.
- Example: 2 dimensions 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))
text(10, 10, "slot0 slot1 slot2")
- 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.
struct($Player,Name,Hp,Att,Def,Int)
set($Player.Name,
"Saros")
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.
struct($Player[3],Name,Hp, Att, Def, Int)
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 |
----------------------------
| ascii | | gzip |
| utf8 | | pak |
| | | tar |
----------------------------
13.1 Write file
- Example: Write file
- 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()
- Result:
Hello World
How are you?
I'm good.
- Example 2: Read file and end of 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:
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")
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:
- Share to public, anyone has link can view
- Generate Google Drive Direct Link and copy to filename
- 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:
14. Random
- Generate a number with random from seed time.
- Example: Random, random with length and random string.
- Result
random 20 digit: XQAOKV3MSFWINHH51M14
random 30 digit: PF3BPOTM4VPF0J58OU96NIIFIYZ176
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:
{
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: -Result: