Ren'Py SortGame

pobrecito007

Newbie
Dec 18, 2019
21
1
Hi,
I am stuck scripting a mini game for sorting garbage. I have 3 containers; 1 for resudial waste, 1 for glass and 1 for metal.

So i placed various obejects around the containers which should be place in the right one. Example: GlassBottle should be place in the GlassContainer.

The player has to sort the garbage every day.

I tried to rewrite this script but it completly failed



Any advice how i can do this?

thanks a lot in advanced
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,976
16,232
Any advice how i can do this?
Firstly by not trying to use scripts that are six years old. At first view this one seem to be more or less alright, but Ren'Py still had 45 updates released since it was wrote. Those scripts can be a source for the algorithm to use, but they should only be used for this.

Secondly, look at the page of the documentation, that come with a presenting how to use it.
Basically speaking, you've to give a name to your waste, and use the dropped of the trash object to test if it's the right one or not.
 

pobrecito007

Newbie
Dec 18, 2019
21
1
I am getting really confused now. So how do i define containers and waste products?
Code:
init python:

    def product_dragged(drags, drop):

        if not drop:
            return

        store.product = drags[0].drag_name
        store.container = drop.drag_name

        return True

screen send_product_screen:

    # A map as background.
    add "camp_garbage_day.png"

    # A drag group ensures that the products and the cities can be
    # dragged to each other.
    draggroup:

        # Our products.
        drag:
            drag_name "beerbottle"
            child "beerbottle.png"
            droppable False
            dragged product_dragged
            xpos 100 ypos 100
        drag:
            drag_name "bigbag"
            child "bigbag.png"
            droppable False
            dragged product_dragged
            #xpos 150 ypos 100

        # The cities they can go to.
        drag:
            drag_name "fieldGlass"
            draggable False
            child "fieldGlass.png"
            xpos 450 ypos 140
        drag:
            drag_name "fieldMetal"
            draggable False
            child "fieldMetal.png"
            xpos 100 ypos 280

label send_product:
    "We need to investigate! Who should we send, and where should they go?"

    call screen send_product_screen

    "Okay, we'll send [product] to [container]."

#More complicated systems take significant programming skill to get right. The Ren'Py cardgame framework is both an example of how to use drag and drop in a complex system, and useful for making card games in its own right.

#The as clause can be used to bind a drag to variable, which can then be used to call methods on the drag.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
I am getting really confused now. So how do i define containers and waste products?

The waste products are the drag:drag_name: objects that include the dragged product_dragged parameters. The containers would be the ones without.

In effect, when those objects are dragged, they invoke the function product_dragged(drags, drop):. If it decides it has interacted with another hotspots within the same draggroup:, it reacts by storing the values in the two variables product and container and then exits from the screen (the return True line, part of the function).
 

pobrecito007

Newbie
Dec 18, 2019
21
1
Thank you so much for the explanation. I can see things clear now.
i am missing now that the beerbottle only should go into the glass container and lets say the bigbag only into the metal container and when i placed the product into the container it should be gone
 

pobrecito007

Newbie
Dec 18, 2019
21
1
i am still facing some problems. why do i have to put everything on true( marked like this #<- ) to make it work?

How do i make the product gone, after placing it in the container?
How do i add images which shows the dropping?


Code:
init python:
    fieldMetal = "false"
    fieldGlass = "false"

    def product_dragged(drags, drop):

        if not drop:
            return

        store.product = drags[0].drag_name
        store.container = drop.drag_name

        if product == "beerbottle" and container == "fieldGlass":
            fieldGlass = "true" #<- 
        else:
            fieldGlass = "true" #<- 

        if product == "bigbag" and container == "fieldMetal":
            fieldMetal = "true" #<- 
        else:
            fieldMetal = "false" #<- 

        if fieldGlass == "true" and fieldMetal == "true":
            return True

        else:
            pass

#    def container_metal(drop):
#        store.container = drop.field

screen send_product_screen:

    # A map as background.
    add "camp_garbage_day.png"

    # A drag group ensures that the products and the cities can be
    # dragged to each other.
    draggroup:

        # Our products.
        drag:
            drag_name "beerbottle"
            child "beerbottle.png"
            droppable False
            dragged product_dragged
            xpos 0 ypos 0
            #action Call("putaway_candles_return")
        drag:
            drag_name "bigbag"
            child "bigbag.png"
            droppable False
            dragged product_dragged
            xpos 1050 ypos 800

        # The cities they can go to.
        drag:
            drag_name "fieldGlass"
            draggable False
            child "fieldGlass.png"
            xpos 400 ypos 440
        drag:
            drag_name "fieldMetal"
            draggable False
            child "fieldMetal.png"
            xpos 1415 ypos 438

label send_product:
    "We need to investigate! Who should we send, and where should they go?"

    call screen send_product_screen

    "Okay, we'll send [product] to [container]."
    call putaway_candles_return
    jump send_product

#More complicated systems take significant programming skill to get right. The Ren'Py cardgame framework is both an example of how to use drag and drop in a complex system, and useful for making card games in its own right.

#The as clause can be used to bind a drag to variable, which can then be used to call methods on the drag.


label putaway_candles_return:
    if waste_bigbag == 2:
        $ waste_bigbag = 0


    #$ spa_job_money += 1

    $ putaway_active = 0
 
Last edited: