[SOLVED] create and delete imagebuttons from python block
Posted: Mon Oct 31, 2022 8:19 am
I'm trying to delete imagebuttons by id from a python function, as well as add imagebuttons to specific 'fixed' blocks, by id, from a python function.
But I've been searching for days and haven't been able to find docs on python functions that do this stuff.
This part (found from very outdated docs, renpy 5.6) almost works for adding imagebuttons. Except hover image (img2) doesn't work (doesn't show on hover), and the clicked (or action) function is triggered on hovers as well as clicks. The hovered function works fine.
Still dunno how to add it to a 'fixed' block though. I think get_displayable(screen, id) can grab a 'fixed' block correctly, but idk how to add an imagebutton as its child.
Are there no built in functions for this? Would I be able to do this with creator-defined displayables?
I'm familiar with using classes, but i'm fairly new to renpy, and what I can't find is docs of python functions, methods, properties, etc. for renpy. (except the python equivalents https://www.renpy.org/doc/html/statemen ... lents.html which just gives an overview.)
What i basically want is:
for some context, this is for a chess-like board game, except the board is bigger than screen so it's in a vpgrid. And the tiles have unique status effect that show on hover, so each tile is an imagebutton. Other imagebuttons - like chess pieces - are placed on top of certain tiles (so tiles + "chess pieces" are in 'fixed' blocks) and can be moved.
The only part I'm having trouble with is "moving" the "chess pieces", by removing and adding imagebuttons from inside python functions.
Basically, this. But everything here is placeholder, i'm just getting the "move" functionality to work. I wanna move the placeholder sword icons, which are imagebuttons. The tiles are also imagebuttons, the odd one out is being hovered over.

even if not direct answers, just links to relevant docs, example codes, etc. would be extremely appreciated
But I've been searching for days and haven't been able to find docs on python functions that do this stuff.
Code: Select all
init python:
def add_button(img1, img2):
ui.imagebutton(img1, img2, clicked=click_function() , hovered=hover_function()) # using clicked=None, action = click_function() gives same problem described below
Still dunno how to add it to a 'fixed' block though. I think get_displayable(screen, id) can grab a 'fixed' block correctly, but idk how to add an imagebutton as its child.
Are there no built in functions for this? Would I be able to do this with creator-defined displayables?
I'm familiar with using classes, but i'm fairly new to renpy, and what I can't find is docs of python functions, methods, properties, etc. for renpy. (except the python equivalents https://www.renpy.org/doc/html/statemen ... lents.html which just gives an overview.)
What i basically want is:
Code: Select all
init python:
example_function(fixed_id, old_imgbutton_id, new_imgbutton_id):
#none of the below are actual functions, they're pseudo code for what I want to do.
#renpy.delete(old_imgbutton_id)
#fixed_to_add_img_to = renpy.get_by_id(fixed_id)
#fixed_to_add_img_to.children.append(renpy.imagebutton("idle_img", "hover_img", action=another_example_function(), hover=foo_bar(), id=new_imgbutton_id))
#I completely understand these changes aren't permanent to the script/screen. They're not meant to be. That's kind of the point of why i need to do them from a function.
The only part I'm having trouble with is "moving" the "chess pieces", by removing and adding imagebuttons from inside python functions.
Basically, this. But everything here is placeholder, i'm just getting the "move" functionality to work. I wanna move the placeholder sword icons, which are imagebuttons. The tiles are also imagebuttons, the odd one out is being hovered over.

even if not direct answers, just links to relevant docs, example codes, etc. would be extremely appreciated