Extracting events from a list and launching them with an image button

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
kamisama_nuno
Newbie
Posts: 6
Joined: Mon Oct 04, 2021 10:58 am
Contact:

Extracting events from a list and launching them with an image button

#1 Post by kamisama_nuno » Wed Oct 13, 2021 9:31 am

イラスト.png
The event screen I have in mind is as shown in the image, with the event name and the character related to the event being displayed when the event is in a state where the player can move around.
My goal is to avoid confusing the player by displaying the event name and character, since I don't fix the character for each location in the event for the sake of the scenario.
Anyway, I tried to make just the rooftop event, but it doesn't work at all. I've tried referring to various sources, but since I'm a programming beginner, I'm stuck and in trouble.
I'd like to create a list, set event priorities, filter out those that aren't available, and sort the list in order of highest to lowest, but it doesn't work: ......It will say expected statement.
I'm sure this poor program alone is full of mistakes, but I haven't quite incorporated what I want to do yet.

Code: Select all

default roof_eventname = "[r_events.name]"


init 100:
    new_roof_events = [e for e in roof_events if e.displays()]
    new_roof_events.sort(key=lambda i : i.priority)

screen roof_event_button():
    fixed:
        imagebutton:
            idle "roof_idle.png"
            hover "roof_hover.png"
            xpos 82
            ypos 77
            action [Play("sound", "audio/kati.mp3"),Jump("[r_events.labelname]")]
        text roof_eventname xpos 82 ypos 120



    $ r_events = [new_roof_events[0]]

init python:
    import renpy.store as store
    import renpy.exports as renpy

    class Evnt_roof (store.object):
        roof_events = [ ]



        def __init__(self, name, labelname, available = False, completed = False, priority = 100):
            self.name = name
            self.labelname = labelname
            self.available = available
            self.completed = completed
            self.priority = priority
            self.roof_events.append(self)


        def displays(self):
            if self.available and not(self.completed):
                return True
            return False

default event_roof_1 = Evnt_roof("屋上イベントA", "roof_1", True, False, priority = 120)
default event_roof_2 = Evnt_roof("屋上イベントB", "roof_2", True, False, priority = 110)
default event_roof_3 = Evnt_roof("屋上イベントC", "roof_3", True, False, priority = 130)
default event_roof_4 = Evnt_roof("屋上イベントa", "roof_z_1", True, False)

label roof_1:

    "テスト。"

    "これは屋上一個目のイベントです。"

    jump start

label roof_2:

    "テスト。"

    "これは屋上2個目のイベントです。"

    jump start

label roof_3:

    "テスト。"

    "これは屋上3個目のイベントです。何度も表示されるはず。"

    jump start

label roof_z_1:

    "テスト"

    "これは屋上イベント汎用。何度も表示されるはず。"

    jump start

label start:
    show screen roof_event_button

    "lllllllllllllllllllllll"

    return

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/kyuzitu-event.rpy", line 5: expected statement.
    new_roof_events = [e for e in roof_events if e.displays()]
                    ^

File "game/kyuzitu-event.rpy", line 6: expected statement.
    new_roof_events.sort(key=lambda i : i.priority)
                                                   ^

Ren'Py Version: Ren'Py 7.4.5.1648
Wed Oct 13 21:53:34 2021

(1) Events will be triggered according to the likability and flag .
I think unlocking the events in order itself can be done by setting the initial available to false and changing it to true when the event is over,
but how do I set up things like character a needing 50 sensitivity or a special flag for event C in this way? To begin with, is the way this program is set up unsuitable for such a setup?

(2)Change the button display depending on the character appearing in the event.
I'm thinking of setting up a character for each event, and setting up an image for each with an if statement from the screen, but is that difficult?
I'm sure this program is full of mistakes, and I'm very sorry.

Code: Select all

        def __init__(self, name, labelname, charactername,…):
            self.name = name
            self.labelname = labelname
            self.charactername = charactername 
            …           

