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.
-
TheChatotMaestro
- Regular
- Posts: 91
- Joined: Mon Jul 31, 2017 8:33 am
- Deviantart: LedianWithACamera
-
Contact:
#1
Post
by TheChatotMaestro » Sun May 27, 2018 9:01 pm
I'm trying to change this
Code: Select all
screen items_screen:
frame:
has vbox
textbutton "one"
textbutton "two"
textbutton "three"
textbutton "Back" action Return()
to a similar screen that will add and remove list items based on which items you have in your inventory. The inventory will be determined by a list (eg "example_list = [0, 3, 2]") that will have items added and subtracted to it using list append. The textbuttons will lead you to screens where more information on the items can be viewed. However, I only want textbuttons to show up if you have the item. How would I go about this?
Would this work?
Code: Select all
screen items_screen:
frame:
has vbox
if "one" in "listname":
textbutton "one"
if "two" in "listname":
textbutton "two"
if "three" in "listname":
textbutton "three"
textbutton "Back" action Return()
Or am I totally off-base?
-
kivik
- Miko-Class Veteran
- Posts: 786
- Joined: Fri Jun 24, 2016 5:58 pm
-
Contact:
#2
Post
by kivik » Mon May 28, 2018 7:33 am
Most programming languages will have a loop structure specifically to allow you to loop through all the items in your list. They're usually called a for loop:
http://treyhunner.com/2016/04/how-to-lo ... in-python/ (scroll down to "for-in: the usual way")
So you want something like this:
Code: Select all
screen items_screen:
frame:
has vbox
for i in listname:
textbutton i action ???
textbutton "Back" action Return()
Basically in a
for i in list loop in python, it'll go through the loop as many times as there are items, and each iteration of the loop, i contains whatever value your current list item is. So you can directly reference i as the item (i.e. textbutton i in this case.) What you need to be more conscious of in this situation is what the screen action is going to be: It needs to incorporate i in some form, whether it's a Call() that uses i, or another screen action that takes i and make the action contextual to what the item is.
Let us know if you need more help with it.
-
TheChatotMaestro
- Regular
- Posts: 91
- Joined: Mon Jul 31, 2017 8:33 am
- Deviantart: LedianWithACamera
-
Contact:
#3
Post
by TheChatotMaestro » Mon May 28, 2018 4:49 pm
It says the list is not defined
update: I forget if that error was even with this or something else but now I have parenthesis around it and it is working fine. So... parenthesis are a good thing i guess
Last edited by
TheChatotMaestro on Mon May 28, 2018 5:03 pm, edited 1 time in total.
-
kivik
- Miko-Class Veteran
- Posts: 786
- Joined: Fri Jun 24, 2016 5:58 pm
-
Contact:
#4
Post
by kivik » Mon May 28, 2018 4:58 pm
Did you read the thing I linked? My code wasn't actual working code, but what it would look like. Hence the ??? in the button action.
In your example code you mentioned listname so I assumed you'd at least declared the list...
Users browsing this forum: Google [Bot]