[SOLVED]TypeError: argument of type 'Recipe' is not iterable

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
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

[SOLVED]TypeError: argument of type 'Recipe' is not iterable

#1 Post by Discostar »

I have been trying to customize Leon's great Inventory code, but I can't get the combine items/recipes feature to work.

Error

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 163, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 163, in <module>
    $ ui.interact()
  File "renpy/common/00action_other.rpy", line 420, in __call__
    self.callable(*self.args, **self.kwargs)
  File "game/script.rpy", line 67, in combine_items
    if item in recipe and item.selected:
TypeError: argument of type 'Recipe' is not iterable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 163, in script
    $ ui.interact()
  File "/Applications/Renpy6.99/renpy/ast.py", line 785, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "/Applications/Renpy6.99/renpy/python.py", line 1448, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/00gamemenu.rpy", line 163, in <module>
    $ ui.interact()
  File "/Applications/Renpy6.99/renpy/ui.py", line 277, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Applications/Renpy6.99/renpy/display/core.py", line 2276, in interact
    repeat, rv = self.interact_core(preloads=preloads, **kwargs)
  File "/Applications/Renpy6.99/renpy/display/core.py", line 2907, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/transition.py", line 45, in event
    return self.new_widget.event(ev, x, y, st) # E1101
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/screen.py", line 625, in event
    rv = self.child.event(ev, x, y, st)
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 785, in event
    return handle_click(self.clicked)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 728, in handle_click
    rv = run(action)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 283, in run
    new_rv = run(i, *args, **kwargs)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 290, in run
    return var(*args, **kwargs)
  File "renpy/common/00action_other.rpy", line 420, in __call__
    self.callable(*self.args, **self.kwargs)
  File "game/script.rpy", line 67, in combine_items
    if item in recipe and item.selected:
TypeError: argument of type 'Recipe' is not iterable

Darwin-14.4.0-x86_64-i386-64bit
Ren'Py 6.99.4.467
project_zero 0.0

class Recipe and class combine:

Code: Select all

init python:   
    def combine_items():
        for item in inventory.items:
            for recipe in recipes:
                recipe_tmp = recipe
                if item in Recipe and item.selected:
                    recipe_tmp.remove(item)
                    if len(recipe_tmp) == 1:
                        for tmp_item in recipe:
                            pass
                            inventory.drop(item)
                        inventory.add(recipe[0])
        return
        
    class Recipe(store.object):
        def __init__(self, items=[], item_created=None):
            self.items = items
            self.item_created = item_created
        def combine_check(self):
            too_many=False # too many items selected?
            correct_recipe_items = copy.copy(self.items) # make a copy of the list of recipe items
            for item in inventory.selected_items:
                if item.recipeItem: # and item in self.items:
                    if item in correct_recipe_items:
                        correct_recipe_items.remove(item) # remove the current item from the list of correct_recipe_items; if correct_recipe_items is empty at the end, we have created the recipe
                    if not (item in self.items): # current item is not in this recipe
                        too_many=True
            if len(correct_recipe_items) == 0 and not too_many: # correct_recipe_items is empty means we have selecte just the right items
                inventory.add(self.item_created) # add the newly created item
                for drop_item in self.items: # remove all the items in this recipe from inventory
                    inventory.drop(drop_item)
Re: File "game/script.rpy", line 67, in combine_items
if item in recipe and item.selected:
TypeError: argument of type 'Recipe' is not iterable

Line 67 is

Code: Select all

if item in recipe and item.selected:
from the combine_items class.

Thinking there was something wrong with my class Recipe, I tried renaming 'Recipe' in all manner of ways, but nothing.

Any ideas?
Last edited by Discostar on Sat Jul 25, 2015 3:01 pm, edited 1 time in total.

User avatar
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

Re: TypeError: argument of type 'Recipe' is not iterable

#2 Post by Discostar »

Just a quick update-

With the combine code, I realized I wasn't using Leon's combine suggestion- anyway, I updated to that, and now when I click the combine button nothing happens. The select overlay just goes away after clicking combine. Recipe items are not removed and item created is not granted.

Code now looks like that:

Code: Select all

init python:   
    def combine_items():
        for recipe in recipes:
            recipe.combine_check()
        inventory.selected_items = []
        return

    class Recipe(store.object):
        def __init__(self, items=[], item_created=None):
            self.items = items
            self.item_created = item_created
        def combine_check(self):
            too_many=False # too many items selected?
            correct_recipe_items = copy.copy(self.items) # make a copy of the list of recipe items
            for item in inventory.selected_items:
                if item.recipeItem: # and item in self.items:
                    if item in correct_recipe_items:
                        correct_recipe_items.remove(item) # remove the current item from the list of correct_recipe_items; if correct_recipe_items is empty at the end, we have created the recipe
                    if not (item in self.items): # current item is not in this recipe
                        too_many=True
            if len(correct_recipe_items) == 0 and not too_many: # correct_recipe_items is empty means we have selecte just the right items
                inventory.add(self.item_created) # add the newly created item
                for drop_item in self.items: # remove all the items in this recipe from inventory
                    inventory.drop(drop_item)
