How to return deleted objects DragGroup?

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
Pronax
Newbie
Posts: 7
Joined: Fri Jul 27, 2018 11:37 am
Contact:

How to return deleted objects DragGroup?

#1 Post by Pronax »

Hi
I have a code in which when dragging a thing to a certain place, this thing, to hide itself from the screen, is removed across .remove(child) from DragGroup()

Code: Select all

    def fruit(drags, drop):
        global karzina_pl, karzina_srav, prav_list, p


        if not drop:

            drags[0].snap(pos_f[int(drags[0].drag_name.split("-")[0])][0], pos_f[int(drags[0].drag_name.split("-")[0])][1], delay=0.1)
            return
        
        else:
            print (karzina_pl, karzina_srav, prav_list)

            if str(drags[0].drag_name.split("-")[1]) in prav_list:
                stall.remove(drags[0])

                karzina_pl.append(drags[0].drag_name.split("-")[2]) 
                karzina_srav.append(drags[0].drag_name.split("-")[1]) 


                for k in karzina_srav:

                    if (k in prav_list) and (len(karzina_srav) == len(prav_list)):
                        remove_drags()

                        karzina_srav = []
                        prav_list = []
                        p = 1

                        stall.add(apple)
                        # stall.add(pear)
                        # stall.add(banana)
                        # stall.add(melon)
                        stall.add(cherry)
                        stall.add(basket)


                        return True
            else:
                p += 1

                if p >= p_max:
                    renpy.jump("noob")
                else: 
                    return 
There is also a function by which is determined what exactly should be dragging and therefore retire, when I start it, I have to add all the elements to the screen using across .add (child)

Code: Select all


    def add_drags():
        global spis, stall

        stall.add(apple)
        stall.add(pear)
        stall.add(banana)
        stall.add(melon)
        stall.add(cherry)
        stall.add(basket)


    def zapros(item1=None, item2=None, item3=None, item4=None, item5=None):
        global prav_list, vsego_slovar, spis_func, stall           
        prav_list = []

        spis_func = [item1, item2, item3, item4, item5] 

        for i in spis_func: 
            if i != None:               
                for what in vsego_slovar.keys():          
                    if i.title() == what.title(): ## Compare the entered values with a common dictionary
                        prav_list.append(vsego_slovar[i]) ## Add our items to the final customer list
                        print (vsego_slovar[i])

        add_drags()
When I first call this function everything works fine, but when I try to call the function a again I get this error:
  • Code: Select all

    I'm sorry, but an uncaught exception occurred.
    
    While running game code:
      File "game/script.rpy", line 243, in script
        call screen producti
      File "renpy/common/000statements.rpy", line 519, in execute_call_screen
        store._return = renpy.call_screen(name, *args, **kwargs)
    ZeroDivisionError: float division by zero
    
    -- Full Traceback ------------------------------------------------------------
    
    Full traceback:
      File "game/script.rpy", line 243, in script
        call screen producti
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\ast.py", line 1828, in execute
        self.call("execute")
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\ast.py", line 1816, in call
        return renpy.statements.call(method, parsed, *args, **kwargs)
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\statements.py", line 177, in call
        return method(parsed, *args, **kwargs)
      File "renpy/common/000statements.rpy", line 519, in execute_call_screen
        store._return = renpy.call_screen(name, *args, **kwargs)
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\exports.py", line 2710, in call_screen
        rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\ui.py", line 287, in interact
        rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\core.py", line 2649, in interact
        repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\core.py", line 3132, in interact_core
        self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\core.py", line 2055, in draw_screen
        renpy.config.screen_height,
      File "render.pyx", line 485, in renpy.display.render.render_screen
      File "render.pyx", line 233, in renpy.display.render.render
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\layout.py", line 717, in render
        surf = render(child, width, height, cst, cat)
      File "render.pyx", line 145, in renpy.display.render.render
      File "render.pyx", line 233, in renpy.display.render.render
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\layout.py", line 717, in render
        surf = render(child, width, height, cst, cat)
      File "render.pyx", line 145, in renpy.display.render.render
      File "render.pyx", line 233, in renpy.display.render.render
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\layout.py", line 717, in render
        surf = render(child, width, height, cst, cat)
      File "render.pyx", line 145, in renpy.display.render.render
      File "render.pyx", line 233, in renpy.display.render.render
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\screen.py", line 669, in render
        child = renpy.display.render.render(self.child, w, h, st, at)
      File "render.pyx", line 145, in renpy.display.render.render
      File "render.pyx", line 233, in renpy.display.render.render
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\layout.py", line 717, in render
        surf = render(child, width, height, cst, cat)
      File "render.pyx", line 145, in renpy.display.render.render
      File "render.pyx", line 233, in renpy.display.render.render
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\layout.py", line 717, in render
        surf = render(child, width, height, cst, cat)
      File "render.pyx", line 145, in renpy.display.render.render
      File "render.pyx", line 233, in renpy.display.render.render
      File "C:\Users\Администратор\Desktop\Программы\Renpy\renpy-7.0.0-sdk\renpy\display\dragdrop.py", line 458, in render
        done = (at - self.at) / (self.target_at - self.at)
    ZeroDivisionError: float division by zero
    
    Windows-7-6.1.7601-SP1
    Ren'Py 7.0.0.196
    Drag&Drop 1.0
    Tue Oct 09 23:28:02 2018
    
