Hello,
Currently I do the following to display inventory items:
1. In INIT section, I have $inv=[]
2. To display inventory near bottom of screen, I entered:
screen statsinv:
hbox:
text("{color=#5f9ea0}Inv: %s{/color}" % inv)
3. When an item is added, I have $inv.append("watch") for example.
The Inventory starts out actually displaying the brackets, and puts a single-quote around each item.
So the game displays the following:
Inv: ['watch', 'ring']
I just want it to display
Inv: watch, ring
Is there a way to do that?
Thanks
inventory items
Forum rules
Ren'Py specific questions should be posted in the Ren'Py Questions and Annoucements forum, not here.
Ren'Py specific questions should be posted in the Ren'Py Questions and Annoucements forum, not here.
Re: inventory items
Since 'inv' is a list, when you interpolate it into a string, it uses Python's default string representation of a list, which includes the square brackets and the quotes.bozance wrote: I just want it to display
Inv: watch, ring
Is there a way to do that?
One thing you can do is use the 'join' method of a string, which takes a sequence (like a list) as a parameter and joins all the items in the list together using that string between each one. So, for example:
Code: Select all
>>> inv = ['watch', 'ring']
>>> print "Inv: " + str(inv)
Inv: ['watch', 'ring']
>>> print "Inv: " + ", ".join(inv)
Inv: watch, ring
Code: Select all
", ".join(inv)
Code: Select all
", "
Server error: user 'Jake' not found
Re: inventory items
Thanks--though I'm not sure exactly where to put that in my script.
If I have the following in the INIT section, where exactly would I put the join stuff? Can you enter it in where it would belong in the example below?
Sorry if my question is too basic. I'm an English major and anything beyond jump and basic if statements and I'm screwed.
Init:
screen statsinv:
hbox:
yalign 0.95
xpos 0.01
xfill True
text("{color=#5f9ea0}Inv: %s{/color}" % inv)
If I have the following in the INIT section, where exactly would I put the join stuff? Can you enter it in where it would belong in the example below?
Sorry if my question is too basic. I'm an English major and anything beyond jump and basic if statements and I'm screwed.
Init:
screen statsinv:
hbox:
yalign 0.95
xpos 0.01
xfill True
text("{color=#5f9ea0}Inv: %s{/color}" % inv)
Re: inventory items
Ah--I just had to enter
text("Inv: "+", ".join(inv))
at the bottom of the hbox definition.
Thanks again for the help... I wish there were an in-person training course for Renpy!
text("Inv: "+", ".join(inv))
at the bottom of the hbox definition.
Thanks again for the help... I wish there were an in-person training course for Renpy!
Who is online
Users browsing this forum: No registered users