Ren'Py Triggering more than one event and other stuff(resolved)

blapper21

Newbie
Game Developer
Oct 8, 2021
81
160
OK, i have another question if I can manage it without pissing anyone off.

The event trigger seems to be working great but when I try to do an animation in my game_scenes script its displaying the menu from the script over the top of it, I've tried all kinds to get it to stop doing it. Like using "scene onlayer overlay", moving it to a separate screen file, which was even worse, asked ChapGPT etc

I suspect its the while loop for the menu "change location" "Open Map" in the script but as Im not overly familiar with Renpy compared to C# I dont know the best way to deal with it.


Python:
label start_game:
    call variables
    $ GameRunning = True
    while GameRunning:
        $ Location_img = Location.lower()
        if renpy.has_image(Location.lower(), exact=True):
            show expression Location_img
        menu:
            "I am at [Location]"
            "change location":
                $ Location = "bed"
            "Open Map":
                $ Location = renpy.call_screen("MapScreen", _layer="screens")

                $ BlockToCall = ""
        python:

            for event in EVENTS:

                if event.date_check(LocationID, calendar.Hours, calendar.Day):


                    BlockToCall = event.Block

        if BlockToCall != "":

            call expression BlockToCall

label variables:
    $ calendar = Calendar(0, 0, 0, 0, ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],0)
    $ EVENTS[0] = Event(2, 12, 0, "EvOne", True)
    $ EVENTS[1] = Event(2, 12, 1, "EvTwo", True)

    
    return
Python:
label EvTwo:
    show soldier
    soldier "blah"
    
    $ EVENTS[1].SetInactive()
    menu:
        "1":
            jump 1
        "Don't":
            "You spend a day in jail."
            $ calendar.AddTime(24)

label 1:
    show soldier
    
    
    image animation_loop_sp:
        "soldier4"
        pause 0.2
        "soldier5"
        pause 0.2
        repeat(5)

    
        show animation_loop_sp
        
    
    return
Python:
init python:
    # Define the Calendar class
    class Calendar(object):
        def __init__(self, Hours, Hour, Days, Day, WeekDays, PlaceID):  # Add PlaceID attribute
            self.Hour = Hour
            self.Hours = Hours
            self.Days = Days
            self.Day = Day
            self.WeekDays = WeekDays
            self.PlaceID = PlaceID  # Assign PlaceID
          
        @property
        def Output(self):           
            return self.WeekDays[self.Day] + " " + str(self.Days+1) + " " + str(self.Hours).zfill(2) + ":" + "00"
      
        def AddTime(self, hours):
            self.Hours += hours
            if self.Hours > 23:
                self.Hours %= 24
                self.Day += 1
                self.Days += 1
            if self.Day > 6:
                self.Day = 0
 
    # Create an instance of the Calendar class with a default PlaceID

    class Event(object):
        def __init__(self, LocationID, Hours, Day, Block, IsActive):
            self.LocationID = LocationID
            self.Hours = Hours
            self.Day = Day
            self.Block = Block
            self.IsActive = IsActive
            
        def date_check(self, current_location, current_hour, current_day):
            print("Checking event:", self.Block)
            print("Event hour:", self.Hours)
            print("Event day:", self.Day)
            print("Event location:", self.LocationID)

            print("Current hour:", current_hour)
            print("Current day:", current_day)
            print("Current location:", current_location)# Check if the event is active, it's the specified hour, and the player is at the specified location
            if self.IsActive and self.Hours == current_hour and self.LocationID == current_location and self.Day == current_day:
                print("Event triggered!")
                return True
            else:
                print("Event not triggered.")
                return False

        def SetInactive(self):
            self.IsActive = False

    # Define the Place class
    class Place(object):
        def __init__(self, ID, x, y, name, IsActive):
            self.ID = ID
            self.x = x
            self.y = y
            self.name = name
            self.IsActive = IsActive
          
        @property
        def avatar(self):
            icon = "icons/" + self.name.lower() + "_icon.png"
            return(icon)
                
        
    # Initialize lists for events, places, and sub-locations
    EVENTS = []
    Places = []

    # Create placeholder instances for events, places, and sub-locations
    t = 0
    while t < 50:
        EVENTS.append(Event(0, 0, 0, "", False))
        Places.append(Place(0, 0, 0, "", False))
        t += 1
 
    # Define specific places and sub-locations
    Places[0] = Place(0, 1000, 600, "Home", True)
    Places[1] = Place(1, 200, 700, "Bedroom", True)
    Places[2] = Place(2, 1200, 500, "Showers", True)
    #Places[3] = Place(3, 500,200, "Terminal", True)
