Value in list not changing in loop

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
jwideman
Newbie
Posts: 14
Joined: Tue Jul 30, 2019 7:17 pm
Contact:

Value in list not changing in loop

#1 Post by jwideman » Sat Jun 20, 2020 4:08 pm

First of all, I really wish renpy had better debugging tools. This has been kicking my ass for 3 days and I'm still struggling to figure out where my code is failing. Anyway...

Code: Select all

    class Events(renpy.store.object):
        def __init__(self):
            self.eventlist = []

        def get(self):
            return self.eventlist

        def add(self,x):
            for event in self.eventlist:
                if x.name == event.name:
                    return
            self.eventlist.append(x)

        def remove(self,x):
            for i,event in enumerate(self.eventlist):
                if x.name == event.name:
                    self.eventlist[i].disabled = True

        def readd(self,x):
            for i,event in enumerate(self.eventlist):
                if x.name == event.name:
                    self.eventlist[i].disabled = False

        def loop(self):
            disable = False
            for i,event in enumerate(self.eventlist):
                if not event.disabled:
                    event_conditions = 0    #the total number of conditions for the event
                    event_met = 0    #the number of conditions met
                    if event.location:
                        event_conditions += 1
                        if event.location == locstring:
                            event_met += 1
                    if event.day:
                        event_conditions += 1
                        if event.day == day:
                            event_met += 1
                    if event.time:
                        event_conditions += 1
                        if event.time == time_of_day:
                            event_met += 1
                    if event_met and event_met == event_conditions:
                        if event.auto:
                            renpy.call(event.name)
                        else:
                            itemlist.add(event.item)
                        self.eventlist[i].disabled = True

For some reason unknown to me, that last line does nothing.

strayerror
Regular
Posts: 154
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Value in list not changing in loop

#2 Post by strayerror » Sat Jun 20, 2020 6:01 pm

If you hit the renpy.call(event.name) line, then control will not be returned to your function. The requested label will begin and the remainder of your code ignored.

This is because internally renpy.call triggers an exception that will be caught and interpreted by the main event loop further up-stack than your code is executing.
This will not only prevent your final line executing, but also any subsequent trips around your for loop.

jwideman
Newbie
Posts: 14
Joined: Tue Jul 30, 2019 7:17 pm
Contact:

Re: Value in list not changing in loop

#3 Post by jwideman » Sat Jun 20, 2020 6:43 pm

Even though my label has a return line? Okay, so renpy.call() is poorly named. Alrighty then. Thanks.

Post Reply

Who is online

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