Instructions
In PolyScript, instructions are the lines of code that 'do things', which can be anything from setting variables to spawning new polys.
In PolyScript, instructions are the lines of code that 'do things', which can be anything from setting variables to spawning new polys.
Instructions always begin with the instruction name in full uppercase and are followed by the relevant arguments (parameters), for example:
DEF number A = 5
The instruction above defines a numerical variable called 'A' and sets its value to 5.
Unlike most programming languages, every argument is separated by a single space and does not include the instruction name. Even the equals sign is technically an argument! The arguments of the above code are: number, A, = (sort of), and 5.
Here's another example of an instruction:
FETCH tone = "CurrentPoly" "tone"
The instruction above defines a variable called 'tone' and sets it to the tone of the current poly (the next poly coming up for the player).
Defined variables can also take the place of most arguments, for example:
DEF string fetchLocation = "CurrentPoly"
FETCH tone = fetchLocation "tone"
The remainder of this page will detail all of the instructions in PolyScript.
DEF [data type] [variable name] = [value]
Defines or redefines a variable.
[data type] —> The data type of the variable. Either number, string, or boolean, not wrapped in quotation marks.
[variable name] —> The name of the variable. Cannot have any characters other than letters, numbers, and underscores.
[value] —> The value of the variable. Must coincide with the data type chosen.
e.g.:
DEF number score = 10
DEF boolean clocked = false
DEF string name = "Gavis"
DEF string firstName = name
CALC [variable name] = [value 1] [operation] [value 2]
Defines or redefines a variable as the result of a calculation.
[variable name] —> The name of the variable to store the result. Cannot have any characters other than letters, numbers, and underscores.
[value 1] —> The first value to partake in the calculation. Must be a number.
[operation] —> The operation to perform. Either...
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
^ (exponentiation AKA 'to the power of')
% (modulo i.e. integer division but only gives the remainder)
[value 2] —> The second value to partake in the calculation. Must be a number.
e.g.:
DEF score = 0
DEF scoreIncrement = 5
CALC score = score + scoreIncrement
CALC loss = score * -0.5
FETCH [variable name] [=/#=] [master table] [table branch 1] [table branch 2] [table branch 3...]
Fetches a value from one Polyaudios' PolyScript-accessible tables. Using this incorrectly could crash your game!
[variable name] —> The name of the variable to store the result. Cannot have any characters other than letters, numbers, and underscores.
[=/#=] —> The setting operation to use. '=' sets [variable name] to the value accessed using the master table and table branches and '#=' sets [variable name] to the length of the list accessed (using the master table and branches). In the PolyScript FETCH/GAMESET diagram below, only the variables with a white-colored box can have their length read.
[master table] —> The name of the table you want to access (as a string). Either...
"CurrentLevel"
"CurrentPoly"
[table branch 1, 2, ... n] —> The names of the values within the master table you want to access (as strings). This follows a tree of values depending on the master table you access. Use the button below to view all the available master tables and their branches.
e.g.:
FETCH polyIndex = "CurrentLevel" "polyIndex"
FETCH poly3Tone = "CurrentLevel" "polys" 3 "tone"
FETCH toneCount #= "CurrentLevel" "tones"
GAMESET [master table] [table branch 1] [table branch 2] [table branch 3...] = [value]
Fetches a value from one Polyaudios' PolyScript-accessible tables. Using this incorrectly could crash your game!
[master table] —> The name of the table you want to access (as a string). Either...
"CurrentLevel"
"CurrentPoly"
[table branch 1, 2, ... n] —> The names of the values within the master table you want to access (as strings). This follows a tree of values depending on the master table you access. Use the button below to view all the available master tables and their branches.
[value] —> Any (defined) variable or data literal e.g. "hello", true, 10, playerScore etc. Be sure to match this value's data type to the proper data type of the value you want to modify, otherwise the game could crash.
e.g.:
GAMESET "CurrentPoly" "holding" = true
GAMESET "CurrentPoly" "tone" = "o"
GAMESET "CurrentLevel" "attemptCount" = 9999
RUNSECTION [section name]
Runs all the code in a section.
[section name] —> The section of which to run the code inside (can be an organizational section or a callback section). Use the button below to view all the existing sections that can be called upon.
e.g.:
onPolyTouch
DEF toneToSetTo = "C"
grey
GAMESET "CurrentLevel" "polys" 2 "tone" = toneToSetTo
\ grey
orange
RUNSECTION grey
\ orange
magenta
RUNSECTION onPolyTouch // runs 'DEF toneToSetTo = "C"'
\ magenta
\ onPolyTouch
IF [value 1] [comparative operator] [value 2]
// code...
END
Runs the code inside if and only if the associated conditional passes.
[value 1] —> A value to compare to value 2.
[comparative operator] —> How to compare value 1 to value 2. Either...
== (value 1 is equal to value 2?)
!= (value 1 is not equal to value 2?)
> (value 1 is greater than value 2?)
>= (value 1 is greater than or equal to value 2?)
< (value 1 is less than value 2?)
<= (value 1 is less than or equal to value 2?)
e.g.:
FETCH polyIndex = "CurrentLevel" "polyIndex"
IF polyIndex == 3
POLY spawn at 1 withdata: "orange" "0"
END
THROW! [error message]
Throws an error and stops execution.
[error message] —> Error message to use (string/number).
e.g.:
FETCH polyIndex = "CurrentLevel" "polyIndex"
THROW! polyIndex
THROW! "Hello there"
SOUND [instruction branch] [sound table] [sound name] [volume] [pitch]
Plays a sound.
[instruction branch] —> What branch of SOUND to use. Either...
play (play a sound)
[sound table] —> What sound table to access (string). Either...
"sfx" (SFX sounds like clicking, completing a challenge world, earning the crown, etc.)
"tones" (tone sounds like for t-sound polys, staccato polys, modules, etc.)
[sound name] —> The name of the sound from the sound table to play (string). Press the button below to open the list of all SFX and tone sounds.
[volume] —> The volume of the sound to play (number). Must be within the range [0, 1].
[pitch] —> The pitch of the sound to play (number). Doubling the pitch raises the sound by an octave and halving the pitch does the opposite. Must be greater than 0. Use the button below to learn more.
e.g.:
onGameEvent
resetGameData
SOUND play "sfx" "completedLevel" .6 2
\ resetGameData
\ onGameEvent
POLY [instruction branch] ...
Does something relating to polys.
[instruction branch] —> What branch of POLY to use. Either...
spawn (spawn a poly)
design (make a new poly type or tone)
POLY spawn at [spawn index] withdata: [poly type name] [poly tone]
Spawns a poly.
[spawn index] —> At what index to spawn the poly (number). This index is out of the whole poly sequence of the level, not only the polys left to hit. Must be at least 1.
[poly type name] —> The poly type's name (string) of the poly to spawn.
[poly tone] —> The tone (string) of the poly to spawn.
POLY design poly withdata: [internal identifier] [poly type name] [pre-lag] [width multiplier] [pitch] withcolor [r] [g] [b]
Designs a new poly type.
[internal identifier] —> What single character to associate with the poly type. Choosing an existing poly type's internal identifier will overwrite that poly type with the new poly you define here.
[poly type name] —> The name of the poly. Existing poly types have names like "red", "grey", and "green".
[pre-lag] —> The time the player must wait after the preceding poly to hit this poly in seconds.
[width multiplier] —> This number is mutliplied by "PolyGraphics" "poly" "width" to get the width of the poly to be drawn on-screen.
[pitch] —> The pitch of the poly. Use the button below to navigate to the Sounds subpage and learn more.
[r] —> The R channel of the RGB color of the new poly. Ranges from [0, 1], not [0, 255].
[g] —> The G channel of the RGB color of the new poly. Ranges from [0, 1], not [0, 255].
[b] —> The B channel of the RGB color of the new poly. Ranges from [0, 1], not [0, 255].
POLY design tone withdata: [tone character] [tone name] soundslike [existing tone character]
Designs a new poly type.
[tone character] —> What single character to represent the tone. Choosing an existing tone character for this argument may cause the game to crash.
[tone name] —> The name of the tone. Existing tones have names like "Staccato", "Tube", and "Module fake". This will be shown in the editor.
[existing tone character] —> What existing tone sound to use for this tone.
e.g.:
onPolyTouch
red
FETCH polyIndex = "CurrentLevel" "polyIndex"
CALC polyIndex = polyIndex + 1
POLY spawn at polyIndex withdata: "red" "I" // spawns an i-sound red hold poly right after the poly currently being hit
\ red
\ onPolyTouch