Is it possible for the script to recognise game files?

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
Lucky Duck
Regular
Posts: 32
Joined: Fri Dec 15, 2017 5:08 am
Deviantart: AdamAnimationz
Skype: theluckiestofpone@gmail.com
Contact:

Is it possible for the script to recognise game files?

#1 Post by Lucky Duck »

What I mean by this is...

...Maybe this'll help explain better: I'm sure everyone has played or at-least know of the game "doki doki literature club". Im curious to ask how they did the whole bit of where you need to delete something from the game to make the game fixed if that makes sense?

Like the script/game is constantly searching for a file in its folders but asoon as you remove it you break the game to fix the game, if that makes sense? ^^'' so basically im asking how can i replicate the script looking for a file like how they did in doki doki literature club? ^^

hopfully that made sense ^^'' I probably said it wrong ;-;

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Is it possible for the script to recognise game files?

#2 Post by RicharDann »

I'm not really sure how DDLC actually does it but it's probably using renpy.exists.

For example, the game could check if the files are there before starting:

Code: Select all

label before_main_menu:
    if renpy.exists("file"):
       # jump to a label, or show the main menu
    else:
       # show game over 
This label is run whenever the game is started and before showing the main (title) menu. If it finds the file, it would execute some code, either start the game, or jump to some label. If it doesn't, some other code like the game over or the ending scene is run. Again, this is only a theory, it could work out,

BUT!...

Be very careful with using this kind of code, specially if you don't know much Python or Ren'Py, if misused it can easily break the game or cause unexpected behavior.
The most important step is always the next one.

Lucky Duck
Regular
Posts: 32
Joined: Fri Dec 15, 2017 5:08 am
Deviantart: AdamAnimationz
Skype: theluckiestofpone@gmail.com
Contact:

Re: Is it possible for the script to recognise game files?

#3 Post by Lucky Duck »

Richar, i dont know much about it ^^'' but i really want to do the same thing they did in that game though. Would it be possible to combine the code you wrote with a scene later on? so say you start the game and delete the file the game will check that its gone but nothing happens. BUT if you get half way through the game and the script knows its half way through and you delete it, THEN it does extra stuff in the game, i-if that makes sense? so it knows you cant change/delete the game just yet, but only when your reach a certain point in the game? ^^''

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Is it possible for the script to recognise game files?

#4 Post by RicharDann »

Yes, that ceirtainly should be possible. You can check "if this file exists" in any point of the game you want. But note the script will not be constantly checking if the file exists (it could, but that could cause problems). That code I wrote however doesn't do anything as is, it's just an example. But yeah the file check can be done mid-game. I may have to write an short example game to try this further, to be honest I haven't tested it that much yet.

I would advice against tinkering with this until you learn more about programming and the way Ren'Py works though. If you're still going to, you should at least back up your game before trying stuff in case something unexpected happens. Or have an experienced programmer take care of that part of your game.
The most important step is always the next one.

Lucky Duck
Regular
Posts: 32
Joined: Fri Dec 15, 2017 5:08 am
Deviantart: AdamAnimationz
Skype: theluckiestofpone@gmail.com
Contact:

Re: Is it possible for the script to recognise game files?

#5 Post by Lucky Duck »

Thank you so much for all of this ^^ umm I havent actually made a game yet ^^'' because I wanted to know how todo this first to give it ago. And to make a little tiny version of the gaming checking if the file is missing to continue as a test for an actual game. I dont know where to find an experienced programmer though so that's why i asked ^^''

Would there be any chance if your ever free for you to mess around with it untill it does work? I know thats asking alot :S but you seem to know alot about it, and im sorry for bothering you with this ^^'' So would you be able to test it further? ^w^

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Is it possible for the script to recognise game files?

#6 Post by RicharDann »

To be honest, I'm not really an expert or anything, I just know stuff that I've learned here by asking questions in this forum, reading the Ren'Py Documentation that I linked to, studying other people's games and code, and practicing myself.

There's an entire section of the forum here: viewforum.php?f=66 where programmers offer their help in this kind of work, some of them even do so for free. You can go there and see if someone is avaiable. I would really like to help you too, but I have a couple projects to look after already. There are many talented people here in this forum who will be happy to help you as well.

