Change Cursor Via Screen Imagebutton [Solved!]

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
User avatar
Heiden
Regular
Posts: 140
Joined: Sat May 11, 2013 3:20 pm
Completed: Elvine, The Life Threads, Helena's Flowers, Dr. Frank's Build-A-Boyfriend, Beyond the Deep, The Bog's Heart, The Girl With the Gray Hair Awakens, The Far Rings, NB107A
Projects: The Town Pages, Kill the Prince?! [Nano 2020]
Tumblr: heidengames
itch: Heiden
Contact:

Change Cursor Via Screen Imagebutton [Solved!]

#1 Post by Heiden » Thu Feb 09, 2017 1:17 pm

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!
Last edited by Heiden on Thu Feb 09, 2017 1:48 pm, edited 1 time in total.
Completed: Elvine (GxB), The Life Threads, Helena's Flowers (GxG)(As Writer, Coder), Dr. Frank's Build-A-Boyfriend (BxB), Beyond the Deep (GxB)(As Artist), The Bog's Heart, The Girl with the Gray Hair Awakens, The Far Rings, NB107A.

All available to play on my itch.io page!

User avatar
IrinaLazareva
Veteran
Posts: 389
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Change Cursor Via Screen Imagebutton

#2 Post by IrinaLazareva » Thu Feb 09, 2017 1:43 pm

try Function()

Code: Select all

        imagebutton auto ..... action Function(change_cursor, "1")
https://www.renpy.org/doc/html/screen_a ... l#Function
There is a light at the end of the tunnel, just pray it's not a train.

___
TODO: unresolved/нерешённое

User avatar
Heiden
Regular
Posts: 140
Joined: Sat May 11, 2013 3:20 pm
Completed: Elvine, The Life Threads, Helena's Flowers, Dr. Frank's Build-A-Boyfriend, Beyond the Deep, The Bog's Heart, The Girl With the Gray Hair Awakens, The Far Rings, NB107A
Projects: The Town Pages, Kill the Prince?! [Nano 2020]
Tumblr: heidengames
itch: Heiden
Contact:

Re: Change Cursor Via Screen Imagebutton

#3 Post by Heiden » Thu Feb 09, 2017 1:47 pm

It's working!!

Thank you so much! :D :D
Completed: Elvine (GxB), The Life Threads, Helena's Flowers (GxG)(As Writer, Coder), Dr. Frank's Build-A-Boyfriend (BxB), Beyond the Deep (GxB)(As Artist), The Bog's Heart, The Girl with the Gray Hair Awakens, The Far Rings, NB107A.

All available to play on my itch.io page!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], richycapy