Help in deleting the contents of an array at the end of a conversation.

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
nhguy03276
Regular
Posts: 41
Joined: Thu Jan 29, 2015 12:48 pm
Contact:

Help in deleting the contents of an array at the end of a conversation.

#1 Post by nhguy03276 »

I'm probably just being dense again, but the lack of a Foreach loop in the main program has really gotten stumped.

Essentially, I want to reset my vendors inventory after the conversation is done.

I normally would use something like:

Code: Select all

Foreach item in vendor.items[]:
              vendor.drop[item] 
but of course, it isn't going to be that simple... and I can't seem to get the python to work either... I just need a simple method to call to blank all items in a random length array.

Thanks

User avatar
Lord Hisu
Regular
Posts: 58
Joined: Sun Feb 11, 2018 2:31 am
Contact:

Re: Help in deleting the contents of an array at the end of a conversation.

#2 Post by Lord Hisu »

You can just do:

Code: Select all

vendor.items = []
But keep in mind this will not delete the objects from memory, just clear the list.

nhguy03276
Regular
Posts: 41
Joined: Thu Jan 29, 2015 12:48 pm
Contact:

Re: Help in deleting the contents of an array at the end of a conversation.

#3 Post by nhguy03276 »

Thank you. That appears to work. It is funny how sometimes your mind gets stuck, and I just didn't see a solution... Also, this is the second programming language in the last 2 months I've encountered without a For each loop... I can't fathom why... For each loops can be so useful at times.

User avatar
Lord Hisu
Regular
Posts: 58
Joined: Sun Feb 11, 2018 2:31 am
Contact:

Re: Help in deleting the contents of an array at the end of a conversation.

#4 Post by Lord Hisu »

I think maybe you mean this?

Code: Select all

for gummy in gummy_jar:
    if gummy.type == "green":
        kid.eat(gummy)
'gummy_jar' can be any type of iterable: lists, dictionaries, tuples, or even strings.
'gummy' is the item being accessed. So, for each gummy the kid picks in the jar, if the gummy is green, the kid eat it. =)

You can use for loops, but if you just want to reset a list, you don't need one.
If you wanted to apply some action in the content of the iterable, then you would need a for loop.

Post Reply

Who is online

Users browsing this forum: Google [Bot]