Variables

Rockstar variables are dynamically typed. There are three different ways to assign a variable in Rockstar.

  1. <variable> is <expression>. Valid aliases for is are are, am, was, were, and the contractions 's and 're
  2. put <expression> into <variable>
  3. let <variable> be <expression>
x is 1. Print x (prints: 1)
Y was 2. Print y (prints: 2)
z is -1. Print z (prints: -1)
The limit's 55. Print the limit. (prints: 55)

Put 12 into a variable. Print a variable. (prints: 12)
Let my variable be 34. Print my variable (prints: 34)

Put nothing into the fire. Print the fire. (prints: null)
Let the fire be silence. Print the fire. (prints: )


Rockstar variables are function scoped - see variable scope in the section on functions for more about how this work.

Variable names in Rockstar

Rockstar supports three different kinds of variable names.

Simple variables can be any valid identifier that isn’t a reserved keyword. A simple variable name must contain only letters, and cannot contain spaces. Note that Rockstar does not allow numbers or underscores in variable names - remember the golden rule of Rockstar syntax: if you can’t sing it, you can’t have it. Simple variables are case-insensitive.

x is 2
pi is 3.14159
greeting is "hello world"

say x (prints: 2)
say pi (prints: 3.14159)
say greeting (prints: hello world)

Common variables consist of one of the keywords aanthemyyour or our followed by whitespace and an identifier. The keyword is part of the variable name, so a boy is a different variable from the boy. Common variables are case-insensitive.

Common variables can include language keywords, so you can have variables called your scream, my null, the silence.

The greeting is "hello world"
SHOUT THE GREETING (prints: hello world)

A number is 12
Our flag is "death"
print a number (prints: 12)
print our flag (prints: death)

The variable is 1
my variable is 2
Your variable is 3
Say the variable (prints: 1)
Say my variable (prints: 2)
Say your variable (prints: 3)

The silence is nothing
Scream the silence (prints: null)
Your scream is "aargh!"
Scream your scream (prints: aargh!)

Proper variables are multi-word proper nouns: words which aren’t language keywords, each starting with an uppercase letter, separated by spaces. (Single-word variables are always simple variables.) Whilst some developers may use this feature to create variables with names like Customer IDTax Rate or Distance In Kilometres, we recommend you favour idiomatic variable names such as Doctor FeelgoodMister CrowleyTom Sawyer, and Billie Jean.

A note on case sensitivity in Rockstar

Rockstar keywords and variable names are all case-insensitive, with the exception of proper variables. Proper variables are case-insensitive apart from the first letter of each word, which must be a capital letter.

  • TIMEtimetIMeTIMe are all equivalent. Simple variables are case-insensitive.
  • MY HEARTmy heartMy Heart - are all equivalent; the keyword my triggers common variable behaviour
  • Tom SawyerTOM SAWYERTOm SAWyer - are all equivalent; the capital S on Sawyer triggers proper variable behaviour
  • DOCTOR feelgood is not a valid Rockstar variable; the lowercase f on feelgood does not match any valid variable naming style and so the variable name is not valid.

Pronouns

As well as referring to variables by name, you can refer to them using pronouns. The keywords itheshehimhertheythemzehirziezirxexemve, and ver refer to the current pronoun subject.

The pronoun subject is updated when:

  • A variable is declared or assigned:

    My heart is true. Say it - it here refers to my heart

  • A variable is the left-hand side of a comparison used as the condition in an if, while or until statement

    If my heart is true, give it back, yeah - it refers to my heart

The number is 1. Shout it (prints: 1)
It is 2. Shout it (prints: 2)
The string is "hello". Print it (prints: hello)
It is "world". Print it (prints: world)
Print the number (prints: 2)
Print the string (prints: world)

Doctor Feelgood is right. Scream Doctor Feelgood (prints: true)
He is wrong. Scream Doctor Feelgood (prints: false)

The Darkness are 1. Shout the darkness (prints: 1)
They are 2. Shout them (prints: 2)

Alpha is 1
Beta is 2
If alpha is 1 print it (prints: 1)

Gamma is 3
Delta is 4
While gamma ain't nothing, write it. Knock it down, yeah. (writes: 321)



