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.
-
Dharker
- Regular
- Posts: 98
- Joined: Sun Sep 15, 2013 6:45 am
-
Contact:
#1
Post
by Dharker » Wed Apr 19, 2017 2:39 pm
Hi,
I am looking for a simple code that will open a directory in the game folder.
E.g. I have an image button where if you click on it, it goes to a website url.
Code: Select all
imagebutton auto "ui/bgselect/moviescene1a_%s.png" action [OpenURL("http://websiteurl.com"), Play("sound", "se/open.ogg")] hovered Play("sound", "se/select.ogg")
But what I would like is for instead of it opening a URL it opens a folder in the game directory.
Is this possible and what would the code be to replace the OPENURL code, and for it to automatically link to the game directory so i do not need to include the c: part as well. Just the folders after the /game/ part.
Thanks.
-
Dharker
- Regular
- Posts: 98
- Joined: Sun Sep 15, 2013 6:45 am
-
Contact:
#3
Post
by Dharker » Thu Apr 20, 2017 12:52 pm
Thxs, I was hoping to find something a little more 'safe' that might work on all platforms.
Ideally just similar to OPENURL but goes to a local folder, i don't really want it to open a file or exe. I just want it to open a folder within the game directory.
-
Saltome
- Veteran
- Posts: 237
- Joined: Sun Oct 26, 2014 1:07 pm
- Deviantart: saltome
-
Contact:
#4
Post
by Saltome » Fri Apr 21, 2017 1:07 am
Well, hate to say it but there's no such thing as "work on all platforms".
You can use the above example to open a folder. And I added a small change to make sure it doesn't crash on other operating systems... I hope. Now if it really is important you may consider extending the functionality so it works on other platforms. But if you can avoid it, do so.
You can use this as a normal function in the labels, or as a screen action.
Code: Select all
init python:
from os import startfile as osstartfile, name as osname
def opendir(path = "C:"):
if osname == "nt":
osstartfile(path)
@renpy.pure
class OpenDir(Action, DictEquality):
def __init__(self, path):
self.path = path
def __call__(self):
opendir(self.path)
screen test:
textbutton "OPEN" align(.5,.5) action OpenDir("C:\\")
label start:
"start"
"Regular function."
$ opendir("C:\\")
"Screen action."
show screen test
"end"
Deviant Art: 
-
xavimat
- Eileen-Class Veteran
- Posts: 1458
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love, unknown
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
-
Contact:
#5
Post
by xavimat » Fri Apr 21, 2017 12:00 pm
That thread is very old.
I'm using this code and (I think) it works:
Code: Select all
label open_folder:
python hide:
import subprocess
import sys
import os
import platform
bonus = os.path.abspath(os.path.join(config.basedir, "FOLDER_NAME_IN_BASEDIR"))
if sys.platform == "win32":
os.startfile(bonus)
elif platform.mac_ver()[0]:
subprocess.Popen([ "open", bonus ])
else:
subprocess.Popen([ "xdg-open", bonus ])
(I got this here:
viewtopic.php?f=8&t=10636 )
You could use also config.gamedir instead of config.basedir