Code: Select all
jump (current_week + "_evt")
Code: Select all
jump (current_week + "_evt")
There is a number of ways, I usually use:daikiraikimi wrote:I was wondering if I could jump to a label, where the name of the label draws on a variable? Something like this:
Where current_week is a variable. So, if current_week = "Art" then it will jump to label Art_evtCode: Select all
jump (current_week + "_evt")
Code: Select all
Jump("".join([thevariable])
Code: Select all
label start:
$ foo = 'bar'
jump foo
return
label foo:
"foo" "this is where we end up when foo is used literally ..."
jump expression foo
return
label bar:
"bar" "... but using expression with foo, means it's evaluated to its
value (bar) and now we're here!"
return
Oh ! That's actually brilliant, it's more elegant than the "".join() in my opinion ! I don't seem to find a way to make it work in screens though.strayerror wrote: ↑Sun Feb 10, 2019 1:53 pm First, all of the options presented by xela will work for you. I'm just going to expand a little on the expression keyword, which is the way to do what you're asking without leaving renpy and jumping into python. The expression keyword causes the remainder of the line to be evaluated and the result used, rather than taking it literally. Here's an example:
Hope that helps!Code: Select all
label start: $ foo = 'bar' jump foo return label foo: "foo" "this is where we end up when foo is used literally ..." jump expression foo return label bar: "bar" "... but using expression with foo, means it's evaluated to its value (bar) and now we're here!" return
Code: Select all
label mjbusy:
$ random = renpy.random.randint(0, 13)
$ renpy.jump("".join(["mjbusy", random]))
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/characters/mj.rpy", line 56, in script
$ renpy.jump("mjbusy" + random)
File "game/characters/mj.rpy", line 56, in <module>
$ renpy.jump("mjbusy" + random)
TypeError: sequence item 1: expected string or Unicode, int found
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/characters/mj.rpy", line 56, in script
$ renpy.jump("mjbusy" + random)
File "C:\Users\Scott\Downloads\Cats\Omnaverse\renpy-7.0.0-sdk\renpy\ast.py", line 912, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\Scott\Downloads\Cats\Omnaverse\renpy-7.0.0-sdk\renpy\python.py", line 2004, in py_exec_bytecode
exec bytecode in globals, locals
File "game/characters/mj.rpy", line 56, in <module>
$ renpy.jump("mjbusy" + random)
TypeError: sequence item 1: expected string or Unicode, int found
Windows-8-6.2.9200
Ren'Py 7.3.2.320
Wed Jul 31 21:57:04 2019
Code: Select all
$ random = str(renpy.random.randint(0, 13))
Code: Select all
$ rand = str(renpy.random.randint(0, 13)).zfill(2)
Code: Select all
jump expression "bla" + rand
Code: Select all
$rnd_val=renpy.random.randint(0,13)
...
jump expression 'event_{:0>2}'.format(rnd_val)
Users browsing this forum: No registered users