Help! I’m Stuck on a Bug While Building a Roguelike

0
8
Asked By CraftyPineapple77 On

I'm working on a roguelike game following a tutorial from build-your-own-x, but I keep running into this annoying bug. The error message I'm getting is: "IndexError: only integers, slices, ellipsis, numpy.newaxis, and integer or boolean arrays are valid indices." This happens at the line: [action.target_xy] in my activate method. Here's a part of the code where the error occurs:

def activate(self, action: actions.ItemAction) -> None:
consumer = action.entity
target = action.target_actor

if not self.engine.game_map.visible[action.target_xy]:
raise Impossible("You cannot target an area that you cannot see.")
if not target:
raise Impossible("You must select an enemy to target.")
if target is consumer:
raise Impossible("You cannot confuse yourself!")

self.engine.message_log.add_message(
f"The eyes of the {target.name} look vacant, as it starts to stumble around!",
color.status_effect_applied,
)
target.ai = components.ai.ConfusedEnemy(
entity=target, previous_ai=target.ai, turns_remaining=self.number_of_turns,
)
self.consume()

I've been trying to figure out what the issue is for three days now. Can anyone explain why this is happening and how to fix it?

2 Answers

Answered By DebuggingDynamo On

It looks like when you call the `activate` function, you might be passing an `ItemAction` object that has a null or invalid `target_xy` property. You should double-check that `target_xy` is set correctly before using it.

Answered By SyntaxSlinger On

From the error message, it seems like `action.target_xy` isn't a valid index. Have you inspected what `action.target_xy` actually contains? Knowing its value can help pinpoint the issue.

CuriousCoder -

I checked it, and it's not properly set. I think it might just be a parameter.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.