Exception: Drag expects a child

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
ChesStrategy
Regular
Posts: 96
Joined: Wed Jan 14, 2015 7:01 pm
Contact:

Exception: Drag expects a child

#1 Post by ChesStrategy »

Hi, new to ren'Py and a beginner on Python.

I've followed most of the tutorials and wiki and have been able to get stuff I wanted working. However, I'm still trying to figure out how drag and drop works; preferably sticking with python code instead of the screen language. I've stripped down my code to make it more easily reproducible:

Code: Select all

# The game starts here.
label start:
    python:
        def inventory(**kwargs):
            testItem = ui.textbutton("TestItem",action=SetVariable("success", True ),xsize=10, ysize=10)
            ui.drag(drag_name="TestItem")
            ui.close()
            
        renpy.define_screen("test_inventory", inventory)
    
    show screen test_inventory
    pause

return

Code: Select all

Exception: Widget <Drag at 42c9bf0> expects a child.
Any help is greatly appreciated!

On a separate, minor note, would a scrolling viewport with multiple drags be feasible? That is it possible to expand this further to use a viewport with a nested Fixed which have multiple drags added inside? That would be my ideal goal :D ; to have a scrollable inventory where I can drag items out to 'equip' on a character's paper doll (on another screen).

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Exception: Drag expects a child

#2 Post by xela »

I don't know how to describe thr error better than the Exception does.

Your post is also really weird and hard to respond to, there should not be any conceivable advantage to using ui module over sl, it's like asking about the best way to make your renpy experience the most unpleasant.

If you believe you really can't pull your design off with sl and need freedom and complexity of python, use instances of classes instead of ui.
Like what we're doing? Support us at:
Image

ChesStrategy
Regular
Posts: 96
Joined: Wed Jan 14, 2015 7:01 pm
Contact:

Re: Exception: Drag expects a child

#3 Post by ChesStrategy »

I guess I must be missing something about the creating the drag object. PyTom mentioned in an older post (possibly outdated) that if we use the UI object and create a drag that way (i.e ui.drag() ), we don't need to supply the first argument? Anyways, here was the post I was referring to:

http://lemmasoft.renai.us/forums/viewto ... ag#p121086

In the example PyTom gives, he also uses the an id argument; I was not sure if ui.drag() has that anymore since the post was from awhile ago and I no longer see it in the documentation. Sorry for any potential obvious questions, but I mainly just want to get a working example of drag.

I did get a working example of drag with the screen language; but I still ran into the same exception when I made the screen more complex. I can post the more complicated example with the screen language here, if you guys prefer to help me with that instead.

The ultimate result I would like, screen language used or not. Is a vertically scrollable, draggable window that holds a vbox (or vertical list) of draggable objects itself. Each draggable object would be a button with both an image and text, and can be dragged from the current list, to another screen.

Hope this is clearer. :(

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Exception: Drag expects a child

#4 Post by xela »

ChesStrategy wrote:Hope this is clearer. :(
It is, but nothing changes. ui module may not even be officially supported other and remains there for backwards compatibility. If you run into issues, there will be less people willing to help you out on the forums and if there are bugs, they may not be fixed ever or at least not make a priority for the developers.

My point is, if you want to drop screen language and create a pure python implementation, do so using Drag and DragGroup classes, not the ui module.
ChesStrategy wrote:I guess I must be missing something about the creating the drag object. PyTom mentioned in an older post (possibly outdated) that if we use the UI object and create a drag that way (i.e ui.drag() ), we don't need to supply the first argument? Anyways, here was the post I was referring to:

http://lemmasoft.renai.us/forums/viewto ... ag#p121086

In the example PyTom gives, he also uses the an id argument; I was not sure if ui.drag() has that anymore since the post was from awhile ago and I no longer see it in the documentation. Sorry for any potential obvious questions, but I mainly just want to get a working example of drag.
It may take the followup statement as a child, I've never used drag/drop paired with ui module. I've tried putting the button after the drag and it threw a different error, so I am prolly right.
ChesStrategy wrote:I did get a working example of drag with the screen language; but I still ran into the same exception when I made the screen more complex. I can post the more complicated example with the screen language here, if you guys prefer to help me with that instead.
Ideally, you'd want to isolate the code causing the error and post it here, maybe even in a dummy project.
ChesStrategy wrote:The ultimate result I would like, screen language used or not. Is a vertically scrollable, draggable window that holds a vbox (or vertical list) of draggable objects itself. Each draggable object would be a button with both an image and text, and can be dragged from the current list, to another screen.
Dragging it to another screen may be a bit tricky (although it may be doable, I just try to avoid creating problems for myself). Otherwise, sounds both doable and reasonable.
Like what we're doing? Support us at:
Image

ChesStrategy
Regular
Posts: 96
Joined: Wed Jan 14, 2015 7:01 pm
Contact:

Re: Exception: Drag expects a child

#5 Post by ChesStrategy »

Xela,

I'll take your advice and try using the Drag and Draggroup python classes directly then. Can you direct me to an example within a tutorial, wiki, or here on the forums that uses a displayable with renpy.Render() to create a screen?

Or, if I'm misunderstanding how renpy.render() works; does it bypass using screens altogether? So I just have to call it in a python block somewhere after label: Start?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Exception: Drag expects a child

#6 Post by xela »

You don't render them, that's taken care of. You're setting up the displayable and show them using the renpy.show function.

There are no tutorials but I think the solitaire game is built using classes and that's mostly drag/drop.

Honestly I see no reason not to use screen language, but it's always the call of a programmer.
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Ocelot