An error I get when trying to call a function I made

So basically I have this function compare_arrays. For my assingment and almost as soon as it gets called make code arcade gives this error that I’m guessing is an internal error.
“e.findIdx is not a function” no line number since it does not exist in my code. Here is my function:

def compare_arrays(arr1, arr2):
    
    feedback = [0, 0, 0, 0]  # Initialize feedback array with zeros
    for i in range(3):

        print(arr1)
        print(i)
        if arr1[i] == arr2[i]:
            print("set to 1")
            feedback[i] = 1
            print(arr1 + ", " + arr2 + ", " + feedback)
        elif isin(arr1[i], arr2):
            print("set to 2")
            feedback[i] = 2
            print(arr1 + ", " + arr2 + ", " + feedback)
        else:
            print("set to 0")
            feedback[i] = 0
            print(arr1 + ", " + arr2 + ", " + feedback)
    return [feedback[0],feedback[1],feedback[2],feedback[3]]

def isin(val, arr):
    for i in range(4):
        if arr[i] == val:
            return True
    
    return False

Here is the link to my project: https://arcade.makecode.com/S04313-39937-09651-25135
the controls are:
left arrow: move selector left
right arrow: move selector right
up arrow: submit guess
down arrow: select
B Button: open the color picker menu

The project is based off of the game master mind. It would help anyone to understand this project and how it works if they understand how to play master mind.

1 Like

Welcome, @Obsidian !

This is a great looking game!

This is a tough error to track down! But I think I know how to help you.

Sometimes, Python gets confused as to a variable’s type, particularly with function parameters. If you run into this error, it’s likely that Python doesn’t know that your parameters are lists. Change your compare_arrays() function definition to this:

def compare_arrays(arr1: List[number], arr2: List[number]):

This notation lets Python know the type of these two parameters.

Also, to simplify your function, at the end, just return feedback. You don’t have to create a new array with the elements in feedback; just return the array as it is.

You’ll need to make a similar correction to isin().

def isin(val, arr: List[number]):

Once you do that, then Python should be happier with your code. At least, your project was running for me without generating any errors.

If you get stuck again, just let us know! Be sure to post a new share link with your new code.

Great project! And only after unit 2! Impressive!

2 Likes

Oh wow! Thank you so much, this actually did fix it! I never knew that about python, so I guess I also learned something from this. If I do get stuck again I will definitely let you know thanks for the help! And Thank you!

1 Like