I did however test this out a little and I made a short example project, here.
The Key_v1.rar
(436.79 KiB) Downloaded 77 times
To test it out, go to the game folder, look for keys directory and take out the main_key file (it can be any kind of file, and it can be in any folder, this is again just an example). If all goes well (it did for me, but who knows) the game will react to not finding the file. I'm assuming you already have the Ren'Py SDK installed and know how to work with it. If not, I suggest you do and read the quick start tutorials and then try this.

Here's the script too, just in case:

Code: Select all

# The script of the game goes in this file.

label start:

    #If you uncomment the lines below, the game will look for the file
    #right at the start. I commented them to demonstrate the check
    #can be made mid-game.

    # This is is the code check.
    # if renpy.exists("keys/main_key"):

    #     jump normal_game

    # else:
    #     jump end_error

   jump normal_game
   
label normal_game:

    "Hello there."

    "This is a really short game."

    "Are you making sure that the Main Key file is doing okay?"


    # Here we check if the file exists. If it does, some dialogue
    #is displayed.
    if renpy.exists("keys/main_key"):

        "..."

        "Oh, there it is. Great."

        "Who knows what would happen if it weren't."

        return

    #If the file is not found, jump to the end_error label
    else:

        jump end_error

label end_error:
    "main_key not found..."

    "Wait....... it's gone......."

    "Where is the file.......?"

    "Ah, you deleted it, didn't you!"

    "Well I hope you're happy. You broke the game."

    "Good bye."

    return
The most important step is always the next one.

Lucky Duck
Regular
Posts: 32
Joined: Fri Dec 15, 2017 5:08 am
Deviantart: AdamAnimationz
Skype: theluckiestofpone@gmail.com
Contact:

Re: Is it possible for the script to recognise game files?

#7 Post by Lucky Duck »

Thank you so so much for all your help ^^ c: it means alot c: and i know your busy with your own things :S but umm

would it be possible for it to reach the extra scene when the file is deleted at a certain point in the game, so say your in the middle and delete it it'll know its the middle and the files gone to activate, instead of at the begining so maybe theres 2 secret scenes like;

if you delete it at the VERRY begining at the game it'll say "uh oh! looks like you tried todo something you shouldtn of... just yet" then when your at the middle of the game and do it, you get a different scene ending, sorry if that sounds confusing ^^''

and is this possible, if you delete the file in the beginning you wont have it so your stuck on the first secret screen and cant do anything now cause the files gone, is it possible for the game to check where you are in the game say the beginning and not the middle and if the files deleted, and after it saying the uh oh message, it recreates the file you deleted so you dont have to remake the file and everything, if possible?

and i played your key game and it was amazing >w< thank you for testing it out >w< but would what i suggested above be able to be implemented? >w<

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Is it possible for the script to recognise game files?

#8 Post by RicharDann »

Yes, all of that should be possible. It was made in DDLC, remember?

Probably using persistent data and some sort of flag check. Many ways to go about this.
The most important step is always the next one.

Lucky Duck
Regular
Posts: 32
Joined: Fri Dec 15, 2017 5:08 am
Deviantart: AdamAnimationz
Skype: theluckiestofpone@gmail.com
Contact:

Re: Is it possible for the script to recognise game files?

#9 Post by Lucky Duck »

Yeah I remember xd its just im a little confused on how to implement it myself ^^''

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Is it possible for the script to recognise game files?

#10 Post by trooper6 »

You should remember that DDLC is an example of advanced coding. You might want to start with the basics first. Learn how to make a simpler RenPy game, integrate some Python into it. And build up.

Understanding the basics and intermediates will mean that you'll be able to work it out yourself...or better understand what people tell you when you ask for help.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Alejandro Lovera
Newbie
Posts: 3
Joined: Thu Apr 08, 2021 12:02 pm
Tumblr: no
Deviantart: no
Github: no
Skype: no
Soundcloud: no
itch: no
Contact:

Re: Is it possible for the script to recognise game files?

#11 Post by Alejandro Lovera »

Lucky Duck wrote: Mon Dec 18, 2017 4:46 pm Yeah I remember xd its just im a little confused on how to implement it myself ^^''

Hi, have you found the solution or rather the code needed to make the game recognize when a file is deleted?

uncoded
Regular
Posts: 27
Joined: Fri Apr 09, 2021 10:29 am
Contact:

Re: Is it possible for the script to recognise game files?

#12 Post by uncoded »

