Page 1 of 1

conditional substitution for "what"

Posted: Mon May 31, 2021 11:05 am
by smollvrn
Hi, i need check conditional statement before each say or menu choice 'what'. Would you help me to create function or maybe oneline substution for this:

Code: Select all

if persistent.c=="1":
   $ a = tuple1
if persistent.c=="2":
   $ a = tuple2
"[a[0]]"
something like that:

Code: Select all

"[tuple(c)[0]]"
or like that

Code: Select all

"%s" % (str("\[tuple"+c+"\[0\]\]"))
or substitution:
if i add in def parse in "renpy/substiturion.py"

Code: Select all

s = s.replace("tuple(c)", "tuple1")
its work, but i cannot transfer persistent variable from game code to renpy main code for select, i get 'not defined variable', maybe you help me to do this

Code: Select all

if c == '1':
 s = s.replace("tuple(c)", "tuple1")

Re: conditional substitution for "what"

Posted: Mon May 31, 2021 9:34 pm
by philat
Not really sure what you're trying to do and I'm almost certain you wouldn't want to write a game in tuple format, but fwiw, you can get the variable tuple1 or tuple2 using getattr or eval (e.g., getattr(store, "tuple"+persistent.c)

Re: conditional substitution for "what"

Posted: Fri Jun 04, 2021 3:04 pm
by zmook
This does sound like one of those cases where you really want to back up a step and tell us why you are trying to do that, so you don't have to kludge a clever solution to an unnecessary problem.