Nested if (or not...)
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.
-
- Newbie
- Posts: 14
- Joined: Wed Nov 29, 2017 10:49 am
- Contact:
Nested if (or not...)
Hello,
Trying to avoid nested if statements when presenting random images on entering a new area.
What i have is a number of images related to a specific area:
corridor1
corridor2
corridor3
and so on...
Right now i use nested if statements and a random variable to control what image (and message) that will show up.
But it is so tedious to create the nested ifs...
SO, i wonder how i can use the random variable to populate the number? I haev been trying to find a way to concatenate the two, but with no luck...
Also, is it possible to utilise the same random variable to read of an external text file and a specific row? I would like to tailor the text to the specific image, as you can in the nested ifs
In my mind it is "simple"(i.e i know exactly what i want...) but my coding skills are very limited, unfortunately.
Hope someone can help!
Trying to avoid nested if statements when presenting random images on entering a new area.
What i have is a number of images related to a specific area:
corridor1
corridor2
corridor3
and so on...
Right now i use nested if statements and a random variable to control what image (and message) that will show up.
But it is so tedious to create the nested ifs...
SO, i wonder how i can use the random variable to populate the number? I haev been trying to find a way to concatenate the two, but with no luck...
Also, is it possible to utilise the same random variable to read of an external text file and a specific row? I would like to tailor the text to the specific image, as you can in the nested ifs
In my mind it is "simple"(i.e i know exactly what i want...) but my coding skills are very limited, unfortunately.
Hope someone can help!
- IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
- Contact:
Re: Nested if (or not...)
Perhaps, it will help
https://www.renpy.org/doc/html/displaya ... tionSwitch
https://www.renpy.org/doc/html/displaya ... tionSwitch
Code: Select all
default myset = renpy.random.randint(1,3)
image corridor = ConditionSwitch(
"myset==1", "corridor1.png",
"myset==2", "corridor2.png",
"myset==3", "corridor3.png",
)
label start:
scene corridor
"1"
$ myset = renpy.random.randint(1,3)
"2...etc"
return
- IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
- Contact:
Re: Nested if (or not...)
little UPD.
Code: Select all
default myset = renpy.random.randint(1,3)
image corridor = ConditionSwitch(
"myset==1", "corridor1.png",
"myset==2", "corridor2.png",
"myset==3", "corridor3.png",
"myset==4", "road1.png",
"myset==5", "road2.png",
"myset==6", "road3.png",
##etc
)
label start:
scene corridor
"in random corridor 1"
$ myset = renpy.random.randint(1,3)
"in second random corridor"
$ myset = renpy.random.randint(4,6)
"on random road"
"etc"
return
-
- Newbie
- Posts: 14
- Joined: Wed Nov 29, 2017 10:49 am
- Contact:
Re: Nested if (or not...)
Thanks but it would be so much easier to just be able to convert the variable to a string and concatenate to a show statement.
$ hit = renpy.random.randint(1,20)
show corridor + str[hit]
I have found some (old) references that "str" could/should convert the random integer (i presume) to a string, not got it to work though...
$ hit = renpy.random.randint(1,20)
show corridor + str[hit]
I have found some (old) references that "str" could/should convert the random integer (i presume) to a string, not got it to work though...
-
- Newbie
- Posts: 14
- Joined: Wed Nov 29, 2017 10:49 am
- Contact:
Re: Nested if (or not...)
Some progress...
hit is: $ hit = renpy.random.randint(1,20)
I can get it to work in text:
"{image=corridor[hit]}"
This will show a random image taken from a set of images where the name conform to the "naming convention" based on the random variable [hit]. But it is in a textbox, so that is not really what i try to achieve...
So, what syntax do i need to use to get it to work in a show statement???
show corridor[hit] (does not work)
show corridor+[hit] (does not work)
show corridor&[hit] (does not work)
And many other permutations is equally unsuccessful....
Grateful for any help! It can't be that hard, or has no one tried something like this before?
hit is: $ hit = renpy.random.randint(1,20)
I can get it to work in text:
"{image=corridor[hit]}"
This will show a random image taken from a set of images where the name conform to the "naming convention" based on the random variable [hit]. But it is in a textbox, so that is not really what i try to achieve...
So, what syntax do i need to use to get it to work in a show statement???
show corridor[hit] (does not work)
show corridor+[hit] (does not work)
show corridor&[hit] (does not work)
And many other permutations is equally unsuccessful....
Grateful for any help! It can't be that hard, or has no one tried something like this before?
- Ocelot
- Lemma-Class Veteran
- Posts: 2384
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Nested if (or not...)
You can define image as a result of interpolation:
Code: Select all
define random_corridor = DynamicImage("corridor[hit]")
# . . .
$ hit = renpy.random.randint(1,20)
show random_corridor
< < insert Rick Cook quote here > >
-
- Newbie
- Posts: 14
- Joined: Wed Nov 29, 2017 10:49 am
- Contact:
Re: Nested if (or not...)
Thanks for the support!
But nope, can't get it to work.
I get the "default image" ( the grey outline) so i am not sure what is wrong.
It does state that it is showing "random_corridor", so far so good, but it does not seems to understand the syntax, properly.
But nope, can't get it to work.
I get the "default image" ( the grey outline) so i am not sure what is wrong.
It does state that it is showing "random_corridor", so far so good, but it does not seems to understand the syntax, properly.
- 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: Nested if (or not...)
DynamicImage( "corridor[hit].png" ) ## add .png
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
-
- Newbie
- Posts: 14
- Joined: Wed Nov 29, 2017 10:49 am
- Contact:
Re: Nested if (or not...)
Nope, same result, see my code below.
Code: Select all
"Test"
$ hit = renpy.random.randint(1,1)
"hit is [hit]" ## verifying variable
define random_corridor = DynamicImage( "corridor[hit].png" ) ## add .png
# . . .
# $ hit = renpy.random.randint(1,1)## removed since it initiates the variable too late
show random_corridor ## grey outline "standard image"
"----"
show corridor1 ## verifying image
"...."
"{image=corridor[hit]}" ## show image in text, works.
"End test"
- 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: Nested if (or not...)
the define should be outside of any label, not define or default either, use image
Code: Select all
default hit = 1
image random_corridor = DynamicImage( "corridor[hit].png" )
label a:
scene random_corridor
"start"
$ hit = 2
"end"
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
-
- Newbie
- Posts: 14
- Joined: Wed Nov 29, 2017 10:49 am
- Contact:
Re: Nested if (or not...)
Got it! One thing that confused me, i had to direct to folder... Also, i changed from scene to show
So, the final code looks like (annoyingly easy!)
OK, thanks a lot for the support!!
So, the final code looks like (annoyingly easy!)
Code: Select all
$ hit = renpy.random.randint(1,28) ## initiates a random variable
image street1 = DynamicImage( "street/street1/1street [hit].jpg" ) ## "binds" the image to a dynamic image that uses the "hit variable", in this case all images are named 1street and a number.
show street1 ## Shows random image
OK, thanks a lot for the support!!
Who is online
Users browsing this forum: No registered users