Narrat Docs
Search…
Add Function

Add Function

The add function is similar to the set function, but increments values. You can use it to add a number to an existing value, or substract by adding a negative number.

Example

The following code will setup a counter variable, then effectively put the player in a loop where they can increase the counter up to 10 times until they have a new choice to move on.
1
add_example:
2
set DATA.counter 0
3
jump add_example_add
4
5
add_example_add:
6
choice:
7
talk cat idle "Do you want to increase the counter? You can only do it 10 times":
8
"Increase the counter" $if this.DATA.counter < 10:
9
add DATA.counter 1
10
"No!":
11
talk cat idle "Ok then"
12
"I'm done" $if this.DATA.counter >= 10:
13
jump add_example_end
14
jump add_example_add
15
16
add_example_end:
17
talk cat idle "It seems you're done with the counter now"
18
Copied!
Result of the above code
Copy link