Multiple Choice and Restrictions
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: 6
- Joined: Mon Oct 04, 2021 10:58 am
- Contact:
Multiple Choice and Restrictions
Select one from each of the a, b, c, d groups and the ABCD group to proceed.
What I actually want to do is to pick a training and then pick someone to go with me to that training together.
Depending on who you go with, you want to fluctuate your status increase and then have an event happen afterwards.
viewtopic.php?t=21466
Referring to this topic, I found out that multiple selections can be represented by images and text, but I don't know how to set up the process to select and execute only one of the different groups at a time.
What you can do by selecting multiple items and pressing OK ......
If you would please advise me.
English is not my primary language, so I apologize for any oddities.
Last edited by kamisama_nuno on Tue Oct 05, 2021 10:51 am, edited 1 time in total.
- hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Contact:
Re: Multiple Choice and Restrictions
A simple example...
Code: Select all
default trainings = ["strength", "agility", "intelligence"]
default trainers = ["person1", "person2", "person3"]
screen training_picker():
default picked_training = None
default picked_trainer = None
vbox:
hbox:
for training in trainings:
textbutton training action SetScreenVariable("picked_training", training) selected (picked_training == training)
hbox:
for trainer in trainers:
textbutton trainer action SetScreenVariable("picked_trainer", trainer) selected (picked_trainer == trainer)
textbutton "Ok" action Return((picked_training, picked_trainer)) sensitive (picked_training in trainings and picked_trainer in trainers)
label start:
call screen training_picker()
$ training, trainer = _return
if training == "strength":
pass # do something...
-
- Newbie
- Posts: 6
- Joined: Mon Oct 04, 2021 10:58 am
- Contact:
Re: Multiple Choice and Restrictions
Thank you so much!
I ran it to try it out and it worked fine!
I'm embarrassed to say that this was the first time I learned how to use the sensitive action, so it was very helpful. Thank you very much.
I'm sorry for my lack of knowledge, but I'd like to ask you another question.
I'd like to do this with image buttons instead of text buttons, but how do I set up individual image buttons if I'm outputting for in from a list?
Probably the following code won't set it up, and in fact I couldn't even run it.
Do you define it directly in a list or flag?
I ran it to try it out and it worked fine!
I'm embarrassed to say that this was the first time I learned how to use the sensitive action, so it was very helpful. Thank you very much.
I'm sorry for my lack of knowledge, but I'd like to ask you another question.
I'd like to do this with image buttons instead of text buttons, but how do I set up individual image buttons if I'm outputting for in from a list?
Probably the following code won't set it up, and in fact I couldn't even run it.
Do you define it directly in a list or flag?
Code: Select all
default trainings = ["strength", "agility", "intelligence"]
default trainers = ["person1", "person2", "person3"]
screen training_picker():
default picked_training = None
default picked_trainer = None
vbox:
hbox:
for training in trainings:
imagebutton auto "a_%s.png" training action SetScreenVariable("picked_training", training) selected (picked_training == training)
imagebutton auto "b_%s.png" training action SetScreenVariable("picked_training", training) selected (picked_training == training)
imagebutton auto "c_%s.png" training action SetScreenVariable("picked_training", training) selected (picked_training == training)
hbox:
for trainer in trainers:
textbutton trainer action SetScreenVariable("picked_trainer", trainer) selected (picked_trainer == trainer)
textbutton "Ok" action Return((picked_training, picked_trainer)) sensitive (picked_training in trainings and picked_trainer in trainers)
label start:
call screen training_picker()
$ training, trainer = _return
if training == "strength":
pass # do something...
- hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Contact:
Re: Multiple Choice and Restrictions
You almost got it right but just like in my example you only need one imagebutton.
Referring to my original sample, if you have images in your game such as "strength_idle.png", "agility_idle.png" etc, then it will work out fine.
The default variables for trainings and trainers, you can alter those, put either a string or object as an element, etc., depending on the setup of your game.
Code: Select all
for training in trainings:
imagebutton auto "[training]_%s.png" action SetScreenVariable("picked_training", training) selected (picked_training == training)
The default variables for trainings and trainers, you can alter those, put either a string or object as an element, etc., depending on the setup of your game.
Last edited by hell_oh_world on Tue Oct 05, 2021 5:10 am, edited 1 time in total.
-
- Newbie
- Posts: 6
- Joined: Mon Oct 04, 2021 10:58 am
- Contact:
Re: Multiple Choice and Restrictions
So that's how you can refer to the list.
It's very informative. Thank you very much.
I'm sorry, I'm trying to try it as soon as possible, but I'm getting an error, so I thought I'd try running it once, and I copied the whole code.
strength_idle.png
strength_hover.png
intelligence_idle.png
intelligence_hover.png
agility_idle.png
agility_hover.png
I have these in imagine file.
I've been trying for a while now and I can't figure out why it's not enabled... sorry...
It's very informative. Thank you very much.
I'm sorry, I'm trying to try it as soon as possible, but I'm getting an error, so I thought I'd try running it once, and I copied the whole code.
Code: Select all
default trainings = ["strength", "agility", "intelligence"]
default trainers = ["person1", "person2", "person3"]
screen training_picker():
default picked_training = None
default picked_trainer = None
vbox:
hbox:
for training in trainings:
imagebutton auto "[training]_%s.png" training action SetScreenVariable("picked_training", training) selected (picked_training == training)
hbox:
for trainer in trainers:
textbutton trainer action SetScreenVariable("picked_trainer", trainer) selected (picked_trainer == trainer)
textbutton "Ok" action Return((picked_training, picked_trainer)) sensitive (picked_training in trainings and picked_trainer in trainers)
label start:
call screen training_picker()
$ training, trainer = _return
if training == "strength":
pass # do something...
Code: Select all
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.
File "game/df.rpy", line 11: u'training' is not a keyword argument or valid child for the imagebutton statement.
imagebutton auto "[trainings]_%s.png" training action SetScreenVariable("picked_training", training) selected (picked_training == training)
^
Ren'Py Version: Ren'Py 7.4.5.1648
Tue Oct 5 17:02:25 2021
strength_hover.png
intelligence_idle.png
intelligence_hover.png
agility_idle.png
agility_hover.png
I have these in imagine file.
I've been trying for a while now and I can't figure out why it's not enabled... sorry...
- hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Contact:
Re: Multiple Choice and Restrictions
My bad. It says you included an unknown keyword and that keyword is "training" (before the action keyword), remove that. (I didn't know I put that somewhere in my code)
Also, it should be [training] not [trainings] just like in my example.
*Updated the code for full correction.*
Also, it should be [training] not [trainings] just like in my example.
*Updated the code for full correction.*
-
- Newbie
- Posts: 6
- Joined: Mon Oct 04, 2021 10:58 am
- Contact:
Re: Multiple Choice and Restrictions
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/df.rpy", line 21, in script
call screen training_picker()
File "renpy/common/000statements.rpy", line 569, in execute_call_screen
store._return = renpy.call_screen(name, *args, **kwargs)
File "game/df.rpy", line 4, in execute
screen training_picker():
File "game/df.rpy", line 4, in execute
screen training_picker():
File "game/df.rpy", line 8, in execute
vbox:
File "game/df.rpy", line 9, in execute
hbox:
File "game/df.rpy", line 10, in execute
for training in trainings:
File "game/df.rpy", line 11, in execute
imagebutton auto "[training]_%s.png" action SetScreenVariable("picked_training", training) selected (picked_training == training)
Exception: Imagebutton does not have a idle image. (auto=u'[training]_%s.png').
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/df.rpy", line 21, in script
call screen training_picker()
File "renpy/ast.py", line 1969, in execute
self.call("execute")
File "renpy/ast.py", line 1957, in call
return renpy.statements.call(method, parsed, *args, **kwargs)
File "renpy/statements.py", line 278, in call
return method(parsed, *args, **kwargs)
File "renpy/common/000statements.rpy", line 569, in execute_call_screen
store._return = renpy.call_screen(name, *args, **kwargs)
File "renpy/exports.py", line 3057, in call_screen
rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
File "renpy/ui.py", line 298, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "renpy/display/core.py", line 3213, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
File "renpy/display/core.py", line 3630, in interact_core
root_widget.visit_all(lambda i : i.per_interact())
File "renpy/display/core.py", line 567, in visit_all
d.visit_all(callback, seen)
File "renpy/display/core.py", line 567, in visit_all
d.visit_all(callback, seen)
File "renpy/display/core.py", line 567, in visit_all
d.visit_all(callback, seen)
File "renpy/display/screen.py", line 432, in visit_all
callback(self)
File "renpy/display/core.py", line 3630, in <lambda>
root_widget.visit_all(lambda i : i.per_interact())
File "renpy/display/screen.py", line 443, in per_interact
self.update()
File "renpy/display/screen.py", line 631, in update
self.screen.function(**self.scope)
File "game/df.rpy", line 4, in execute
screen training_picker():
File "game/df.rpy", line 4, in execute
screen training_picker():
File "game/df.rpy", line 8, in execute
vbox:
File "game/df.rpy", line 9, in execute
hbox:
File "game/df.rpy", line 10, in execute
for training in trainings:
File "game/df.rpy", line 11, in execute
imagebutton auto "[training]_%s.png" action SetScreenVariable("picked_training", training) selected (picked_training == training)
File "renpy/ui.py", line 952, in _imagebutton
idle = choice(idle, idle_image, "idle", required=True)
File "renpy/ui.py", line 946, in choice
raise Exception("Imagebutton does not have a %s image. (auto=%r)." % (name, auto))
Exception: Imagebutton does not have a idle image. (auto=u'[training]_%s.png').
Windows-10-10.0.19041
Ren'Py 7.4.5.1648
zannaku 1.0
Tue Oct 5 19:12:22 2021
I've replaced the code in the previous section, but it says the file is missing.
strength_idle.png
strength_hover.png
intelligence_idle.png
intelligence_hover.png
agility_idle.png
agility_hover.png
I thought it might be because I didn't have any sensitive images, so I tried to prepare each one, but there was no improvement...
- hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Contact:
Re: Multiple Choice and Restrictions
I might be wrong, but I think Ren'Py's interpolation doesn't work with imagebuttons.
Hopefully, this will solve that.
Hopefully, this will solve that.
Code: Select all
imagebutton auto "{}_%s.png".format(training) action SetScreenVariable("picked_training", training) selected (picked_training == training)
-
- Newbie
- Posts: 6
- Joined: Mon Oct 04, 2021 10:58 am
- Contact:
Re: Multiple Choice and Restrictions
It worked, it worked, it worked fine!!
Thank you so much for coming up with the code all those times!That was very helpful!
Thank you so much for coming up with the code all those times!That was very helpful!
Who is online
Users browsing this forum: No registered users