Thanks in advance an apologies for pissing people off with my inexperience earlier.
 
Last edited:

peterppp

Member
Mar 5, 2020
458
864
Not sure if I've messed up indentation by putting all the code in spoiler tags.
not sure? i quick look says you did lol. insert as </> Code to preserve indentation.

since I don't want to spend time correcting the indentation, i haven't tested the code, so i may be wrong on the rest, but from what I can see, you can't even trigger EvOne with the code you have presented to us. here are the issues i see

1) $ calendar.AddTime(1) is commented.
2) locationID is never changed from -1
3) if event.date_check(LocationID, calendar.Hour): passes calendar.Hour, a value which is never changed. did you mean calendar.Hours? and i don't see the purpose of having both calendar.Hour and calendar.Hours.

i don't see anything wrong in the code where the hours are changed, but since it seems you haven't provided us with the code you say is working for EvOne (and you ruined the indentation) it may be wrong in the version you use
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,111
14,798
Wondering if anyone can help.
Not with what you shown.

As said by peterppp, the addTime method isn't called, so the time is increased by something else. This while the event trigger code rely on the current_hour and current_day variables, that are expected as arugments, but not passed.


Strictly speaking, based on the sole code that you included in your post, what is surprising is that EvOne is called, not that EvTwo isn't.
 

blapper21

Newbie
Game Developer
Oct 8, 2021
81
160
Not with what you shown.

As said by peterppp, the addTime method isn't called, so the time is increased by something else. This while the event trigger code rely on the current_hour and current_day variables, that are expected as arugments, but not passed.


Strictly speaking, based on the sole code that you included in your post, what is surprising is that EvOne is called, not that EvTwo isn't.
Hi apologies for that addTime is called in the map screen at the moment. The player presses a button which triggers it.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,111
14,798
Hi apologies for that addTime is called in the map screen at the moment. The player presses a button which triggers it.
What change nothing to the fact that you don't fully pass the arguments to the event trigger method, nor the fact that, like peterppp said, the one you pass isn't the one you should pass.

Accordingly to the code you shown, there's just no way for date_check to log a hour other than 0, since you call it with calendar.Hour, that is defined at 0 and never updated in the code you shown.

In fact, to be totally precise, there's just no way for that code to works.

You use event.date_check(LocationID, calendar.Hour) to call a method defined as def date_check(self, current_location, current_hour, current_day). There's one more argument expected, than the number of passed arguments. Python would highly dislike that and throw an exception that Ren'Py would show you.

Also, still accordingly to the code you shown, there's only one event that can be triggered before the game end. Therefore there's no way, at least on the code you shown, to get a couple hour/day that goes further than the one triggering the first event.

Python:
label start:
    [...]
    jump start_game   # <- a jump, so no entry added in the calling stack.

label start_game:
    [...]

    while GameRunning:
        [...]
        python:
            for event in EVENTS:
                if event.date_check(LocationID, calendar.Hour): # <- Here Ren'Py would throw an exception.
                    BlockToCall = event.Block
        if BlockToCall != "":
            call expression BlockToCall
            return   # <- You want to return to a point that do not exist.
                     # Ren'Py will end the game and return to the main menu.
I don't know what trigger the event you get from the console, but it's not the code in the "start_game" label. Like it's probably also not your add_time method that effectively update the time.
 

Quintillian

Newbie
Apr 15, 2019
94
196
blapper21 Please provide more code for context. The more code the better. AND please for the love of everything that exists, add code formatting to any examples. It takes minimum effort. Here is a quick clip showing how.

 

blapper21

Newbie
Game Developer
Oct 8, 2021
81
160
blapper21 Please provide more code for context. The more code the better. AND please for the love of everything that exists, add code formatting to any examples. It takes minimum effort. Here is a quick clip showing how.

show us the code that actually works with EvOne. and insert the code with </> Code this time
Sorry about this.
Script
Python:
## The setup code is added here.

default knowledge = 1

default charm = 2

default guts = 3

default kindness = 4

default proficiency = 5

default Location = "Home"

default LocationID = -1

$ GameRunning = False

label start:

    # set my_quests' values

    call create_my_quests

    show screen gameUI

    jump start_game



