Manage items in a list (Array)

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
richycapy
Regular
Posts: 56
Joined: Mon May 27, 2019 8:53 pm
Organization: EN Productions
Location: Mexico
Contact:

Manage items in a list (Array)

#1 Post by richycapy »

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: Select all

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: Select all

$ 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: Select all

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

emanuel
Newbie
Posts: 18
Joined: Fri Dec 25, 2020 8:44 am
Contact:

Re: Manage items in a list (Array)

#2 Post by emanuel »

You need to turn that in a Python block, like so:

Code: Select all

python:
	poolsupply = Item("Pool Supply", "Artículos de limpieza", "quimicos.png", 1, 5, 0, 150)
	productssent.append(poolsupply)
	for product in productssent:
		if product.daysittakes == product.dayspassed:
			productsdelivered.append(product)
			productssent.remove(product)
		else:
			product.passday()
The for loop does nothing when the list is empty, and it's also not empty because you just added an item, so I removed that 'if len > 0' check.
There was also an assignment (=) in the if statement, where you probably want a equality comparison (==)

There are some limitations when it comes to classes and save games in Renpy, but I'm not sure about that, so you may want to look into that.

Post Reply

Who is online

Users browsing this forum: Ocelot, Semrush [Bot]