Hello, hello. I was just wondering if it's possible when checking a variable with an if statement or something, to check for a specific phrase within that variable instead. Say if I had multiple options during a choice, and later had dialogue associated with maybe two of those, rather than stipulate each tiny difference within the variable, if I could just see if it contained part of it.
To make it simple, here's the choice and the options it could be...
$ Choice1 = "Pos"
$ Choice1 = "Pos Mary"
$ Choice1 = "Pos John"
$ Choice1 = "Swa"
$ Choice1 = "Swa Mary"
$ Choice1 = "Swa John"
Is it possible to just look to see if Choice1 contains either "Swa" or "Pos" rather than specify the whole thing? If not, since I'm always learning, any alternatives with similar results?
Thanks in advance.
Variable containing a word
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.
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.
Re: Variable containing a word
Code: Select all
if "Pos" in Choice1:
"True"
else:
"False"
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Variable containing a word
For more *precision*...
Code: Select all
if Choice1.startswith( "Pos" ):
"True: Startswith Pos"
elif Choice1.endswith( "Mary" ):
"True: Endswith Mary"
elif Choice1[:3] == "Pos": # first 3 letters
"True: Starts Pos"
elif Choice1[-4:].lower() == "john": # final 4 letters lowercased
"True: Ends john"
else:
"False"
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Variable containing a word
Awesome, thank you both the information! I will try those out next time I get a chance.
Thanks!
Thanks!
Re: Variable containing a word
Rather than make a new thread, I figure I should just ask it here, which is basic advice, I suppose. The above question is the result of me including a short little card game. While I would love to code an entire card game (do not have the skills), it's a mildly scripted thing, but there are variables based on what you play and when. So rather than have a ton of variables for every player, I was thinking just having one, which contained multiple strings/shortenings that sort of represented the cards the player had and so on.
While the original question is something that will help me in other places, I am now wondering if it's possible to not just have an if statement that is looking for a certain word, but can I add or remove specific parts of a variable by doing this?
So, let's use another example...
$ Testing = "c.12 c.4 c.1 h:13"
Can I search for c.1 and replace it or remove it, while leaving the rest of the content of the variable in-tact? Thanks in advance for answers on this.
While the original question is something that will help me in other places, I am now wondering if it's possible to not just have an if statement that is looking for a certain word, but can I add or remove specific parts of a variable by doing this?
So, let's use another example...
$ Testing = "c.12 c.4 c.1 h:13"
Can I search for c.1 and replace it or remove it, while leaving the rest of the content of the variable in-tact? Thanks in advance for answers on this.
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Variable containing a word
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
-
- Newbie
- Posts: 1
- Joined: Tue Oct 16, 2018 2:21 am
- Contact:
Re: Variable containing a word
More on.....Python List
Who is online
Users browsing this forum: No registered users