## start_game label was created to separate the initial setup from the game.

label start_game:

    call variables

    $ GameRunning = True

    while GameRunning:

        $ Location_img = Location.lower()

        if renpy.has_image(Location.lower(), exact=True):

            show expression Location_img

    



        menu:

            "I am at [Location]"

            "change location":

                $ Location = "bed"

            "Open Map":

                $ Location = renpy.call_screen("MapScreen", _layer="screens")

            "Visit sub-location":

                $ Location = renpy.call_screen("SubLockHud", _layer="screens")



        $ BlockToCall = ""

            

        #$ calendar.AddTime(1)   

    

        python:

            for event in EVENTS:

                if event.date_check(LocationID, calendar.Hour):

                    BlockToCall = event.Block

        if BlockToCall != "":

            call expression BlockToCall

            return





## This label will show a menu of choices if they "should show".

label tasks_choices:

    menu:

        "[quest_clean_room.name]" if quest_clean_room.should_show:

            $ quest_clean_room.completed = True

            jump cleaned_room



        "[quest_cook_breakfast.name]" if quest_cook_breakfast.should_show:

            $ quest_cook_breakfast.completed = True



            ## After cooking breakfast, the quest "Eat Breakfast" should be available.

            $ quest_eat_breakfast.available = True

            jump cooked_breakfast



        "[quest_eat_breakfast.name]" if quest_eat_breakfast.should_show:

            $ quest_eat_breakfast.completed = True

            jump ate_breakfast

        
[CODE=python]label EvOne:
    "blah1"
  
    $ EVENTS[0].SetInactive()  # Deactivate the event
    return

label EvTwo:
    "Blah2"
    $ EVENTS[1].SetInactive()  # Deactivate the event
    return


Classes
Python:
init python:
    # Define the Calendar class
    class Calendar(object):
        def __init__(self, Hours, Hour, Days, Day, WeekDays, PlaceID):  # Add PlaceID attribute
            self.Hour = Hour
            self.Hours = Hours
            self.Days = Days
            self.Day = Day
            self.WeekDays = WeekDays
            self.PlaceID = PlaceID  # Assign PlaceID
          
        @property
        def Output(self):           
            return self.WeekDays[self.Day] + " " + str(self.Days+1) + " " + str(self.Hours).zfill(2) + ":" + "00"
      
        def AddTime(self, hours):
            self.Hours += hours
            if self.Hours > 23:
                self.Hours %= 24
                self.Day += 1
                self.Days += 1
            if self.Day > 6:
                self.Day = 0
  
    # Create an instance of the Calendar class with a default PlaceID

    class Event(object):
        def __init__(self, LocationID, Hour, Day, Block, IsActive):
            self.LocationID = LocationID
            self.Hour = Hour
            self.Day = Day
            self.Block = Block
            self.IsActive = IsActive
          


        def date_check(self, current_location, current_hour, current_day):
            print("Checking event:", self.Block)
            print("Event hour:", self.Hour)
            print("Event day:", self.Day)
            print("Event location:", self.LocationID)

            print("Current hour:", current_hour)
            print("Current day:", current_day)
            print("Current location:", current_location)# Check if the event is active, it's the specified hour, and the player is at the specified location
            if self.IsActive and self.Hour == current_hour and self.LocationID == current_location and self.Day == current_day:
                print("Event triggered!")
                return True
            else:
                print("Event not triggered.")
                return False

        def SetInactive(self):
            self.IsActive = False

          


    # Define the Place class
    class Place(object):
        def __init__(self, ID, x, y, name, IsActive):
            self.ID = ID
            self.x = x
            self.y = y
            self.name = name
            self.IsActive = IsActive
          
        @property
        def avatar(self):
            icon = "icons/" + self.name.lower() + "_icon.png"
            return(icon)
                
        @property
        def rooms(self):
            outList = []
            for q in SubLocations:
                if q.parent == self.ID:
                    outList.append (q.ID)
            return outList

    # Define the SubPlace class
    class SubPlace(object):
        def __init__(self, ID, parent, name, isActive):
            self.ID = ID
            self.parent = parent
            self.name = name
            self.isActive = isActive
  
    # Initialize lists for events, places, and sub-locations
    EVENTS = []
    SubLocations = []
    Places = []

    # Create placeholder instances for events, places, and sub-locations
    t = 0
    while t < 50:
        EVENTS.append(Event(0, 0, 0, "", False))
        Places.append(Place(0, 0, 0, "", False))
        SubLocations.append(SubPlace(t, -1, "", False))
        t += 1
  
    # Define specific places and sub-locations
    Places[0] = Place(0, 1000, 600, "Home", True)
    Places[1] = Place(1, 200, 700, "Bedroom", True)
    Places[2] = Place(2, 1200, 500, "Showers", True)
    #Places[3] = Place(3, 500,200, "Terminal", True)


    # Iterate over events and check if they should be triggered
    # for event in EVENTS:
    #     if event.DateCheck(calendar):
    #         event.Block()
