creating a next page function
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.
- morg
- Regular
- Posts: 95
- Joined: Sun May 10, 2015 7:35 am
- Projects: Cupid's Affair
- Tumblr: n-morg
- Contact:
creating a next page function
Hi! so I have coded this sort of clothes shop and everything is nice except one thing: the Ui is ugly. I Have a pic of a 3x3 grid and want to display 9 clothing items per page, but I don't know how to do that next page function. I've read leon's CG galleries and inventories with those systems but I didn't get a single thing, and in turn couldn't implement it. Could someone perhaps explain it to me? thanks in advance
- theCodeCat
- Regular
- Posts: 62
- Joined: Sun Sep 06, 2015 8:40 pm
- Projects: Lucid9, Mystic Destinies: Serendipity of Aeons
- Skype: theCodeCat
- Contact:
Re: creating a next page function
I would suggest something like this:
The screen itself just displays a particular page of the shop with the items you want, but also contains buttons that re-displays the screen with a larger or smaller page number.
To start it off you would write something like:
call screen shop([<items to display>])
(Since the "page" parameter has the default value of 0 you don't need to specify it when initially showing the screen)
Code: Select all
screen shop(itemList,page=0):
python:
# Ideally the total number of pages should be calculated based off of
# the number if items in the itemList, but to keep this simple I've hardcoded
# the page count
totalPages = 4
# Grabs which items should be displayed on this page
# NOTE: This list may hold less than 9 items
itemsOnPage = itemList[9*page:9]
# < Add screen code for displaying 'itemsOnPage' items in a 3x3 grid here >
# The next-page button would look something like:
if page < totalPages:
textbutton "Next" action Show("shop",itemList,page=(page+1))
# And the last-page button something like:
if page > 0:
textbutton "Back" action Show("shop",itemList,page=(page-1))
To start it off you would write something like:
call screen shop([<items to display>])
(Since the "page" parameter has the default value of 0 you don't need to specify it when initially showing the screen)
- morg
- Regular
- Posts: 95
- Joined: Sun May 10, 2015 7:35 am
- Projects: Cupid's Affair
- Tumblr: n-morg
- Contact:
Re: creating a next page function
I seem to be doing something wrong, I typed this (I hope I understood you properly)
and it gave me this;
I'm using a basic set to store my items in
so i guess there is a silly mistake there somewhere, lol. what should i do?
Code: Select all
screen shop(itemList,page=0):
python:
# Ideally the total number of pages should be calculated based off of
# the number if items in the itemList, but to keep this simple I've hardcoded
# the page count
totalPages = 4
# Grabs which items should be displayed on this page
# NOTE: This list may hold less than 9 items
itemsOnPage = itemList[9*page:9]
grid 3 3:
for item in chest:
imagebutton auto item.icon action SetVariable("top", item.pic) #< Add screen code for displaying 'itemsOnPage' items in a 3x3 grid here >
# The next-page button would look something like:
if page < totalPages:
textbutton "Next" action Show("shop",itemList,page=(page+1))
# And the last-page button something like:
if page > 0:
textbutton "Back" action Show("shop",itemList,page=(page-1))
and it gave me this;
Code: Select all
While running game code:
File "game/script.rpy", line 178, in script
call screen shop([chest.items])
File "renpy/common/000statements.rpy", line 452, in execute_call_screen
args, kwargs = a.evaluate()
File "game/script.rpy", line 178, in <module>
call screen shop([chest.items])
AttributeError: 'RevertableSet' object has no attribute 'items'
Code: Select all
$ chest = set()
$ frillytop = Top("Frilly Crop Top", 25, "dressup/frillytop_icon_%s.png", "dressup/frillytop_pink.png")
- theCodeCat
- Regular
- Posts: 62
- Joined: Sun Sep 06, 2015 8:40 pm
- Projects: Lucid9, Mystic Destinies: Serendipity of Aeons
- Skype: theCodeCat
- Contact:
Re: creating a next page function
I actually don't have much experience working with set objects in python, but it looks like the set class doesn't have an "items" property, so chest.items is meaningless.
At any rate, the screen code I gave assumes its been given a list and I would recommend using a list structure anyways since it allows you to specify the order in which items are displayed.
If for whatever reason you want to keep 'chest' as a set, you can convert it to a list before passing it to the screen by writing "list(chest)" instead of just "chest".
Other than that, there are 2 other mistakes I see.
1.
because you are displaying the current page in a grid, not all of the items. The 'page' variable only affects 'itemsOnPage', so if you ignore 'itemsOnPage', then the current page value has 0 effect.
2. When calling the screen you should write
When I wrote '[<items to display>]' I meant to indicate that you need pass in a list of items. ([] brackets get used to define lists in python)
At any rate, the screen code I gave assumes its been given a list and I would recommend using a list structure anyways since it allows you to specify the order in which items are displayed.
If for whatever reason you want to keep 'chest' as a set, you can convert it to a list before passing it to the screen by writing "list(chest)" instead of just "chest".
Other than that, there are 2 other mistakes I see.
1.
Code: Select all
for item in chest:
# SHOULD BE
for item in itemsOnPage:
2. When calling the screen you should write
Code: Select all
#IF 'chest' is a list
call screen shop(chest)
#OR
# IF 'chest' is a set
call screen shop(list(chest))
- morg
- Regular
- Posts: 95
- Joined: Sun May 10, 2015 7:35 am
- Projects: Cupid's Affair
- Tumblr: n-morg
- Contact:
Re: creating a next page function
alright, so I edited the code a little bit;
the screen displays properly when called but when I press the next button I get this error;
not sure what this means? maybe there has been a confusion when I converted the set?
Code: Select all
screen shop(itemList,page=0):
add "park"
add "girl" xalign 0.9
python:
totalpages = 4
itemsOnPage = itemList[3*page:3]
grid 1 3 xalign 0.1 yalign 0.2:
hbox:
for item in itemsOnPage:
frame:
imagebutton auto item.icon action SetVariable("top", item.pic)
hbox:
text "empty"
hbox:
text "empty"
textbutton "Done" action Return() xalign 0.1 yalign 0.9
if page < totalpages:
textbutton "Next" action Show("shop",itemList,page=(page+1)) xalign 0.6 yalign 0.02
if page > 0:
textbutton "Back" action Show("shop",itemList,page=(page-1)) xalign 0.1 yalign 0.02
Code: Select all
While running game code:
File "game/script.rpy", line 211, in script
g "start game"
File "renpy/common/000statements.rpy", line 457, in execute_call_screen
store._return = renpy.call_screen(name, *args, **kwargs)
Exception: Required parameter itemList has no value.
-
- Miko-Class Veteran
- Posts: 758
- Joined: Tue Jun 22, 2010 12:54 am
- Completed: Christmas
- IRC Nick: DragoonHP
- Location: Zion Island, Solario
- Contact:
Re: creating a next page function
Change Show("shop",itemList,page=(page-1)) to Show("shop", itemList=itemList, page=(page-1))
- morg
- Regular
- Posts: 95
- Joined: Sun May 10, 2015 7:35 am
- Projects: Cupid's Affair
- Tumblr: n-morg
- Contact:
Re: creating a next page function
thank you very much, the button works now.
But another problem has popped up, when I turn the page it shows me no clothes, even though I have added more than 3. (I've added five items, it shows me three on the first page but fails to show me the other two on the second)
But another problem has popped up, when I turn the page it shows me no clothes, even though I have added more than 3. (I've added five items, it shows me three on the first page but fails to show me the other two on the second)
Who is online
Users browsing this forum: No registered users