Using the Script Engine

From GPU

Contents

Introduction

The purpose of the Script Engine is to make calculating things with GPU more easy (or more complex). You do almost any calculation, because it doesn't only have fixed commands, but can use the commands implemented inside gpu as well. The downside with the Script Engine is that it may be hard to understand, but with a little bit help you will get there.

Variables, strings and other datatypes

To make the script engine more dynamic, you can use variables instead of numerical values.
The syntax for this would be:
#var_nr
This would result in the folowing:
pse 1000
Would give the same result as:
set 1,1000
pse #1

There also is a way to use variables inside strings.
This is done by using var(var_nr) inside a string.
Example:
out "Variable 1=var(1)"

The first variable (var(0)) contains the version number of the script engine.
This could be used to check for version compatibility.

Functions

This is a list of functions:

set var#, dec_nr

This puts the value dec_nr in variable var#.
Example:
set 1,10
This stores the value 10 in variable 1.

cpy source_var#, dest_var#

Copies the value of variable(source_var#) to variable(dest_var#).
Example:
cpy 1,2
This copies the value of variable 1 to variable 2.

snd "string, var(#) is replaced",var#_result

Sends a GPU stack command to the cluster
Example:
snd "1,2,add",1
This will send the command 1,2,add to the cluster.
The answer is stored in variable 1 in this format: result1,result2,...,resultn
Double results are filtered, so no double results are returned.

out "string, var(#) is replaced"

This outputs a string to the
Example:
set 1,10
This stores the value 10 in variable 1.

skp lines_to_skip

This skips the execution pointer.
Example:
skp 10
or
skp -5

This would make the pointer skip 10 lines, or go 5 lines back.

gto line

This makes the execution pointer skip to a fixed position
The line numbering starts at 0 (the first line is number 0). Example:
gto 5
This makes the execution pointer jump to line 5.

equ var#_first, var#_second, var#_store

Checks if var#_first equals var#_second, and if so, stores 1 in var#_store. If not, then 0 is stored.
Example:
set 1,4
set 2,4
equ 1,2,3
out "var(1) equals var(2) = var(3)"

This checks if variable 1 equals variable 2.

big var#_first, var#_second, var#_store

Checks if var#_first is bigger than var#_second, and if so, stores 1 in var#_store. If not, then 0 is stored.
Example:
set 1,5
set 2,4
equ 1,2,3
out "var(1) is bigger than var(2) = var(3)"

This checks if variable 1 is bigger than variable 2.

sml var#_first, var#_second, var#_store

Checks if var#_first is smaller than var#_second, and if so, stores 1 in var#_store. If not, then 0 is stored.
Example:
set 1,3
set 2,4
equ 1,2,3
out "var(1) is smaller than var(2) = var(3)"

This checks if variable 1 is smaller than variable 2.

add var#, var#

This adds the second variable to the first.
Example:
set 1,10
set 2,5
add 1,2

Adds 5 to 10, and stores it in variable 1.

sub var#, var#

This substracts the second variable of the first.
Example:
set 1,10
set 2,5
sub 1,2

Substracts 5 from 10, and stores it in variable 1.

mul var#, var#

This multiplies the second variable with the first.
Example:
set 1,10
set 2,5
sub 1,2

Multiplies 5 with 10, and stores it in variable 1.

div var#, var#

This divides the first variable with by the second.
Example:
set 1,10
set 2,5
sub 1,2

Divides 10 by 5, and stores it in variable 1.

mem dec_size

Registers additional memory (the regular vars only go up to 100) by the size of dec_size
Example:
mem 100 </code>
Registers 100 extra variables.

mcp var#, mem#

This puts the value of the variable in the specified memory spot.
Example:
set 1,4
mem 10
mcp 1,1

This puts the value 4 in the memory position 1.

mgt mem#, var#

This retreives the value of the memory and puts it in the specified variable.
Example:
set 1,4
mem 10
mcp 1,1
mgt 1,1

This puts the value 4 in the memory position 1 and places it in variable 2..

pse dec_miliseconds

Pauses the script dec_miliseconds miliseconds.
This can be used to wait for results from the GPU cluster. Example:
pse 1000
This pauses the script for one second.

If you have any additional questions, feel fry to ask them on the chat.