Python:
screen MapScreen():
    frame:
        xpos 0 ypos 0
        xminimum 1920
        yminimum 75
        ymaximum 75
        textbutton _("Wait 1-Hour"):
            action Function(calendar.AddTime, 1)
    frame:
        xalign 0.0
        yalign 0.0
        xsize 1980
        ysize 1080
        background "map.png"
        hbox:
            xpos 800 ypos 75
            textbutton _("Wait 1-Hour"):
                    action Function(calendar.AddTime, 1)
        for q in Places:
            hbox:
                xpos q.x
                ypos q.y
                if q.IsActive:
                    imagebutton:
                        yalign 0.5
                        hover q.avatar
                        idle q.avatar
                        action SetVariable("LocationID", q.ID), Return(q.name)
 
Last edited:

peterppp

Member
Mar 5, 2020
458
864
Sorry about this.
Script
Python:
## The setup code is added here.

default knowledge = 1

default charm = 2

default guts = 3

default kindness = 4

default proficiency = 5

default Location = "Home"

default LocationID = -1

$ GameRunning = False

label start:

    # set my_quests' values

    call create_my_quests

    show screen gameUI

    jump start_game



## start_game label was created to separate the initial setup from the game.

label start_game:

    call variables

    $ GameRunning = True

    while GameRunning:

        $ Location_img = Location.lower()

        if renpy.has_image(Location.lower(), exact=True):

            show expression Location_img

    



        menu:

            "I am at [Location]"

            "change location":

                $ Location = "bed"

            "Open Map":

                $ Location = renpy.call_screen("MapScreen", _layer="screens")

            "Visit sub-location":

                $ Location = renpy.call_screen("SubLockHud", _layer="screens")



        $ BlockToCall = ""

            

        #$ calendar.AddTime(1)   

    

        python:

            for event in EVENTS:

                if event.date_check(LocationID, calendar.Hour):

                    BlockToCall = event.Block

        if BlockToCall != "":

            call expression BlockToCall

            return





## This label will show a menu of choices if they "should show".

label tasks_choices:

    menu:

        "[quest_clean_room.name]" if quest_clean_room.should_show:

            $ quest_clean_room.completed = True

            jump cleaned_room



        "[quest_cook_breakfast.name]" if quest_cook_breakfast.should_show:

            $ quest_cook_breakfast.completed = True



            ## After cooking breakfast, the quest "Eat Breakfast" should be available.

            $ quest_eat_breakfast.available = True

            jump cooked_breakfast



        "[quest_eat_breakfast.name]" if quest_eat_breakfast.should_show:

            $ quest_eat_breakfast.completed = True

            jump ate_breakfast

        
[CODE=python]label EvOne:
    "blah1"
  
    $ EVENTS[0].SetInactive()  # Deactivate the event
    return

label EvTwo:
    "Blah2"
    $ EVENTS[1].SetInactive()  # Deactivate the event
    return


