Ren'Py Manage items in a list (Array)

RichyCapy

Active Member
Game Developer
Jul 26, 2017
763
844
Hello

I’m trying to create a delivery inventory system, in which the user when he buys something online, it takes certain amount of days to deliver

This is the class of my inventory:

Code:
init python:
    class Item:
            def __init__(self, name, namees, picture, maxallowed, daysittakes, dayspassed, cost):
                self.name = name
                self.namees = namees
                self.picture = picture
                self.maxallowed = maxallowed
                self.daysittakes = daysittakes
                self.dayspassed = dayspassed
                self.cost = cost

            def passday(self, amount=1):
                self.passday+= amount
                if self.passday> daysittakes:
                    self.passday= daysittakes
At the end of each day, I would like to see which products are on their way, and place the once arrived on another list, or add another day to the once still to arrive, so I do this:

Code:
$ poolsupply = Item("Pool Supply", "Artículos de limpieza", "quimicos.png", 1, 5, 0, 150)

$ productssent.append(poolsupply)

$ countproductssent = len(productssent)
    if countproductssent > 0:
        for product in productssent:
            if product.daysittakes = product.dayspassed:
                $ productsdelivered.append(product)
                $ productssent.remove(product)
            else:
                $  product.passday()
But Im getting this error:
Code:
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/historias.rpy", line 3221: expected statement.
    for product in productssent:
                ^

Ren'Py Version: Ren'Py 7.3.5.606
Mon Dec 28 18:32:37 2020
Can someone help me with this? :D
Thanks a lot
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,360
15,270
Code:
init python:
    class Item:
            def __init__(self, name, namees, picture, maxallowed, daysittakes, dayspassed, cost):
                self.name = name
                self.namees = namees
                self.picture = picture
                self.maxallowed = maxallowed
                self.daysittakes = daysittakes
                self.dayspassed = dayspassed
                self.cost = cost

            def passday(self, amount=1):
                self.passday+= amount
                if self.passday> daysittakes:
                    self.passday= daysittakes
Why so complicated ?
Python:
init python:
    class Item:
#            def __init__(self, name, namees, picture, maxallowed, daysittakes, dayspassed, cost):
            def __init__(self, name, namees, picture, maxallowed, daysittakes, cost):
                self.name = name
                self.namees = namees
                self.picture = picture
                self.maxallowed = maxallowed
# You don't need this.
# If you want to consider that there's already few days passed,
# just provide the right value in /daysittakes/.
#                self.dayspassed = dayspassed
                self.daysittakes = daysittakes
                self.cost = cost

            def passday(self, amount=1):
                # X days have passed, so there's X days less before the delivery.
                self.daysittakes -= amount
                # Ensure that it will not be negative for it to have a /null/-like value (see bellow)
                # Obviously, when /daysittakes/ reach 0, the delivery happened.
                if self.daysittakes < 0:
                    self.daysittakes = 0

Code:
File "game/historias.rpy", line 3221: expected statement.
    for product in productssent:
                ^
As the error say, for isn't a valid statement for Ren'py language.

Therefore, if you want a for loop, what is the best approach here, you need to use Python, either in a Python block or a function. Since you initially put the code into a label, I'll go for the first approach:
Python:
label whatever:
    [...]
    python:
        # If the list is empty, the loop will just not be proceeded.
        for product in productssent:
            # Effect of the modification made above :
            # If at least one more day before delivery, pass a day
            if product.daysittakes:
                product.passday()
            # Else (if the value is /null/) deliver
           else:
                productsdelivered.append(product)
                productssent.remove(product)