[SOLVED] Automated "reaction" (such as an image appearing) when changing a specific condition?

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
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

[SOLVED] Automated "reaction" (such as an image appearing) when changing a specific condition?

#1 Post by MoonByte » Fri May 21, 2021 12:44 pm

I have genuinely no idea if it is possible, so getting told "nope, sorry", is obviously absolutely fine.

I am making a dating sim and during each meeting with a character, the player gets a total of up to 20 options that increase or decrease their relationship meter.
Most Dating Sims make that a trial & error thing OR are super obvious about it with the choices themselves (Ladykiller in a Binder) OR at least tell you what a choice does if you finished the game once (Coming Out On Top).

My personal idea is that if I add something to a set condition, for x seconds a image appears (maybe a heart) and if something is subtracted from a condition, for x seconds a different image appears (broken heart). Like, the choice itself doesn't explain what it does to the stat, but once a player clicks on "How are you?", the image tells them instantly if the character liked or disliked that.

Now I COULD do that...by hand...for all 8 characters, in all 5 chapters where each character is met 4 times, each time with their ~20 options...........
And as stated at the start, I will if that is my only option.
But ideally, maybe there is some script that I can throw in somewhere that automatically reacts to me doing an

Code: Select all

$ clara_friendship += 1
and the second that + is there, it's like "alright, heart image for 5 seconds at position x!"

I know that in RPG Maker XP I can have such a thing happen with so-called parallel processes, but I genuinely have no clue if Renpy has something like that and how they'd work. Like, an automated

Code: Select all