Code: Select all

screen roof_event_button():
    fixed:
    if self.charactername == "a":
            imagebutton:
                auto "a_%s.png" action [Play("sound", "audio/kati.mp3"),Jump("[r_events.labelname]")]

    elif self.charactername == "b" :
                imagebutton:
                    auto "b_%s.png" action [Play("sound", "audio/kati.mp3"),Jump("[r_events.labelname]")]
                    
                    ……
       text roof_eventname xpos 82 ypos 120   

I would like to know if there is a better way to do this.
I am a beginner in programming and English is not my first language. I'm sorry.

OldGoateye
Newbie
Posts: 14
Joined: Fri Oct 09, 2015 4:31 am
Contact:

Re: Extracting events from a list and launching them with an image button

#2 Post by OldGoateye » Mon Oct 25, 2021 4:19 pm

Since I hate seeing questions go unanswered, I'm going to try to take a stab at this. I'm also a beginner, almost certainly worse than you.
And I also struggle with english, I will try to keep this short, and hopefully easy to follow.

I. Event Priority

Am I right in saying: You want to have character events that respond to what the character thinks of you. I think the code you're using might be too complex! Let's see if a simpler solution works.

Code: Select all

$ test_likability = 100 # this for a character who's neutral feelings are 100. Below that will fire negative events. Above that will fire positive events.


label roof_1: # you can get here through any button or jump condition

if test_likability == 100: 
    jump roof_1_neutral # you don't have to use jumps; here's an alternate version
# if test_likability == 100:
    #testcharacter "I don't know you that well. {w}Want to each lunch?" # This avoids jumps. A lot of programmers don't like them. I don't agree! But here's how.
    
# what if we want to make priority without using priority though?

if test_likability == 120 and testcharacter_good1 == False:
    jump roof_1_happy
    
roof_1_happy:
   testcharacter "Hello, my friend! {w}It's good to see you. {w}Let's go get crepes!"
   $ testcharacter_good1 # this can be used to prevent the event from firing once it's been seen, or lower it from the list.

else #you can use elif [else if] to add lots of options. make sure else is the last one.]
    jump roof_1_standard
    
roof_1_standard:
    testcharacter "Just another day. {w}Yesterday was nice. {w}Tomorrow will be nice, too."
That's ONE way of going about it. It may not work perfectly for you.

But you should be able to get there from the kind of buttons you're already using!
Now, part two...

II. Character Buttons

Am I right in saying: You want to have the buttons change, depending on a character in the event?

Well, here's how I'd do that.

Code: Select all

screen roof_event_button(): # define your buttons like this. also copy with screen_roof_event_testcharacter, for example
    fixed:
        imagebutton:
            idle "roof_idle.png" 
            hover "roof_hover.png"
            xpos 82
            ypos 77
            action [Play("sound", "audio/kati.mp3"),Jump("[r_events.labelname]")]
        text roof_eventname xpos 82 ypos 120
        
screen roof_event_testcharacter(): # for when testcharacter is eating lunch on the roof
    fixed:
        imagebutton:
            idle "roof_idle.png" 
            hover "roof_hover_testcharacterwave.png"
            xpos 82
            ypos 77
            action [Play("sound", "audio/kati.mp3"),Jump("[r_events.labelname]")]
        text roof_eventname xpos 82 ypos 120

Code: Select all

# define who is on the roof at some point. if it's noon and noon is when testcharacter is there, at noon $ testroof

r_events:

if testroof == True:
    jump testroofevents

elif childhoodfriendroof == True:
    jump childhoodfriendroofevents

elif rivalroof == True:
    jump rivalroofevents

else: # this is used when nobody is on the roof and player wants to rest
    jump emptyroofevents
These are potentially simpler ways to do what you want to do. Maybe not as complex, but I think they should work. I hope they help you. Don't give up because people don't help you; sometimes that's just how it is. I hope you can keep making games.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]