Alright, I've spent the past few months looking into Ren'Py and trying to learn how things are done- the forums, and especially this here cookbook has been incredibly helpful. SO! Here's something I've been working on for a little bit, just a small function that updates itself and loads the next chapter upon being called.
Code: Select all
init python:
def nextCh():
global num
if num == None:
num = 0
lbl = "Ch" + "%d" % num
num += 1
if renpy.has_label(lbl) == True:
renpy.call(lbl)
else:
global lbl
renpy.jump("error")
How it works is simple! First you make
num global, so that it can be reused as necessary and doesn't lock up. Then you make sure it actually has a value- since without a value it just breaks and can't be added to. You don't
need to, but I store the result in a variable as a string. The "Ch" means chapter, and the next part:
"%d" % num; just turns the variable
num into a string! That means if
num == 0,
lbl == "Ch0"! After that, it adds 1 to
num so that the next time you call the function, lbl == "Ch1", and then lbl == "Ch2", and so on. The next line just checks to make sure the label you want exists, because you don't want to be calling "Ch10" when you only have 9 Chapters, and then I use renpy.call(lbl) so I can call from a variable! Finally, if the label
lbl doesn't exist, it saves the variable globally and then jumps to an error label! The error looks like this:
Code: Select all
label error:
"It appears there was an error while trying to load the label [lbl]. Please contact CoreBear#9999 at the {a=https://discord.gg/mgF4B5sxez}discord{/a}."
$ renpy.quit()
And this is how you use it;
Code: Select all
label start:
$nextCh()
$nextCh()
$nextCh()
label Ch0:
"This is the prologue, if you have one. Otherwise, just the start of your story!"
label Ch1:
"We don't have a Ch2 label, so in this scenario it would call the error label.