if clara_friendship [whatever would tell the code that it's number has increased]:
	show heart at right
	time 2.0
	hide heart
or something like that.
Last edited by MoonByte on Sat May 22, 2021 12:11 pm, edited 3 times in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#2 Post by Alex » Fri May 21, 2021 1:21 pm

You could try to do it like

Code: Select all

init python:
    def my_func(txt, pos, t=2.0):
        renpy.show_screen("test_scr", my_txt=txt, txt_pos=pos, t=t)
        
    def check_func():
        global a, b, a_old, b_old
        if a > a_old:
            my_func("< a is up >", (0.5, 0.3), 0.5)
        elif a < a_old:
            my_func("< a is down >", (0.5, 0.3), 0.5)
        if b > b_old:
            my_func("< b is up >", (0.5, 0.3), 0.5)
        if b < b_old:
            my_func("< b is down >", (0.5, 0.3), 0.5)
            
        a_old = a
        b_old = b
    
    config.python_callbacks.append(check_func)

transform my_transform(t=2.0):
    alpha 0.0
    linear t alpha 1.0 yoffset -50
    
screen test_scr(my_txt, txt_pos, t):
    text my_txt size 50 align txt_pos at my_transform(t)
    timer t action Hide("test_scr")

default a = 0
default b = 0
default a_old = 0
default b_old = 0

# The game starts here.
label start:
    "..."
    $ a += 1
    "... ..."
    $ b -= 1
    "?!"
    
    menu:
        "Choice 1":
            $ my_func("< OK >", (0.5, 0.3), 0.5)
            "Ok"
        "Choice 2":
            $ my_func("< NO >", (0.5, 0.3))
            "No..."
    "?!"
https://www.renpy.org/doc/html/config.h ... _callbacks

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#3 Post by MoonByte » Fri May 21, 2021 1:58 pm

Ok, so it def works automatically and also much thanks for the callback link!
Now I guess I have to show my "starter with programming" card and confess:

how do I make it an image instead of text cause when I simply exchange the "< a is up >" with "heart.png", it just says that as text on the screen.
And exchanging the text at the start of text my_txt size 50 align txt_pos at my_transform(t) with image just breaks the entire thing.
I looked over the Displayables page and the Displaying Images page, but nothing there looked like your script and what was described in them also didn't sound like anything I could use (I think).

Like, there's multiple "text" and "txt" in your code and I am unsure which of these to change into what so that I can have the heart.png show up instead of text.
Sorry if it should be glaringly obvious v_v"

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#4 Post by Alex » Fri May 21, 2021 2:51 pm

MoonByte wrote:
Fri May 21, 2021 1:58 pm
...Like, there's multiple "text" and "txt" in your code and I am unsure which of these to change into what so that I can have the heart.png show up instead of text. ...
Ah, ok then some useful links:
https://www.renpy.org/doc/html/screens.html#add
https://www.renpy.org/doc/html/screens.html#timer
https://www.renpy.org/doc/html/screens.html

https://www.renpy.org/doc/html/screen_actions.html

https://www.renpy.org/doc/html/atl.html

https://www.renpy.org/doc/html/screen_p ... how_screen


With image it will look like

Code: Select all

screen test_scr(my_txt, txt_pos, t):
    add my_txt size 50 align txt_pos at my_transform(t)
    timer t action Hide("test_scr")
All those 'txt', 'my_txt', etc. are variables, so you could give them more apropriate names.

The thing works like:
- test_scr screen is used to show the things you need onscreen. It has several parameters (you can add more if needed). And you need to pass values for all those parameters when you want to show this screen.
- check_func is running my_func with some values (in parenteses you should specify properties that is used in this function and their values; if you won't specify the value for 't' it'll have the default value 2.0).
- my_func is showing a screen test_scr with some values (the screen parameters are receive the values of my_func properties).

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#5 Post by MoonByte » Fri May 21, 2021 4:54 pm

Ok, it is technically solved as it shows the pictures how I want them so I promise this is my last ask for this :'3

So I have this:

Code: Select all

init python:
    def my_func(txt, pos, t=4.0):
        renpy.show_screen("test_scr", my_txt=txt, txt_pos=pos, t=t)

    def check_func():
        global a, b, a_old, b_old
        if a > a_old:
            my_func("red_up.png", (0.8, 0.6), 0.5)
        elif a < a_old:
            my_func("red_down.png", (0.8, 0.6), 0.5)
        if b > b_old:
            my_func("green_up.png", (0.8, 0.6), 0.5)
        if b < b_old:
            my_func("green_down.png", (0.8, 0.6), 0.5)

        a_old = a
        b_old = b

    config.python_callbacks.append(check_func)

transform my_transform(t=4.0):
    alpha 0.0
    linear t alpha 1.0 yoffset -50

screen test_scr(my_txt, txt_pos, t):
    add my_txt align txt_pos
    timer t action Hide("test_scr")

default a = 0
default b = 0
default a_old = 0
default b_old = 0
The image just blinks in and out.
Where would I have to put a "with dissolve" or "Dissolve(0.5)" or whatever to make it fade out?
I tried in the my_func("whatever") row, I tried where Hide is (apparently you can't dissolve a screen, considering that nothing happened at all lol),but they all just either returned errors or the image just didn't disappear at all.

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#6 Post by emz911 » Fri May 21, 2021 5:05 pm

Code: Select all

action Hide("test_scr", dissolve)
Should work!

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#7 Post by MoonByte » Fri May 21, 2021 5:14 pm

That did it!
I always kept the 0.5 in it, so it never worked out.
Thanks, you two!

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#8 Post by MoonByte » Sat May 22, 2021 9:37 am

Ok, this is getting embarrassing for me now lol

It worked just fine in my test game with just a and b as variables
So I went and put the ACTUAL variables in for all my characters (warning, obviously long list of stuff):

Code: Select all

init python:
    def my_func(txt, pos, t=4.0):
        renpy.show_screen("test_scr", my_txt=txt, txt_pos=pos, t=t)

    def check_func():
        global whitney, whitney_old, whitneyrom, whitneyrom_old, edward, edward_old, edwardrom, edwardrom_old, zarah, zarah_old, zarahrom, zarahrom_old, trevor, trevor_old, chris, chris_old, chrisrom, chrisrom_old, birk, birk_old, birkrom, birkrom_old, amanda, amanda_old, amandarom, amandarom_old, john, john_old
        if whitney > whitney_old:
            my_func("whit_up.png", (0.9, 0.65), 0.5)
        if whitney < whitney_old:
            my_func("whit_down.png", (0.9, 0.65), 0.5)
        if whitneyrom > whitneyrom_old:
            my_func("whitrom_up.png", (0.9, 0.65), 0.5)
        if whitneyrom < whitneyrom_old:
            my_func("whitrom_down.png", (0.9, 0.65), 0.5)
        if edward > edward_old:
            my_func("ed_up.png", (0.9, 0.65), 0.5)
        if edward < edward_old:
            my_func("ed_down.png", (0.9, 0.65), 0.5)
        if edwardrom > edwardrom_old:
            my_func("edrom_up.png", (0.9, 0.65), 0.5)
        if edwardrom < edwardrom_old:
            my_func("edrom_down.png", (0.9, 0.65), 0.5)
        if zarah > zarah_old:
            my_func("zarah_up.png", (0.9, 0.65), 0.5)
        if zarah < zarah_old:
            my_func("zarah_down.png", (0.9, 0.65), 0.5)
        if zarahrom > zarahrom_old:
            my_func("zarahrom_up.png", (0.9, 0.65), 0.5)
        if zarahrom < zarahrom_old:
            my_func("zarahrom_down.png", (0.9, 0.65), 0.5)
        if trevor > trevor_old:
            my_func("trevor_up.png", (0.9, 0.65), 0.5)
        if trevor < trevor_old:
            my_func("trevor_down.png", (0.9, 0.65), 0.5)
        if chris > chris_old:
            my_func("chris_up.png", (0.9, 0.65), 0.5)
        if chris < chris_old:
            my_func("chris_down.png", (0.9, 0.65), 0.5)
        if chrisrom > chrisrom_old:
            my_func("chrisrom_up.png", (0.9, 0.65), 0.5)
        if chrisrom < chrisrom_old:
            my_func("chrisrom_down.png", (0.9, 0.65), 0.5)
        if birk > birk_old:
            my_func("birk_up.png", (0.9, 0.65), 0.5)
        if birk < birk_old:
            my_func("birk_down.png", (0.9, 0.65), 0.5)
        if birkrom > birkrom_old:
            my_func("birkrom_up.png", (0.9, 0.65), 0.5)
        if birkrom < birkrom_old:
            my_func("birkrom_down.png", (0.9, 0.65), 0.5)
        if john > john_old:
            my_func("john_up.png", (0.9, 0.65), 0.5)
        if john < john_old:
            my_func("john_down.png", (0.9, 0.65), 0.5)
        if amanda > amanda_old:
            my_func("amanda_up.png", (0.9, 0.65), 0.5)
        if amanda < amanda_old:
            my_func("amanda_down.png", (0.9, 0.65), 0.5)
        if amandarom > amandarom_old:
            my_func("amandarom_up.png", (0.9, 0.65), 0.5)
        if amandarom < amandarom_old:
            my_func("amandarom_down.png", (0.9, 0.65), 0.5)


        whitney_old = whitney
        whitneyrom_old = whitneyrom
        edward_old = edward
        edwardrom_old = edwardrom
        zarah_old = zarah
        zarahrom_old = zarahrom
        trevor_old = trevor
        chris_old = chris
        chrisrom_old = chrisrom
        birk_old = birk
        birkrom_old = birkrom
        john_old = john
        amanda_old = amanda
        amandarom_old = amandarom



    config.python_callbacks.append(check_func)

transform my_transform(t=4.0):
    alpha 0.0
    linear t alpha 1.0 yoffset -50

screen test_scr(my_txt, txt_pos, t):
    add my_txt align txt_pos
    timer 2.0 action Hide("test_scr", dissolve)

default whitney = 0
default whitney_old = 0
default whitneyrom = 0
default whitneyrom_old = 0
default edward = 0
default edward_old = 0
default edwardrom = 0
default edwardrom_old = 0
default zarah = 0
default zarah_old = 0
default zarahrom = 0
default zarahrom_old = 0
default trevor = 0
default trevor_old = 0


default chris = 0
default chris_old = 0
default chrisrom = 0
default chrisrom_old = 0
default birk = 0
default birk_old = 0
default birkrom = 0
default birkrom_old = 0
default amanda = 0
default amanda_old = 0
default amandarom = 0
default amandarom_old = 0
default john = 0
default john_old = 0
And now I just get errors that the names are not defined?
Like, right now it says that "if whitney > whitney_old:" is the problem, before that it was chris and once birk.
But they ARE defined??
And I don't see any typos or anything either (I literally checked each by using strg+F, all should be correct).
Did I put the value definitions at a wrong spot? (but in the test it worked just fine right there)
Is there some sort of character limit and my variable names are somehow too long to work out?
Does that script only accept x global names and I overloaded it?

Like, what is this error trying to tell me here?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00start.rpy", line 190, in script
    python:
  File "game/script.rpy", line 31, in check_func
    if whitney > whitney_old:
NameError: global name 'whitney' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/00start.rpy", line 190, in script
    python:
  File "renpy/ast.py", line 927, in execute
    i()
  File "game/script.rpy", line 31, in check_func
    if whitney > whitney_old:
NameError: global name 'whitney' is not defined

Windows-10-10.0.19041
Ren'Py 7.4.4.1439
Graphic Test 1.0
Sat May 22 15:32:30 2021

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#9 Post by Alex » Sat May 22, 2021 11:30 am

Did you start a new game or restore from save?
Try to start new game.

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Automated "reaction" (such as an image appearing) when changing a specific condition?

#10 Post by MoonByte » Sat May 22, 2021 12:10 pm

I copy & pasted the code into a brand new project and it indeed works without any complaints...
Trying to launch my project with the error only causes an error before I even reach the start screen.
So I guess, it is indeed an issue in that project. I will just save all the important code separately and compile them together one at a time (so I see when something causes an problem and can fix it...or it just works and I am happy).
Sorry for the panic, the error seemed so specific to this that I thought I misunderstood something about the code again and had done an obvious error.

Post Reply

Who is online

Users browsing this forum: mold.FF