I declared variables like this:

Code: Select all

stall = DragGroup()

    apple = Drag(
        drag_name = "0-apple-Apple",
        d = "apple.png",
        droppable = False,
        dragged = fruit,
        pos = (pos_f[0][0], pos_f[0][1])
    )

    pear = Drag(
        drag_name = "1-pear-Pear",
        d = "pear.png",
        droppable = False,
        dragged = fruit,
        xpos =pos_f[1][0],
        ypos =pos_f[1][1]
    )

    banana = Drag(
        drag_name ="2-banana-Banana",
        d = "banana.png",
        droppable =False,
        dragged =fruit,
        xpos =pos_f[2][0], 
        ypos =pos_f[2][1]
    )

    melon = Drag(
        drag_name ="3-melon-Melon",
        d = "melon.png",
        droppable =False,
        dragged= fruit,
        xpos =pos_f[3][0], 
        ypos= pos_f[3][1]
    )

    cherry = Drag(
        drag_name= "4-cherry-cherry",
        d = "cherry.png",
        droppable= False,
        dragged= fruit,
        xpos= pos_f[4][0],
        ypos =pos_f[4][1]
    )

    ## Dropped
    basket = Drag(
        drag_name ="basket",
        d =  "basket.png",
        draggable = False,
        xpos= 450,
        ypos =140
    )
And I call this:

Code: Select all

screen producti:
    add "menu.jpg"

    add stall

label start:

    $ zapros("Pear", "Banana", "Melon")

    "[prav_list]" ## We check that we set everything correctly

    call screen producti 
    $ karzz = " ".join(karzina_pl) ## Displaying list items
    "In our basket [karzz]."

    $ zapros("Pear", "Banana", "Melon")
    call screen producti
And she gets out only on those items that were previously removed.
How to fix this problem? In the Internet there is nothing on this subject(

P.S.
Forgive me for my English - this is not my native language.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to return deleted objects DragGroup?

#2 Post by Remix »

A quick workaround (untested guesswork)

Amend
if not drop:
... drags[0].snap( ...

to
if not drop and drags[0].x:
... drags[0].snap( ...

If that doesn't work you may need to adjust the child.target_at after doing the remove
Frameworks & Scriptlets:

Pronax
Newbie
Posts: 7
Joined: Fri Jul 27, 2018 11:37 am
Contact:

Re: How to return deleted objects DragGroup?

#3 Post by Pronax »

Your method does not work, alas.
But thank you very much for the hint with the child.target_at!
Inserting this simple block before return True:

Code: Select all

apple.snap(pos_f[0][0], pos_f[0][1])
pear.snap(pos_f[1][0], pos_f[1][1])
banana.snap(pos_f[2][0], pos_f[2][1])
melon.snap  (pos_f[3][0], pos_f[3][1])
cherry.snap(pos_f[4][0], pos_f[4][1])

apple.target_at = 0
pear.target_at = 0
banana.target_at = 0
melon.target_at = 0
cherry.target_at = 0
It all worked for me!
Thanks again.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to return deleted objects DragGroup?

#4 Post by Remix »

Nicely done :)
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users