Conceptual questions regarding Ren'Py engine

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:

Conceptual questions regarding Ren'Py engine

#1 Post by ChesStrategy »

Hi all,

I've been digging through the renpy code on github, and I understand some of it. But I'm hoping someone is willing to fill in some knowledge gaps that I have. Hopefully, this will help me accelerate on my project.

Questions
1. I'm partially assuming that renpy has a 'main game loop' like most engines, and that renpy iterates through all of its layers (master, transient, etc), and calls renpy.redraw() on each Displayable/Tranform in each layer on some interval. If I use renpy.show() (without screens, directly on displayables themselves), how should I go about programmatically positioning the displayables and have their position retained between renpy.redraw() calls?

To understand my confusion, see the following code I got working in script.rpy:

Code: Select all

label start:
    python:
        
        fixedBox = renpy.display.layout.MultiBox(layout="fixed")
        fixedBoxBg = Window(child=fixedBox, xmaximum = 200, ymaximum = 200)
        drag_fixedBox = Drag(d=fixedBoxBg,drag_name="my_inv",drag_handle=(0,0,20,20))
        
        #add one item
        t1 = Text("Item 1")
        b1 = Button(child=t1)
        drgItem1 = Drag(d=b1,drag_name="drag_test_item1",drag_handle=(0,0,10,10),id="test4")
        fixedBox.add(drgItem1)
        
        renpy.show("an_alias",what=drag_fixedBox)
        
    pause
    return
I loaded my game successfully then went to the console to try to figure out how renpy places things per 'game loop'. I noticed that drag_fixedBox.xpos and .ypos were 0, so I set them to arbitrary values, and called renpy.redraw(). Nothing happened.

I then set the x and y attributes to some value and called renpy.redraw() and it worked; the displayable was repositioned! :D
However, if I call redraw() again, the position resets back to x=0 y=0. :( I want to see how ren'py positions things, so that I know how to write my event function logic for my UDD/CDD.

Lastly, I noticed that dragging the example displayable around did not change the positional values? What am I missing here?

2. Do displayables need to be added to Screens in order to retain position information? If so, for each screen I create... do I need one of each, all linked by a common screen name?
  • Screen(...)
  • ScreenDisplayable(...)
  • ScreenCache(...)
  • ScreenProfile(...)
If there is a better way to create a screen and not use the ui functions (and somehow create the displayable objects and attach them to a screen) how would I go about doing that?

Thanks for the help and clarifications! Ren'Py has been helpful for my project thus far :D

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

Re: Conceptual questions regarding Ren'Py engine

#2 Post by xela »

1) Is not a valid question, Displayable do not change their positions on redraw, only drags do.

2) No, displayable do not need to be added to Screens in order to retain position information.

Drags within a complex system should go through a function that snaps their positions and handles relevant logic. You Drag is jumping back to it's default position because it is setup to do so by it's default mechanism.

For a dummy drag, you can use: Drag(d=Solid("F00", xysize=(50, 50)), **rest_of_your_kwargs) will work.

====================
I've asked you to post a dummy project with the screen drag/drop code that you had trouble with before you switched to classes, my offer to take a look at it still stands for the weekend ;)
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: No registered users