Page 1 of 1

Change Cursor Via Screen Imagebutton [Solved!]

Posted: Thu Feb 09, 2017 1:17 pm
by Heiden
Hi! I'm wanting to make it so that when a player clicks a certain imagebutton in my game, the cursor changes.

I'm using this code, taken from here (viewtopic.php?f=8&t=37403&hilit=mouse)

Code: Select all

init 1 python:
    def change_cursor(type="default"):
        persistent.mouse = type
        if type == "default":
            setattr(config, "mouse", None)
        elif type == "1":
            setattr(config, "mouse", {"default": [("images/gui/cursor1.png", 0, 0)]})
        elif type == "2":
            setattr(config, "mouse", {"default": [("images/gui/cursor2.png", 0, 0)]})
            
    if not hasattr(persistent, "mouse"):
        change_cursor()
    else:
        change_cursor(persistent.mouse)
and using it in the label scenes as such:

Code: Select all

    $ change_cursor("1")
    "Hey look at this cool cursor!"
    $ change_cursor("2")
    "Wow, another cool cursor!"

And things are working great when I test it out, but I'm a little unsure of how to exactly write the code in order to declare the "$ change_cursor("2")" in an imagebutton format. I've tried using a SetVariable and a SetScreenVariable but neither have worked.

So far what I have is:

Code: Select all

imagebutton auto "images/gui/inventory_screen/inventory_options_use_%s.png" xpos 0 ypos 0 focus_mask True action [ Hide("item_options"), Hide ("inventory_screen"), Show("inventory_button2"), SetVariable("item_use", "True"), SetVariable("inventory_look", "show"), SetVariable("change_cursor", "2"),]
I'm using Renpy 6.99.11, thank you so much for your help!

Re: Change Cursor Via Screen Imagebutton

Posted: Thu Feb 09, 2017 1:43 pm
by IrinaLazareva
try Function()

Code: Select all

        imagebutton auto ..... action Function(change_cursor, "1")
https://www.renpy.org/doc/html/screen_a ... l#Function

Re: Change Cursor Via Screen Imagebutton

Posted: Thu Feb 09, 2017 1:47 pm
by Heiden
It's working!!

Thank you so much! :D :D