conditional substitution for "what"

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
smollvrn
Newbie
Posts: 14
Joined: Sun Mar 14, 2021 3:24 pm
Contact:

conditional substitution for "what"

#1 Post by smollvrn » Mon May 31, 2021 11:05 am

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")

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: conditional substitution for "what"

#2 Post by philat » Mon May 31, 2021 9:34 pm

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)

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: conditional substitution for "what"

#3 Post by zmook » Fri Jun 04, 2021 3:04 pm

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.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: Google [Bot]