https weblinks won't work [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
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

https weblinks won't work [solved]

#1 Post by korova »

Hello !

I have implemented several weblinks in my game.

Most of them work just fine (webbrowser opens on the right page) except ...
links beginning with https

When clicking on those I get :

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 225, in script
  File "renpy/common/000statements.rpy", line 358, in python
  File "renpy/common/00defaults.rpy", line 120, in python
ScriptError: could not find label 'https://www.flickr.com/photos/e_cathedra/2958654667/'.
As I understand it, the program does not recognise that this is a weblink, and not a label.

Is it a bug or a feature ?

Is there any way to go round this error ?

Thanks for your advice.
Last edited by korova on Tue Apr 08, 2014 10:08 am, edited 1 time in total.

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: https weblinks won't work

#2 Post by Asceai »

Yeah, you need to replace the hyperlink handler. The default one is pretty limited

Code: Select all

init python:
  def new_hyperlink_style(target):
    return style.hyperlink_text
    
  def new_hyperlink_function(target):
    if target.startswith("http:") or target.startswith("https:"):
      try:
        import webbrowser
        webbrowser.open(target)
      except:
        pass
    else:
      renpy.call_in_new_context(target)
  
  style.default.hyperlink_functions = (new_hyperlink_style, new_hyperlink_function, None)

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: https weblinks won't work

#3 Post by korova »

Worked like a charm !

Thanks a lot !

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: https weblinks won't work [solved]

#4 Post by PyTom »

This is a good change, I've generalized it a bit, and will include it in the next release of Ren'Py.

Thanks.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Karrion