Classes
Python:
init python:
    # Define the Calendar class
    class Calendar(object):
        def __init__(self, Hours, Hour, Days, Day, WeekDays, PlaceID):  # Add PlaceID attribute
            self.Hour = Hour
            self.Hours = Hours
            self.Days = Days
            self.Day = Day
            self.WeekDays = WeekDays
            self.PlaceID = PlaceID  # Assign PlaceID
          
        @property
        def Output(self):           
            return self.WeekDays[self.Day] + " " + str(self.Days+1) + " " + str(self.Hours).zfill(2) + ":" + "00"
      
        def AddTime(self, hours):
            self.Hours += hours
            if self.Hours > 23:
                self.Hours %= 24
                self.Day += 1
                self.Days += 1
            if self.Day > 6:
                self.Day = 0
  
    # Create an instance of the Calendar class with a default PlaceID

    class Event(object):
        def __init__(self, LocationID, Hour, Day, Block, IsActive):
            self.LocationID = LocationID
            self.Hour = Hour
            self.Day = Day
            self.Block = Block
            self.IsActive = IsActive
          


        def date_check(self, current_location, current_hour, current_day):
            print("Checking event:", self.Block)
            print("Event hour:", self.Hour)
            print("Event day:", self.Day)
            print("Event location:", self.LocationID)

            print("Current hour:", current_hour)
            print("Current day:", current_day)
            print("Current location:", current_location)# Check if the event is active, it's the specified hour, and the player is at the specified location
            if self.IsActive and self.Hour == current_hour and self.LocationID == current_location and self.Day == current_day:
                print("Event triggered!")
                return True
            else:
                print("Event not triggered.")
                return False

        def SetInactive(self):
            self.IsActive = False

          


    # Define the Place class
    class Place(object):
        def __init__(self, ID, x, y, name, IsActive):
            self.ID = ID
            self.x = x
            self.y = y
            self.name = name
            self.IsActive = IsActive
          
        @property
        def avatar(self):
            icon = "icons/" + self.name.lower() + "_icon.png"
            return(icon)
                
        @property
        def rooms(self):
            outList = []
            for q in SubLocations:
                if q.parent == self.ID:
                    outList.append (q.ID)
            return outList

    # Define the SubPlace class
    class SubPlace(object):
        def __init__(self, ID, parent, name, isActive):
            self.ID = ID
            self.parent = parent
            self.name = name
            self.isActive = isActive
  
    # Initialize lists for events, places, and sub-locations
    EVENTS = []
    SubLocations = []
    Places = []

    # Create placeholder instances for events, places, and sub-locations
    t = 0
    while t < 50:
        EVENTS.append(Event(0, 0, 0, "", False))
        Places.append(Place(0, 0, 0, "", False))
        SubLocations.append(SubPlace(t, -1, "", False))
        t += 1
  
    # Define specific places and sub-locations
    Places[0] = Place(0, 1000, 600, "Home", True)
    Places[1] = Place(1, 200, 700, "Bedroom", True)
    Places[2] = Place(2, 1200, 500, "Showers", True)
    #Places[3] = Place(3, 500,200, "Terminal", True)


    # Iterate over events and check if they should be triggered
    # for event in EVENTS:
    #     if event.DateCheck(calendar):
    #         event.Block()
Python:
screen MapScreen():
    frame:
        xpos 0 ypos 0
        xminimum 1920
        yminimum 75
        ymaximum 75
        textbutton _("Wait 1-Hour"):
            action Function(calendar.AddTime, 1)
    frame:
        xalign 0.0
        yalign 0.0
        xsize 1980
        ysize 1080
        background "map.png"
        hbox:
            xpos 800 ypos 75
            textbutton _("Wait 1-Hour"):
                    action Function(calendar.AddTime, 1)
        for q in Places:
            hbox:
                xpos q.x
                ypos q.y
                if q.IsActive:
                    imagebutton:
                        yalign 0.5
                        hover q.avatar
                        idle q.avatar
                        action SetVariable("LocationID", q.ID), Return(q.name)
after fixing your faulty code (please post working code!), the time progression works fine, as seen in the screenshot.
test.png
no event is triggered because you don't check for that there. even if you did, you're still checking for calendar.Hour when it should be calendar.Hours. I also had to add the missing parameter Day (as you've also been told about)
 

blapper21

Newbie
Game Developer
Oct 8, 2021
81
160
after fixing your faulty code (please post working code!), the time progression works fine, as seen in the screenshot.
View attachment 3373887
no event is triggered because you don't check for that there. even if you did, you're still checking for calendar.Hour when it should be calendar.Hours. I also had to add the missing parameter Day (as you've also been told about)
Sorry, what did you change? I cant see any changes. Again, apologies in advance if I missed it.

It looks like i missed this off the script for you


Python:
label variables:
    $ calendar = Calendar(0, 0, 0, 0, ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],0)
    $ EVENTS[0] = Event(2, 12, 0, "EvOne", True)
    $ EVENTS[1] = Event(2, 12, 1, "EvTwo", True)

    
    return
 

peterppp

Member
Mar 5, 2020
458
864
Sorry, what did you change? I cant see any changes. Again, apologies in advance if I missed it.

It looks like i missed this off the script for you


Python:
label variables:
    $ calendar = Calendar(0, 0, 0, 0, ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],0)
    $ EVENTS[0] = Event(2, 12, 0, "EvOne", True)
    $ EVENTS[1] = Event(2, 12, 1, "EvTwo", True)

   
    return
