Realtime/automatic triggered events[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
Ghuraok
Newbie
Posts: 11
Joined: Wed Jul 19, 2017 7:50 pm
Contact:

Realtime/automatic triggered events[Solved]

#1 Post by Ghuraok »

Hi !
I solved my own problem, now I still wanted to post it in case people would have need of a solution for such need/issue. Also I'm open to suggestions if anyone has a more elegant or cleaner solution.

My question was:
Is there a way to automatically run an action within a screen?

Why from Screens?
Well firstly because they're able to verify variables values in realtime and secondly because the jump for a certain label would occur whenever a certain screen is displayed. Let's say it's a user menu, this way the player is out of any sequence and the triggered event can't harm in any ways the gameplay.
I discovered there could be timers on screens and they do work with Jumps, so I simply added one that has 0.01 time left to make sure the player doesn't wait. This way I can set a sequence of events inside a label that can only be jumped to whenever the screen is displayed and the conditions are met.

A major benefit from this is that there's no need to explicitly ask the game to verify for events to run, it will simply activate right when the conditions are met. I find it practical for a game over, or a bad ending, like in Ace Attorney, when you gave too many bad answers. It's a lot cleaner in my opinion.

It presents a few limitations though, like the fact you must prevent the timer to start again once you're done checking for events to run, which can be a bit annoying if you want conditions for such events to occur. You'd have to make separated timers for each type of eventlist.

Here's an example on how it could be used to trigger werewolf transformations :

Code: Select all

define x = Character("FriendX")
define b = Character("FriendB")

label start:
    show screen PlayerInterface
    $FullMoon=False
    $FriendX="Human"
    $FriendB="Terrible friend"
    $eventlist_fullmoon=[]
    "Your friend X got bitten by a werewolf ! Ouch !"
    if FriendX !="Werewolf":
        $eventlist_fullmoon.append("FriendX_WerewolfTransfo")
    "Some other stuff happen"
    "Oh no, friend B got bitten too !"
    if FriendB !="Werewolf":
        $eventlist_fullmoon.append("FriendB_WerewolfTransfo")

    $bookmark="Day2"
    show screen PlayerInterface
    pause 2
label Day2:
    show screen PlayerInterface
    "The adventure continues."
    "..."
    "It's the night already ! Oh look at this beautiful full moon !"
    "I sure hope nothing happens..."
    $bookmark="Night2"
label Night2:
    show screen PlayerInterface
    $FullMoon=True
    "What a terrible night to have a curse..."

    return
screen PlayerInterface:
    if eventlist_fullmoon and FullMoon ==True: #Checks if any werewolves feel like transforming.
        timer 0.01 action[Hide("PlayerInterface"), Jump("FullMoon")]
    textbutton "you get the whole idea"
label FullMoon:
    if "FriendX_WerewolfTransfo" in eventlist_fullmoon and FullMoon==True and FriendX !="Werewolf":
        x "Oh no, I change into a werewolf for the first time ! My name is Friend X !"
        $FriendX="Werewolf"

    if "FriendB_WerewolfTransfo" in eventlist_fullmoon and FullMoon==True and FriendB !="Werewolf":
        b "Oh no, I change into a werewolf for the first time ! My name is Friend X ! I mean B !"
        $FriendB="Werewolf" #FriendB is still an aweful friend, but for the sake of simplicity, let's not create a class system with levels of friendships, yet.

    $eventlist_fullmoon=[] #Just in case you're already a werewolf or got bitten several times.
    $renpy.jump("".join([bookmark]))

Post Reply

Who is online

Users browsing this forum: Google [Bot]