Still trying to figure this sucker out...

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: TypeError: argument of type 'Recipe' is not iterable

#3 Post by orz »

Code: Select all

def combine_items():
        for recipe in recipes:
            recipe.combine_check()
        inventory.selected_items = []
        return
Is 'recipes' a global?

User avatar
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

Re: TypeError: argument of type 'Recipe' is not iterable

#4 Post by Discostar »

orz wrote:

Code: Select all

def combine_items():
        for recipe in recipes:
            recipe.combine_check()
        inventory.selected_items = []
        return
Is 'recipes' a global?
When I do that I get the error "TypeError: argument of type 'function' is not iterable" :?

Let me be sure I'm doing it correctly-

so in an init block I have the following:

Code: Select all

init -1 python:   
    def recipes():
        global recipes
        self = []
        recipes.append("laser", ["chocolate", "banana"])  
Am I doing this correctly?

User avatar
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

Re: TypeError: argument of type 'Recipe' is not iterable

#5 Post by Discostar »

UPDATE! I've defined recipes properly this time (iman00b) (Yay!) but I'm getting this error now (boo!):

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 163, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 163, in <module>
    $ ui.interact()
  File "renpy/common/00action_other.rpy", line 420, in __call__
    self.callable(*self.args, **self.kwargs)
  File "game/script.rpy", line 79, in combine_items
    Recipe.combine_check()
TypeError: unbound method combine_check() must be called with Recipe instance as first argument (got nothing instead)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 163, in script
    $ ui.interact()
  File "/Applications/Renpy6.99/renpy/ast.py", line 785, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "/Applications/Renpy6.99/renpy/python.py", line 1448, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/00gamemenu.rpy", line 163, in <module>
    $ ui.interact()
  File "/Applications/Renpy6.99/renpy/ui.py", line 277, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Applications/Renpy6.99/renpy/display/core.py", line 2276, in interact
    repeat, rv = self.interact_core(preloads=preloads, **kwargs)
  File "/Applications/Renpy6.99/renpy/display/core.py", line 2907, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/transition.py", line 45, in event
    return self.new_widget.event(ev, x, y, st) # E1101
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/screen.py", line 625, in event
    rv = self.child.event(ev, x, y, st)
  File "/Applications/Renpy6.99/renpy/display/layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 785, in event
    return handle_click(self.clicked)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 728, in handle_click
    rv = run(action)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 283, in run
    new_rv = run(i, *args, **kwargs)
  File "/Applications/Renpy6.99/renpy/display/behavior.py", line 290, in run
    return var(*args, **kwargs)
  File "renpy/common/00action_other.rpy", line 420, in __call__
    self.callable(*self.args, **self.kwargs)
  File "game/script.rpy", line 79, in combine_items
    Recipe.combine_check()
TypeError: unbound method combine_check() must be called with Recipe instance as first argument (got nothing instead)

Darwin-14.4.0-x86_64-i386-64bit
Ren'Py 6.99.4.467
project_zero 0.0
Please advise.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: TypeError: argument of type 'Recipe' is not iterable

#6 Post by SinnyROM »

I haven't gotten a chance to look at the inventory code, but it looks like the function combine_check() has Recipe as a required parameter:

Code: Select all

def combine_items():
    global recipes
    for recipe in recipes:
        combine_check(recipe) # here the iterated recipe is passed as a parameter
    inventory.selected_items = []
    return

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: TypeError: argument of type 'Recipe' is not iterable

#7 Post by orz »

What SinnyROM said.

On that error message, it says "TypeError: unbound method combine_check() must be called with Recipe instance as first argument (got nothing instead)".

User avatar
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

Re: [SOLVED]TypeError: argument of type 'Recipe' is not iter

#8 Post by Discostar »

Ok, I got it. Being a newbie, I didn't realize that the biggest problem was a basic one-

I wasn't defining recipes correctly, but the whole "recipes" vs "recipe" thing was confusing me as well.
Anyway- Thank you, SinnyROM and Orz, for helping steer me in the right direction! m(_ _)m

dragonlord3989
Regular
Posts: 30
Joined: Tue Nov 17, 2015 1:34 pm
Contact:

Re: TypeError: argument of type 'Recipe' is not iterable

#9 Post by dragonlord3989 »

Would you be able to post a rar file with you working inventory please?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Toma