hello I am making a command line based game engine and there is an error that keeps popping up it says 'TypeError: 'bool' object is not iterable' when trying to run this code on line 233
232 #quest handler
233 for quest in active_quests not in completed_quests:
234 quest_type = data.quests[quest]["type"]
235 if quest_type == "kill":
236 #check if thing has been killed
237 if data.quests[quest]["number"] in fights_won:
238 unrewarded_quests.append(quest)
I do not know if it thinks that active_quests or completed_quests is a bool. as far as i know there are both lists. there values are as follows
completed_quests = [0]
active_quests = []
part of me thinks that because there is nothing in acitve_quests that it comes back as False I want to know how to make it not brake if there is nothing in active_quests. as long as nothing goes wrong there should always be something in completed_quests. full code can be found at replit and github. github link: https://github.com/mrhoomanwastaken/pypg/tree/people-and-quest-handler-overhaul
replit link: https://replit.com/@mrhoomanwastaken/pypg-game-engine?v=1
CodePudding user response:
You were close, but your syntax was a bit off. You should iterate over a list of elements that satisfy your condition, but instead you were iterating over a boolean of the pattern a not in b
.
for quest in [q for q in active_quests if q not in completed_quests]:
...
CodePudding user response:
active_quests not in completed_quests
returns a bool
, which is why your code won't work.
The for
loop should be rewritten to something like
for quest in [a for a in active_quests if a not in completed_quests]: