Conversions and Mutations
Conversions and Mutations
Most of Rockstar’s built-in operations can either act in place, modifying the variable passed to them, or leave the result in a target variable and leave the source unmodified:
Modify X
- acts in-placeModify X into Y
- leaveX
intact, store the result intoY
Modify X with Z
- act in place, using optional parameterZ
Modify X into Y with Z
- modifyX
usingZ
, store the result iny
Splitting Strings
To split a string in Rockstar, use the cut
mutation, or aliases split
and shatter
.
Split "a,b,c" into the array
Shout the array (prints: [ "a", ",", "b", ",", "c" ])
Shout the array + 0 (prints: 5)
Split "a,b,c" into the array with ","
Shout the array (prints: [ "a", "b", "c" ])
Shout the array + 0 (prints: 3)
My life says heartbreak
Cut my life into pieces
Shout pieces (prints: [ "h", "e", "a", "r", "t", "b", "r", "e", "a", "k" ])
Shout pieces + 0 (prints: 10)
Joining Arrays
To join an array in Rockstar, use the join
mutation, or the aliases unite
or gather
:
Let the string be "abcde"
Split the string into the tokens
Join the tokens with ";"
Print the tokens (prints: a;b;c;d;e)
The input says hey now hey now now
Split the input into the words with " "
Unite the words into the output with "! "
Print the output with "!" (prints: hey! now! hey! now! now!)
Gather the words into the output with "-"
Print the output (prints: hey-now-hey-now-now)
Type Conversions
To convert any value to a string, add it to the empty string.
Let the string be "abcde"
Split the string into the tokens
Join the tokens with ";"
Print the tokens (prints: a;b;c;d;e)
The input says hey now hey now now
Split the input into the words with " "
Unite the words into the output with "! "
Print the output with "!" (prints: hey! now! hey! now! now!)
Gather the words into the output with "-"
Print the output (prints: hey-now-hey-now-now)
The built-in cast
function (aka burn
) will parse strings into numbers, or convert a number into a Unicode character corresponding to the number’s code point.
Let X be "123.45"
Shout X + X (prints: 123.45123.45)
Cast X with 10
Shout X + X (prints: 246.9)
Let X be "FF"
Cast X with 16 (cast using base 16)
Shout X (prints: 255)
Cast 65 into result. Shout result (prints: A)
Cast result. Shout result (prints: 65)
Cast 1046 into result. Shout result (prints: Ж)
Guitar is "1F3B8". Cast it with 16. Cast it.
Shout it. (prints: 🎸)
The string is "32"
Cast the string into the codes
Write the codes at 0 (writes: 51)
Write the codes at 1 (writes: 50)
Arithmetic Rounding
Rounding in Rockstar is performed by the turn
keyword. Turn up
will round up (i.e. towards positive infinity), to the nearest integer; turn down
will round down (towards negative infinity) to the nearest integer, and turn round
will round to the nearest integer. Bonnie Tyler enthusiasts will be pleased to note that Rockstar accepts turn around
as a valid alias.
Turn operations act in-place: they modify the variable directly, and will return the rounded value.
X is 1.2
Turn up X
Shout X (will print 2)
X is 1.2
Turn down X
Shout X (will print 1)
The radio's playing. The night has just begun.
(initialises the radio with 7.35345)
Turn up the radio
Say the radio (will print 8)
Rounding supports variable pronouns, so you can write phrases like:
My heart is on fire. Aflame with desire.
Turn it up.
Shout it.
which will print the value 25 (obviously).