[SOLVED] how to grab and manipulate renpy elements by their IDs

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
The Historian
Newbie
Posts: 6
Joined: Sat Oct 29, 2022 5:43 pm
Completed: Stepmother's Maid
Projects: Greiya: Seven Kingdoms
itch: thehistorian
Contact:

[SOLVED] how to grab and manipulate renpy elements by their IDs

#1 Post by The Historian » Sun Oct 30, 2022 1:36 am

Hello!
I'm having trouble finding docs on how to grab and manipulate elements by their IDs.

The parts I'm having trouble with are the ones I marked with ###

Code: Select all

init python:
	def example_function(id_fixed, id_imagebutton, id_fixed_new):
		###Delete imagebutton with id_imagebutton, and add new imagebutton to id_fixed_new
		# OR, ALTERNATIVELY
		###Move imagebutton with id_imagebutton to id_fixed_new, and change the id and action of imagebutton with id_imagebutton to a new id and action

 
label start:
	screen my_example_screen:
    		fixed id "id_fixed":
      			imagebutton id "id_imagebutton":
				#idle, hover, etc.
        			action example_function("id_fixed", "id_imagebutton", "id_fixed_new") #wanna move this button to fixed below, and change its id and action
 
		fixed id "id_fixed_new":
		#properties, style, whatever, etc.

	show screen my_example_screen

This is a simplified example code block that shows the relevant parts. I can't use manual solutions like having the other button already in place but hidden, etc.

In short, I haven't been able to find how to grab elements by their IDs, or how to manipulate them afterwards.

Thank you in advance for any help!
Last edited by The Historian on Mon Oct 31, 2022 2:39 pm, edited 1 time in total.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1882
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: how to grab and manipulate renpy elements by their IDs

#2 Post by Ocelot » Sun Oct 30, 2022 5:02 am

In short: that would ne useless, since all changes would disappear when screen would reevaluate and redraw itself in the next instant.

You can conditionally create buttons from data contained in some container and your functions would just manipulate those containers.
< < insert Rick Cook quote here > >

The Historian
Newbie
Posts: 6
Joined: Sat Oct 29, 2022 5:43 pm
Completed: Stepmother's Maid
Projects: Greiya: Seven Kingdoms
itch: thehistorian
Contact:

Re: how to grab and manipulate renpy elements by their IDs

#3 Post by The Historian » Sun Oct 30, 2022 5:36 am

Ocelot wrote:
Sun Oct 30, 2022 5:02 am
In short: that would ne useless, since all changes would disappear when screen would reevaluate and redraw itself in the next instant.

You can conditionally create buttons from data contained in some container and your functions would just manipulate those containers.
Those changes shouldn't be permanent, they're only for when the current screen is displayed.

If I call the screen again, I don't want the screen with the updated state.

The Historian
Newbie
Posts: 6
Joined: Sat Oct 29, 2022 5:43 pm
Completed: Stepmother's Maid
Projects: Greiya: Seven Kingdoms
itch: thehistorian
Contact:

Re: how to grab and manipulate renpy elements by their IDs

#4 Post by The Historian » Mon Oct 31, 2022 2:39 pm

Not sure about grabbing and manipulating by IDs, but Ocelot (^ post #2) explained how to achieve result I wanted in alternative way here:
viewtopic.php?f=8&t=65589

I didn't quite get post #2 of this forum cause i'm fairly new to renpy and I didn't realize screen refreshes so often (on every interaction, I think?)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]