i had to change several things, don't remember everything. code just doesn't work as you present it. had to comment out stuff that didn't exist, like call to create_my_quests, and yes adding the variables label (from your previous post)

for the time progression I didn't change anything. it works, but no event is triggered
 
  • Like
Reactions: blapper21

blapper21

Newbie
Game Developer
Oct 8, 2021
81
160
i had to change several things, don't remember everything. code just doesn't work as you present it. had to comment out stuff that didn't exist, like call to create_my_quests, and yes adding the variables label (from your previous post)

for the time progression I didn't change anything. it works, but no event is triggered
I think its working now based on the changes you made, I just need to find a way of making the calendar save its time as its resetting when I go to the menu or etc.

Thanks for your help!
 
  • Like
Reactions: peterppp

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,111
14,798
[...] I just need to find a way of making the calendar save its time as its resetting when I go to the menu or etc.
Oh god...

Well, at least it explain why you never seen the many errors in your "start_game" label... You make everything happen directly in the screen, without effectively returning from it at some point.

What also mean that the Ren'Py code you shown us is really totally useless, because 70% of it is never used, while the code that is effectively used is in the screen that you didn't shown.


Python:
label start_game:
[...]  
       menu:
           "I am at [Location]"

           "change location":
               # $ Location = "bed"
               $ LocationID =  1  # Or whatever is the ID for "bed".
           "Open Map":
               call screen MapScreen
           "Visit sub-location":
               call screen SubLockHud

       if _return == "advance time":
           $ calendar.AddTime(1)   
       else:
           $ LocationID = _return   # and not "Location" like in your code

       python:
           for event in EVENTS:
               if event.date_check(LocationID, calendar.Hours, calendar.Days):
                   call expression event.Block
                   break

screen MapScreen():

    textbutton "advance time":
        action Return( "advance time" )
    textbutton "bedroom":
        action Return( 1 )  # or whatever the LocationID is
    textbutton "living room":
        action Return( 2 )  # or whatever the LocationID is
    [...]
[/quote]
 

blapper21

Newbie
Game Developer
Oct 8, 2021
81
160
Oh god...

Well, at least it explain why you never seen the many errors in your "start_game" label... You make everything happen directly in the screen, without effectively returning from it at some point.

What also mean that the Ren'Py code you shown us is really totally useless, because 70% of it is never used, while the code that is effectively used is in the screen that you didn't shown.


Python:
label start_game:
[...] 
       menu:
           "I am at [Location]"

           "change location":
               # $ Location = "bed"
               $ LocationID =  1  # Or whatever is the ID for "bed".
           "Open Map":
               call screen MapScreen
           "Visit sub-location":
               call screen SubLockHud

       if _return == "advance time":
           $ calendar.AddTime(1)  
       else:
           $ LocationID = _return   # and not "Location" like in your code

       python:
           for event in EVENTS:
               if event.date_check(LocationID, calendar.Hours, calendar.Days):
                   call expression event.Block
                   break

screen MapScreen():

    textbutton "advance time":
        action Return( "advance time" )
    textbutton "bedroom":
        action Return( 1 )  # or whatever the LocationID is
    textbutton "living room":
        action Return( 2 )  # or whatever the LocationID is
    [...]
[/quote]
I've resolved it now but thank you :)
 

blapper21

Newbie
Game Developer
Oct 8, 2021
81
160
OK, i have another question if I can manage it without pissing anyone off.

The event trigger seems to be working great but when I try to do an animation in my game_scenes script its displaying the menu from the script over the top of it, I've tried all kinds to get it to stop doing it. Like using "scene onlayer overlay", moving it to a separate screen file, which was even worse, asked ChapGPT etc

I suspect its the while loop for the menu "change location" "Open Map" in the script but as Im not overly familiar with Renpy compared to C# I dont know the best way to deal with it.


Python:
label start_game:
    call variables
    $ GameRunning = True
    while GameRunning:
        $ Location_img = Location.lower()
        if renpy.has_image(Location.lower(), exact=True):
            show expression Location_img
        menu:
            "I am at [Location]"
            "change location":
                $ Location = "bed"
            "Open Map":
                $ Location = renpy.call_screen("MapScreen", _layer="screens")

                $ BlockToCall = ""
        python:

            for event in EVENTS:

                if event.date_check(LocationID, calendar.Hours, calendar.Day):


                    BlockToCall = event.Block

        if BlockToCall != "":

            call expression BlockToCall

