Help with dress-up system

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.
Post Reply
Message
Author
User avatar
sapiboonggames
Veteran
Posts: 299
Joined: Thu Jan 05, 2012 8:53 am
Completed: I Love You, Brother [BxB]
Contact:

Help with dress-up system

#1 Post by sapiboonggames »

Hello guys, I have been attempting making my own dress-up system, but I'm stuck with one problem which has been making me pull my hair for a while :cry:

Here is how I define the class.
The view is True if the item is available in stores, while if the bought one is True, then the item is bought and no longer available in stores. However, the item can be worn inside the wardrobe.

Code: Select all

    class Top(store.object):
        def __init__(self, name, style, image="", imagehover="", bigimage="", view=True, bought=False, cost=0):
            self.name = name
            self.style = style
            self.image=image # image file to use for this item
            self.imagehover=imagehover
            self.bigimage=bigimage
            self.view=view
            self.bought=bought
            self.cost=cost # how much does it cost in shops?
The dress up system is comprised of 4 parts: the top, bottom, head, and accessory.
This below is the top screen part.

Code: Select all

screen topinventoryscreen:
    tag menu
    use dressupcommand
#    default selected_top = 0
    $ x = 627 # coordinates of the top left item position
    $ y = -26
    $ i = 0
    $ next_top_inv_page = top_inv_page + 1
    $ before_top_inv_page = top_inv_page - 1 
    $ maximum_top_inv_page = int(len(wardrobetop.tops)/12)
    if next_top_inv_page > maximum_top_inv_page:
        $ top_inv_page = maximum_top_inv_page
    if before_top_inv_page < 0:
        $ top_inv_page = 0
    $ sorted_tops = sorted([top for top in wardrobetop.tops if top.bought]) 
    for top in sorted_tops:
        if i+1 <= (top_inv_page+1)*12 and i+1>top_inv_page*12:
            $ x += 128
            if i%4==0: ## PENGGANTIAN BARIS 
                $ y += 145 
                $ x = 627
            $ pic = top.image
            $ pichover = top.imagehover
            imagebutton idle pic hover pichover xpos x ypos y action [SetVariable("top", top), top_addstyle, SetVariable("selected_top",1), SetVariable("showtopbigimage", top.bigimage), Show("displayclothes")]
        $ i += 1
        if len(wardrobetop.tops)>12: ## berarti lebih dari 1 page pasti! 
            imagebutton:
                xpos 994
                ypos 599
                idle "pref/afteridle.png"
                hover "pref/afterhover.png"
                action [SetVariable('top_inv_page', next_top_inv_page), Show("topinventoryscreen")]
        if len(wardrobetop.tops)>24: ## berarti lebih dari 2 page pasti! => tambahan "before page"
            imagebutton:
                xpos 694
                ypos 599
                idle "pref/beforeidle.png"
                hover "pref/beforehover.png"
                action [SetVariable('top_inv_page', before_top_inv_page), Show("topinventoryscreen")]
So, in this part of the code:

Code: Select all

$ sorted_tops = sorted([top for top in wardrobetop.tops if top.bought]) 
    for top in sorted_tops:
        if i+1 <= (top_inv_page+1)*12 and i+1>top_inv_page*12:
            $ x += 128
            if i%4==0: ## PENGGANTIAN BARIS 
                $ y += 145 
                $ x = 627
            $ pic = top.image
            $ pichover = top.imagehover
            imagebutton idle pic hover pichover xpos x ypos y action [SetVariable("top", top), top_addstyle, SetVariable("selected_top",1), SetVariable("showtopbigimage", top.bigimage), Show("displayclothes")]
        $ i += 1 
I want to make it so that only bought tops can be viewed inside the screen.

However, the problem persists in the next lines:

Code: Select all

        if len(wardrobetop.tops)>12: ## berarti lebih dari 1 page pasti! 
            imagebutton:
                xpos 994
                ypos 599
                idle "pref/afteridle.png"
                hover "pref/afterhover.png"
                action [SetVariable('top_inv_page', next_top_inv_page), Show("topinventoryscreen")]
        if len(wardrobetop.tops)>24: ## berarti lebih dari 2 page pasti! => tambahan "before page"
            imagebutton:
                xpos 694
                ypos 599
                idle "pref/beforeidle.png"
                hover "pref/beforehover.png"
                action [SetVariable('top_inv_page', before_top_inv_page), Show("topinventoryscreen")]
This makes it that when I buy items in the later pages (for example, in page 4 of the shop screen), that item appears in random page (I don't know which page it is), and there are multiple pages of the wardrobe screen, even though I only bought one item.

Is there something I can do to fix this problem?
Or is this code so messy that it's beyond help? :cry:

Thank you!
I appreciate any kind of help!
Also, I'm sorry if I can't explain it well ><
Visit my website: http://www.sapiboong.com

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Help with dress-up system

#2 Post by philat »

Is there a reason you're using len(wardrobetop.tops) rather than len(sorted_tops)?

User avatar
sapiboonggames
Veteran
Posts: 299
Joined: Thu Jan 05, 2012 8:53 am
Completed: I Love You, Brother [BxB]
Contact:

Re: Help with dress-up system

#3 Post by sapiboonggames »

philat wrote:Is there a reason you're using len(wardrobetop.tops) rather than len(sorted_tops)?
Ahh! Yeah, I was being so stupid.
Changed all the len(wardrobetop.tops) to len(sorted_tops) and it's working fine.

Thank you!
Visit my website: http://www.sapiboong.com

Post Reply

Who is online

Users browsing this forum: Google [Bot]