Skip to content

How use Rakugo Variables

Rakugo Variables are called RkVar for short. They are global, and accessible from both RkScript and GDScript.

You can define var in RakuScript file, like this:

player.life = 10
You can access it in any RakuScript:
narrator "You have <player.life> life points left"

You can change already existing var:

player.life += 5

Currently in RakuScript we can't do stuff like this:

a = 1
b = a + 1
c = 1 - 2
d = 2 * 2
e = 2 / 2

For now thanks to new features in 2.2, we can workaround this using variable assignments:

a = 1

# b = a + 1
b = a
b += 1

# c = 1 - 2
c = 1
c -= 2

# d = 2 * 2
d = 2
d *= 2

# e = 2 / 2
e = 1
e /= 2

In GDScript you can define RkVars like this:

Rakugo.set_variable("player.life", 10)
You can access it in any RakuScript:
Rakugo.get_variable("player.life")
You can change it:
var life = Rakugo.get_variable("player.life")
life += 5
Rakugo.set_variable("player.life", life)
You can display text with RkVar using Label like this:
expand Label

func update_text():
    var life =  Rakugo.get_variable("player.life")
    text = "You have %d life points left" % life

    # or one-line version:
    text = Rakugo.replace_variables("You have <player.life> life points left")
To auto-update text in label using sg_variable_changed signal:

expand Label

func _ready():
    Rakugo.sg_variable_changed.connect(update_text)

func update_text(var_name:String, value):
    if var_name == "player.life":
        text = text = "You have %d life points left" % value

        # or one-line version:
        text = Rakugo.replace_variables("You have <player.life> life points left")