label variables:
    $ calendar = Calendar(0, 0, 0, 0, ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],0)
    $ EVENTS[0] = Event(2, 12, 0, "EvOne", True)
    $ EVENTS[1] = Event(2, 12, 1, "EvTwo", True)

    
    return
Python:
label EvTwo:
    show soldier
    soldier "blah"
    
    $ EVENTS[1].SetInactive()
    menu:
        "1":
            jump 1
        "Don't":
            "You spend a day in jail."
            $ calendar.AddTime(24)

label 1:
    show soldier
    
    
    image animation_loop_sp:
        "soldier4"
        pause 0.2
        "soldier5"
        pause 0.2
        repeat(5)

    
        show animation_loop_sp
        
    
    return
Python:
init python:
    # Define the Calendar class
    class Calendar(object):
        def __init__(self, Hours, Hour, Days, Day, WeekDays, PlaceID):  # Add PlaceID attribute
            self.Hour = Hour
            self.Hours = Hours
            self.Days = Days
            self.Day = Day
            self.WeekDays = WeekDays
            self.PlaceID = PlaceID  # Assign PlaceID
          
        @property
        def Output(self):           
            return self.WeekDays[self.Day] + " " + str(self.Days+1) + " " + str(self.Hours).zfill(2) + ":" + "00"
      
        def AddTime(self, hours):
            self.Hours += hours
            if self.Hours > 23:
                self.Hours %= 24
                self.Day += 1
                self.Days += 1
            if self.Day > 6:
                self.Day = 0
 
    # Create an instance of the Calendar class with a default PlaceID

    class Event(object):
        def __init__(self, LocationID, Hours, Day, Block, IsActive):
            self.LocationID = LocationID
            self.Hours = Hours
            self.Day = Day
            self.Block = Block
            self.IsActive = IsActive
            
        def date_check(self, current_location, current_hour, current_day):
            print("Checking event:", self.Block)
            print("Event hour:", self.Hours)
            print("Event day:", self.Day)
            print("Event location:", self.LocationID)

            print("Current hour:", current_hour)
            print("Current day:", current_day)
            print("Current location:", current_location)# Check if the event is active, it's the specified hour, and the player is at the specified location
            if self.IsActive and self.Hours == current_hour and self.LocationID == current_location and self.Day == current_day:
                print("Event triggered!")
                return True
            else:
                print("Event not triggered.")
                return False

        def SetInactive(self):
            self.IsActive = False

    # Define the Place class
    class Place(object):
        def __init__(self, ID, x, y, name, IsActive):
            self.ID = ID
            self.x = x
            self.y = y
            self.name = name
            self.IsActive = IsActive
          
        @property
        def avatar(self):
            icon = "icons/" + self.name.lower() + "_icon.png"
            return(icon)
                
        
    # Initialize lists for events, places, and sub-locations
    EVENTS = []
    Places = []

    # Create placeholder instances for events, places, and sub-locations
    t = 0
    while t < 50:
        EVENTS.append(Event(0, 0, 0, "", False))
        Places.append(Place(0, 0, 0, "", False))
        t += 1
 
    # Define specific places and sub-locations
    Places[0] = Place(0, 1000, 600, "Home", True)
    Places[1] = Place(1, 200, 700, "Bedroom", True)
    Places[2] = Place(2, 1200, 500, "Showers", True)
    #Places[3] = Place(3, 500,200, "Terminal", True)
Thanks in advance an apologies for pissing people off with my inexperience earlier.
 

gojira667

Member
Sep 9, 2019
252
229
... asked ChapGPT etc

I suspect its the while loop for the menu "change location" "Open Map" in the script but as Im not overly familiar with Renpy compared to C# I dont know the best way to deal with it.
:unsure: C# sharp influence or the ChatGPT?

You should take a closer look at AON's post. In yours the last event to block "wins" BlockToCall.

label 1... OK.

Outside of Screens, Ren'Py waits until there is an interaction to blit to the screen, generally. There aren't any interactions between show animation_loop_sp and the "I am at [Location]" menu. Add one, e.g. pause 2.1.
 
  • Like
Reactions: blapper21