Array not clearing and clearing wrongly

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
Norezza
Newbie
Posts: 19
Joined: Tue Oct 17, 2017 7:51 pm
Contact:

Array not clearing and clearing wrongly

#1 Post by Norezza »

Hi!

I have a strange problem.

If I start a game, purchase an item, adding it to my inventory, then go back to the main menu and start a new game; the inventory from my previous game is maintained. Example: I start a game, purchase chocolates, the chocolates follow through on a new game.

However! If I save a game, and go back into the game, the chocolate is no longer in my inventory.

These are all in my declarations.rpy file.

Code: Select all

define itemArr = [0,0,0,0,0,0,0,0]
define itemIArr = ['items/item1.png', 'items/item2.png', 'items/item3.png', 'items/item4.png', 'items/item5.png', 'items/item6.png', 'items/item7.png', 'items/item8.png']
define emptyArr = ["", "", "", "", "", "", "", ""]

My function is in functions.rpy

Code: Select all

init python:
    def invent():
        global emptyArr
        i = 0
        while i < len(itemArr):
            if itemArr[i] > 0:
                emptyArr[i] = itemIArr[i]
            i+=1
        return
The one and only time I call invent() is when I click the inventory menu, in the screen.

Code: Select all

screen inventory:
    $invent()
    modal True
    imagemap:
        
        ground "gui/menu/items.png"
        hover "gui/menu/items_hover.png"

        hotspot(999,195,40,40) clicked Hide("inventory")                    
        
        hbox:
            xpos 240
            ypos 235
            spacing 22
            for x in emptyArr:
                if x != "":
                    image x
            
        hbox:
            xpos 300
            ypos 290
            spacing 80
            for x in itemArr:
                if x !=0:
                    text "{b}[x]{/b}":
                        min_width 22

In my quick_menu, I call this with my imagemap.

Code: Select all

hotspot(1121,0,38,30) clicked Show('inventory')
Does anyone have any idea what is causing this inventory issue?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Array not clearing and clearing wrongly

#2 Post by trooper6 »

Try again defining your variables with default rather than define.
default is for variables that will change during the course of the game.
define is for variables that won't.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Norezza
Newbie
Posts: 19
Joined: Tue Oct 17, 2017 7:51 pm
Contact:

Re: Array not clearing and clearing wrongly

#3 Post by Norezza »

Defining the arrays as default gives me an error message saying that the array isn't defined, apparently, so that gave me a new problem

EDIT:
Strange, seems to suddenly have gone away! Thank you, it works! :D

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot], solarisdreams