[Solved]How to copy text with a button?

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
Adabelitoo
Regular
Posts: 86
Joined: Sat Apr 13, 2019 2:32 pm
Contact:

[Solved]How to copy text with a button?

#1 Post by Adabelitoo »

I want to make an imagebutton to copy a link instead of opening it. I searched and found CopyToClipboard(s) as an action but I couldn't make it work (also I don't understand what the "s" is for).

Also I'd like to add that function to the Quick Menu so people can report typos by copying the text and pasting it somewhere else. I don't know if I'll need the exact same thing as the one previously mentioned, so I'd like to know. Thanks for reading.

Bonus question: Maybe it's related to the last one so I'll post it here. Is it possible to save/store the last dialogue and display it when the player makes a save? I know that the game stores values and you can show them with things like %A, %d %b %Y, %H:%M, so maybe this is a thing. In theory, I guess it's already stored somewhere because the dialogue is displayed in the History screen, but I don't know if that applicable outside that screen.
Last edited by Adabelitoo on Mon Feb 05, 2024 3:40 am, edited 1 time in total.

User avatar
m_from_space
Miko-Class Veteran
Posts: 989
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to copy text with a button?

#2 Post by m_from_space »

Adabelitoo wrote: Sun Feb 04, 2024 11:54 pm I want to make an imagebutton to copy a link instead of opening it. I searched and found CopyToClipboard(s) as an action but I couldn't make it work (also I don't understand what the "s" is for).
The "s" is the string you want to copy to the clipboard. ;)

Code: Select all

imagebutton idle "myimage" action CopyToClipboard("http://lemmasoft.renai.us")
Also I'd like to add that function to the Quick Menu so people can report typos by copying the text and pasting it somewhere else. I don't know if I'll need the exact same thing as the one previously mentioned, so I'd like to know. Thanks for reading.
Yes, it's the same thing. If you make this specific button to report typos part of the say screen, you can just use the "what" variable (which is the spoken text at that moment) and copy it.

Code: Select all

screen say(who, what):
    ...
    textbutton "Report Dialogue Line" action CopyToClipboard(what)
Bonus question: Maybe it's related to the last one so I'll post it here. Is it possible to save/store the last dialogue and display it when the player makes a save? I know that the game stores values and you can show them with things like %A, %d %b %Y, %H:%M, so maybe this is a thing. In theory, I guess it's already stored somewhere because the dialogue is displayed in the History screen, but I don't know if that applicable outside that screen.
The history screen just displays all saved dialogue that is within the variable "_history_list". So you just can extract the last spoken line of dialogue from the list in a similar way the history screen does. And then just save it inside a global variable. Or do you want to show this last line inside the save slots? Then you have to save it as part of save data, by adding it to the json dictionary I believe. https://www.renpy.org/dev-doc/html/conf ... _callbacks

But here is a way to get the last line in general:

Code: Select all

screen last_spoken_line():
    if _history_list:
        $ last_entry = _history_list[-1]
        $ last_line = renpy.filter_text_tags(last_entry.what, allow=gui.history_allow_tags)
        text last_line
    else:
        text "There is no last line."
In Renpy 8.2 there is also this new function: https://www.renpy.org/dev-doc/html/othe ... y.last_say

User avatar
Adabelitoo
Regular
Posts: 86
Joined: Sat Apr 13, 2019 2:32 pm
Contact:

Re: How to copy text with a button?

#3 Post by Adabelitoo »

Thanks for replying.
m_from_space wrote: Mon Feb 05, 2024 3:00 am The "s" is the string you want to copy to the clipboard. ;)
I thought that was the case but it didn't work. I even copy-pasted your code but I get NameError: name 'CopyToClipboard' is not defined

User avatar
m_from_space
Miko-Class Veteran
Posts: 989
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to copy text with a button?

#4 Post by m_from_space »

Adabelitoo wrote: Mon Feb 05, 2024 3:15 am Thanks for replying.
m_from_space wrote: Mon Feb 05, 2024 3:00 am The "s" is the string you want to copy to the clipboard. ;)
I thought that was the case but it didn't work. I even copy-pasted your code but I get NameError: name 'CopyToClipboard' is not defined
You have to use Renpy 7.7 or 8.2 for that. It's a new function.

User avatar
Adabelitoo
Regular
Posts: 86
Joined: Sat Apr 13, 2019 2:32 pm
Contact:

Re: How to copy text with a button?

#5 Post by Adabelitoo »

m_from_space wrote: Mon Feb 05, 2024 3:32 am You have to use Renpy 7.7 or 8.2 for that. It's a new function.
I had 8.1 so I thought the version wouldn't be an issue, now it works. Thank you for everything.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Stampaw