(Please don’t file issues pointing out that 80s rockers were a bunch of misogynists and gender-inclusive pronouns aren’t really idiomatic. You’re right, we know, and we’ve all learned a lot since then. Besides, Look What The Cat Dragged In was recorded by four cishet guys who spent more money on lipgloss and hairspray than they did on studio time, and it’s an absolute classic.)

The Thing About “Her”

her is where Rockstar runs smack into one of the English language’s most delightful idiosyncrasies, because the feminine third person pronoun and the feminine possessive are the same word.

Give him his guitar. Give them their horns. Give her her bass

There is therefore a very specific restriction in the Rockstar grammar: you can’t use her as a common variable prefix if the second part of the variable is a keyword.

You can have variables called the times, your lies, my right, even though times, lies and right are language keywords, but you can’t have her times or her lies because they’d create ambiguous expressions:

A girl is 123
Her times are trying
Say her
Say her times 456

Poetic Literals

One of Rockstar’s unique features is the ability to initialise variables using song lyrics.

Poetic Numbers

A poetic number begins with the like or so keyword, followed by a series of words. The Rockstar parser takes the length of each word and interprets it as a decimal digit:

Shout like a big bad monster (prints: 1337)
Scream like a banshee (prints: 17)

Papa was like a rolling stone. Shout Papa. (prints: 175)

the fire is like a shadow, the stars are like the rain
Shout the fire (prints: 16353434)

My dreams are so dark
Scream my dreams (prints: 4)

Words of 10 or more letters are counted modulo 10, so you can use 10-letter words for 0, 11 letters for 1 and 12 letters for 2. Hyphens - are counted as letters, so demon-haunted is treated as a 12-letter word. Apostrophes are not counted, so nothing counts as 7 but nothin' counts as 6. A poetic number counts every word until the end of the current statement (indicated by a newline or punctuation .!?;) If you need a poetic number with a decimal point, use an ellipsis ... or the Unicode equivalent U+2026 as the decimal.

Tommy's like a panther, he ain't talkin' 'bout love. Shout Tommy. (prints: 1724644)
He's like a wild animal.
Shout Tommy (prints: 146)

My heart was like ice... a life unfulfilled, wakin' everybody up, taking booze and pills.
Say it. (prints: 3.1415926535)

e is like my… darkest nightmarish longings, my cravings, a symphony of suff'ring that lasts life-long.
Say it. (prints: 2.718281828459)

Carrie's like a wolf. Danny's like a child. Print Carrie. (prints: 14)
Print Danny. (prints: 15)

Poetic strings

You can initialise string variables without quotes by using the says or said keyword. This will skip exactly one space character and then capture the rest of the line as a literal string. If the character immediately following the says keyword is not a space, it will be included in the string literal.

Tommy says we've got to hold on to what we've got.
Gina says it doesn't make a difference if we make it or not.

Print Tommy (prints: we've got to hold on to what we've got.)
Print Gina (prints: it doesn't make a difference if we make it or not.)

A variable says, I start with a comma.
Print a variable(prints: , I start with a comma.)

A variable says: I start with punctuation.
Print a variable (prints: : I start with punctuation.)

My string said it had "quotes", 'quotes', українська, עִבְרִית, 🎸✨🎆	and	tabs
Print my string (prints: it had "quotes", 'quotes', українська, עִבְרִית, 🎸✨🎆	and	tabs)

Ninja Strings

Ninja strings are another unique feature of Rockstar, designed to let you hide strings inside the lyrics of your Rockstar programs. Using the rock keyword - which we’ll learn more about in the chapter on arrays - you can append characters to the end of a string by providing their Unicode code point - and, combined with the like keyword, you can provide that code point as a poetic number:

A string is "A"
Rock it with 67
Rock it 47, 68
Rock it like raging thunder

Shout it (prints: AC/DC)

You can initialise a ninja string using the hold or holds keyword. The left-hand argument is the name of the variable you’re initialised, the right-hand side is the poetic number containing the code point of the character:

My dreams hold diamond nightmares
Salvation is the sea
My screams hold silent echoes
Your love is meaningless to me

Rock my dreams like a razorblade smile
Rock my dreams with your love, your love
Rock my screams like a heartbroken missile
Rock my screams with your love, your love.

My dreams are with my screams
Rock my dreams with salvation
Whisper my dreams