Automated hyperlinks?
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.
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.
Automated hyperlinks?
Is there anyway I can set something up so that every time a specific word is said, it turns into a hyperlink so the player can see the definition of it?
- Milkymalk
- Miko-Class Veteran
- Posts: 752
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: Automated hyperlinks?
In theory yes, by rewriting the "say" screen and parsing the "what" argument before actually printing it. I'm not good with rewriting built-in stuff, though...
But be warned that it would probably get on the player's nerves to be still given the hyperlink after the tenth time...
But be warned that it would probably get on the player's nerves to be still given the hyperlink after the tenth time...
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Re: Automated hyperlinks?
Thanks for the answer! I'm sort of new to this so I'm not sure exactly what you mean... Is there any way you could give an example?Milkymalk wrote:In theory yes, by rewriting the "say" screen and parsing the "what" argument before actually printing it. I'm not good with rewriting built-in stuff, though...
But be warned that it would probably get on the player's nerves to be still given the hyperlink after the tenth time...
- Milkymalk
- Miko-Class Veteran
- Posts: 752
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: Automated hyperlinks?
The text box you see when a character says something is a screen that is built-in. It's defined on top of screens.rpy:
Because it's just normal screen language code, you can change this however you want. The important thing here is the argument "what" that is given to the screen. It contains the text to be displayed as speech.
What you need to do is string manipulation: Exchange every instance of a given word inside "what" with the same word embedded in hyperlink tags. This is a simple thing to do in Python, just look up string manipulation functions from the Python documentation.
What I don't know though is how to implement it into the screen because screens are quite odd: They don't execute when shown, but essentially ALL THE TIME. So if you replace a word with the same word and a tag, it will get replaced again and again.
I guess you could mark the word so the code knows if it has been replaced already; by using "+word+" instead of "word", so the code replaces it only then.
Example:
"This is a +sample+ sentence."
-> replace "+sample+" with "{a=labelname_to_call}sample{/a}"
Becomes: "This is a {a=labelname_to_call}sample{/a} sentence."
Code for this:
Add this line as the first line of the screen code, it MIGHT work. As I said, I'm not very good with this stuff, but the general method is like I said.
Anybody who knows better than me feel free to throw me out and show us how it's really done
Code: Select all
screen say:
# Defaults for side_image and two_window
default side_image = None
default two_window = False
# Decide if we want to use the one-window or two-window variant.
if not two_window:
# The one window variant.
window:
id "window"
has vbox:
style "say_vbox"
if who:
text who id "who"
text what id "what"
else:
# The two window variant.
vbox:
style "say_two_window_vbox"
if who:
window:
style "say_who_window"
text who:
id "who"
window:
id "window"
has vbox:
style "say_vbox"
text what id "what"
# If there's a side image, display it above the text.
if side_image:
add side_image
else:
add SideImage() xalign 0.0 yalign 1.0
# Use the quick menu.
use quick_menuWhat you need to do is string manipulation: Exchange every instance of a given word inside "what" with the same word embedded in hyperlink tags. This is a simple thing to do in Python, just look up string manipulation functions from the Python documentation.
What I don't know though is how to implement it into the screen because screens are quite odd: They don't execute when shown, but essentially ALL THE TIME. So if you replace a word with the same word and a tag, it will get replaced again and again.
I guess you could mark the word so the code knows if it has been replaced already; by using "+word+" instead of "word", so the code replaces it only then.
Example:
"This is a +sample+ sentence."
-> replace "+sample+" with "{a=labelname_to_call}sample{/a}"
Becomes: "This is a {a=labelname_to_call}sample{/a} sentence."
Code for this:
Code: Select all
$ what.replace("+sample+", "{a="labelname_to_call_in_new_context"}sample{/a}"Anybody who knows better than me feel free to throw me out and show us how it's really done
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Re: Automated hyperlinks?
Hmm, I tried it, but it says that it's not terminated with a new line and to check strings and parenthesis. I've been searching for the documentation on this, but I either can't find it or can't understand what it's saying well enough...Milkymalk wrote:The text box you see when a character says something is a screen that is built-in. It's defined on top of screens.rpy:Because it's just normal screen language code, you can change this however you want. The important thing here is the argument "what" that is given to the screen. It contains the text to be displayed as speech.Code: Select all
screen say: # Defaults for side_image and two_window default side_image = None default two_window = False # Decide if we want to use the one-window or two-window variant. if not two_window: # The one window variant. window: id "window" has vbox: style "say_vbox" if who: text who id "who" text what id "what" else: # The two window variant. vbox: style "say_two_window_vbox" if who: window: style "say_who_window" text who: id "who" window: id "window" has vbox: style "say_vbox" text what id "what" # If there's a side image, display it above the text. if side_image: add side_image else: add SideImage() xalign 0.0 yalign 1.0 # Use the quick menu. use quick_menu
What you need to do is string manipulation: Exchange every instance of a given word inside "what" with the same word embedded in hyperlink tags. This is a simple thing to do in Python, just look up string manipulation functions from the Python documentation.
What I don't know though is how to implement it into the screen because screens are quite odd: They don't execute when shown, but essentially ALL THE TIME. So if you replace a word with the same word and a tag, it will get replaced again and again.
I guess you could mark the word so the code knows if it has been replaced already; by using "+word+" instead of "word", so the code replaces it only then.
Example:
"This is a +sample+ sentence."
-> replace "+sample+" with "{a=labelname_to_call}sample{/a}"
Becomes: "This is a {a=labelname_to_call}sample{/a} sentence."
Code for this:Add this line as the first line of the screen code, it MIGHT work. As I said, I'm not very good with this stuff, but the general method is like I said.Code: Select all
$ what.replace("+sample+", "{a="labelname_to_call_in_new_context"}sample{/a}"
Anybody who knows better than me feel free to throw me out and show us how it's really done
- Milkymalk
- Miko-Class Veteran
- Posts: 752
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: Automated hyperlinks?
Sorry, I missed a closing parenthesis und used quotation marks where no belong:Mithrilda wrote:Hmm, I tried it, but it says that it's not terminated with a new line and to check strings and parenthesis. I've been searching for the documentation on this, but I either can't find it or can't understand what it's saying well enough...Code for this:Code: Select all
$ what.replace("+sample+", "{a=labelname_to_call_in_new_context}sample{/a}"
Code: Select all
$ what.replace("+sample+", "{a=labelname_to_call_in_new_context}sample{/a}")Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Who is online
Users browsing this forum: Google [Bot]