A way to make custom cursor preference persistent data?

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
puffinlady
Regular
Posts: 56
Joined: Fri Jul 20, 2012 8:25 am
Completed: Soundless, Three Lilies
Projects: POLYCHROMANIA, 7388
Organization: milk+ visual
Tumblr: milkplusvn
itch: milkplus
Location: United States
Contact:

A way to make custom cursor preference persistent data?

#1 Post by puffinlady »

Hello!

I recently figured out how to give players the option to choose which cursor they want to use. It works great, except for one thing: the data isn't persistent, so when the player opens the game up again, their setting has reverted to the default.

I'm completely stumped on how I'm supposed to go about making it persistent...

Here's the snippet in my preferences screen that changes the cursor:

Code: Select all

hotspot (265, 297, 37, 34) action SetField(config, "mouse", {"default": [("gui/cursor.png", 1, 1)]}) ## This is the first game cursor option for the player
hotspot (313, 297, 40, 35) action SetField(config, "mouse", {"default": [("gui/cursor2.png", 1, 1)]}) ## This is the second game cursor option
hotspot (361, 299, 132, 28) action SetField(config, "mouse", None) ## This makes the cursor the player's own computer cursor
And here's config.mouse from options.rpy (probably the culprit, dunno how to catch it):

Code: Select all

define config.mouse = {"default": [("gui/cursor.png", 1, 1)]}
"A novel is never anything but a philosophy put into images." - Albert Camus
Posts written outside of our WIP/Completed threads are written by papaya


Image Image
Three Lilies | POLYCHROMANIA

zabuzaeldemonio
Regular
Posts: 103
Joined: Sun Jan 08, 2017 7:24 pm
Projects: Call Me
Location: Spain
Contact:

Re: A way to make custom cursor preference persistent data?

#2 Post by zabuzaeldemonio »

I do not know if this served you but I would do the following:

Code: Select all

        hotspot (265, 297, 37, 34) action [SetVariable("persistent.cursor1", "True"), SetField(config, "mouse", {"default": [("gui/cursor.png", 1, 1)]]}) ## This is the first game cursor option for the player
        hotspot (265, 297, 37, 34) action [SetVariable("persistent.cursor2", "True"), SetField(config, "mouse", {"default": [("gui/cursor2.png", 1, 1)]]}) ## This is the second game cursor option
        hotspot (361, 299, 132, 28) action SetField(config, "mouse", None) ## This makes the cursor the player's own computer cursor

Code: Select all

        if persistent.cursor1:
             define config.mouse = {"default": [("gui/cursor.png", 1, 1)]}
        elif persistent.cursor2:
             define config.mouse = {"default": [("gui/cursor2.png", 1, 1)]}
        else:
            define config.mouse = {"default": [("gui/cursor.png", 1, 1)]}
My personal Project:
Image

User avatar
puffinlady
Regular
Posts: 56
Joined: Fri Jul 20, 2012 8:25 am
Completed: Soundless, Three Lilies
Projects: POLYCHROMANIA, 7388
Organization: milk+ visual
Tumblr: milkplusvn
itch: milkplus
Location: United States
Contact:

Re: A way to make custom cursor preference persistent data?

#3 Post by puffinlady »

zabuzaeldemonio wrote: Tue Mar 13, 2018 6:49 pm I do not know if this served you but I would do the following:

Code: Select all

        hotspot (265, 297, 37, 34) action [SetVariable("persistent.cursor1", "True"), SetField(config, "mouse", {"default": [("gui/cursor.png", 1, 1)]]}) ## This is the first game cursor option for the player
        hotspot (265, 297, 37, 34) action [SetVariable("persistent.cursor2", "True"), SetField(config, "mouse", {"default": [("gui/cursor2.png", 1, 1)]]}) ## This is the second game cursor option
        hotspot (361, 299, 132, 28) action SetField(config, "mouse", None) ## This makes the cursor the player's own computer cursor

Code: Select all

        if persistent.cursor1:
             define config.mouse = {"default": [("gui/cursor.png", 1, 1)]}
        elif persistent.cursor2:
             define config.mouse = {"default": [("gui/cursor2.png", 1, 1)]}
        else:
            define config.mouse = {"default": [("gui/cursor.png", 1, 1)]}
Nope, didn't work. Trying to do it this way only confused the imagemap and made multiple buttons selected at the same time on restart.

Also, for persistent variables, you have to do SetField(persistent, "variable", "value"), not SetVariable().
"A novel is never anything but a philosophy put into images." - Albert Camus
Posts written outside of our WIP/Completed threads are written by papaya


Image Image
Three Lilies | POLYCHROMANIA

User avatar
puffinlady
Regular
Posts: 56
Joined: Fri Jul 20, 2012 8:25 am
Completed: Soundless, Three Lilies
Projects: POLYCHROMANIA, 7388
Organization: milk+ visual
Tumblr: milkplusvn
itch: milkplus
Location: United States
Contact:

Re: A way to make custom cursor preference persistent data?

#4 Post by puffinlady »

Update on my problem.

So, I figured out a way to make it persistent, by creating the variable persistent.mouseconfig and having config.mouse = persistent.mouseconfig.

And I made the preference action SetField(persistent, "mouseconfig", {"default": [("gui/cursor.png", 1, 1)]}) and so on and so forth.

However, it now no longer changes instantly, and the player must restart the game to see their cursor choice. Having multiple actions that change both persistent.mouseconfig and config.mouse just results in an imagemap selected/unselected mess on restart, and the buttons no longer function.

So now I wonder:
  1. Is there a way to force Ren'Py to refresh/re-check config.mouse when the player makes their choice so that it changes instantly? I'm fine with looking in to custom functions and such if there's a Python solution to this.
  2. If not, should I be approaching this from a different angle?
Full changes to the code here if anyone wants to try testing and figuring it out for themselves. I made them textbuttons too so you don't have to mess with that.

options.rpy

Code: Select all

default persistent.mouseconfig = None

#### some ways down ####

define config.mouse = persistent.mouseconfig
screens.rpy, in the Preferences screen

Code: Select all

        label _("Cursor")
        textbutton _("Cursor 1") action SetField(persistent, "mouseconfig", {"default": [("gui/cursor.png", 1, 1)]})
        textbutton _("Cursor 2") action SetField(persistent, "mouseconfig", {"default": [("gui/cursor2.png", 1, 1)]})
        textbutton _("System Cursor") action SetField(persistent, "mouseconfig", None)
"A novel is never anything but a philosophy put into images." - Albert Camus
Posts written outside of our WIP/Completed threads are written by papaya


Image Image
Three Lilies | POLYCHROMANIA

Post Reply

Who is online

Users browsing this forum: No registered users