I don't know of DDLC, but if I wanted the player to delete a file inside my very own game directory, this is how I'd do it:
  • have in my game files a file that is both easy to find and contains nothing useful to my game (excepted the fact that it has to exist or not), let's call it LOOK_INSIDE_THIS_FOLDER/DELETE_ME.txt ; its content doesn't matter, but I could write a message to the player, an easter egg in it or something
  • if the file exists (see below), I'd ask the player in game to find and delete the file LOOK_INSIDE_THIS_FOLDER/DELETE_ME.txt and start a while loop.
    I'd provide him/her with the absolute path to my file, ofc, so they can find the file "easily" (some users don't even know what a folder or a path are).
  • as soon as I detect (see below) the file deletion, I exist my loop and game progresses further
To check if a file exists, I'd use pure python code, something along the lines of :

Code: Select all

import os
try:
    while os.stat('LOOK_INSIDE_THIS_FOLDER/DELETE_ME.txt'):
        pass  # blocking wait
except FileNotFoundError:
    pass  # game continues below
# implement the rest of your game here
I don't yet know Ren'Py well enough to provide a full solution, tho.
The blocking wait in particular can have undesired side effects, idk.

⚠️ Disclaimer: You should never, ever trust your player to tamper with your game files *.
That's why, if I wanted my players to do this, I'd add additional security to make sure it doesn't break anything important (like his or her save files, or critical code or config). Thus, I'd do one or more of these additional steps :
  • backup my whole game folder somewhere else, add a game files corruption detection check, and rollback using my backup if anything goes wrong. Can be hard and not foolproof.
  • use an online updater and rollback using it in case I detect anything wrong. Not easier by any means.
  • do not ask my players to tamper with my game files ; instead, I'd create the DELETE_ME.txt file anywhere on my user machine I have access to and that shouldn't contain system data (user folder presumably), and ask my user to delete it there. If they don't know what they are doing, the least they ever look inside my game files, the better. This seems the easiest, but it's not always possible depending on your player's OS or your own build target.
* I'm not against modding, but that's another topic. Modders generally know what they are doing and/or assume the risks.
🐾

Alejandro Lovera
Newbie
Posts: 3
Joined: Thu Apr 08, 2021 12:02 pm
Tumblr: no
Deviantart: no
Github: no
Skype: no
Soundcloud: no
itch: no
Contact:

Re: Is it possible for the script to recognise game files?

#13 Post by Alejandro Lovera »

I really hope it is not too much trouble to ask but could you make a short example, with about 2 or 3 lines of dialogue please, I really am the first time I try with these renpy functions but I would like to learn

uncoded
Regular
Posts: 27
Joined: Fri Apr 09, 2021 10:29 am
Contact:

Re: Is it possible for the script to recognise game files?

#14 Post by uncoded »

Well, RicharDann provided a solution that seems perfectly fine a few posts ago.
Anything your don't understand with it?
🐾

Alejandro Lovera
Newbie
Posts: 3
Joined: Thu Apr 08, 2021 12:02 pm
Tumblr: no
Deviantart: no
Github: no
Skype: no
Soundcloud: no
itch: no
Contact:

Re: Is it possible for the script to recognise game files?

#15 Post by Alejandro Lovera »

uncoded wrote: Sat Apr 10, 2021 4:21 am Well, RicharDann provided a solution that seems perfectly fine a few posts ago.
Anything your don't understand with it?
Sorry for the delay in responding ... I had a question that is not so related to this function to delete files, but I have a question and if you know a little about the subject I would appreciate it a lot, it is about how to make renpy can open an external file, such as an .exe file .mp4 .txt etc ... I wanted to implement a dynamic similar to that of doki doki literature club but this mechanism would work in that a certain part of the script uses a python command to open a game that is inside the game folder and also a, mp4 to add the feeling of horror to the game however following the python command in the game, for a second it seems to open a window but it closes automatically and I don't know what to do I may have to, I already made sure that the location of the .exe is correct, I was in charge of opening the game from program files (so that it automatically grants administrator rights) and also that all the information of the .exe is inside the ga folder I and since it did not work I would like to know if I am doing something wrong -.- that is my doubt in advance, thank you very much for helping newbies like me in things like this

init python:
import os

label borrado:
scene bg kitchen with wipeleft_scene
show monika 1b at t31
m "mmm"
m "acabas de borrar a yuri"
m 1b "..."
m "no importa"

$ os.system("../zsnesw.exe")

m "jeje"


This is the script I wrote

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]