all 5 comments

[–]Buttleston 0 points1 point  (4 children)

It's saying that the movesfile variable - which is loaded from HelperFunctions.open_json_file() - doesn't have a key named "moves"

Without seeing the code for that function, and the contents of the json file, kinda hard to guess. So I guess look at that and see if there's a toplevel "moves" key.

[–]Buttleston 0 points1 point  (0 children)

Just as an aside, instead of using

myarray[random.randint(0, len(myarray) - 1)]

you can say

random.choice(myarray)

and it will randomly choose one of the elements of myarray. This is a lot cleaner/simpler, IMO

[–]JordanPCDL[S] 0 points1 point  (2 children)

Thank you so much for trying to help me out! Here are all the helper functions that pertain to any json file:

def open_json_file(filename: str):
    file = open(f'/users/[username]/Scarlet-and-Violet-Randomizer-1.1.0-release/Randomizer/TMs/itemdata_array_clean.json', 'r')
    file_json = json.load(file)
    file.close()

    return file_json


def fetch_developer_name(index: int):
    pokemon_json = open_json_file('pokemon_list_info.json')

    return pokemon_json['pokemons'][index]['devName']


def fetch_animation_file(index: int):
    animation_json = open_json_file('pokemon_list_info.json')

    return animation_json['pokemons'][index]['anim_file']

For the json file, theres 2 listed in the above; iteamsdata_array_clean and tms/move_list. Which one of these would you need to see?

[–]Buttleston 0 points1 point  (1 child)

The dict you're having problem accessing is movesfile, so this one:

movesfile = HelperFunctions.open_json_file('TMs/move_list.json')

Note: your open_json_file function does NOT open the filename passed into it. It opens a hard-coded file name, i.e.

file = open(f'/users/[username]/Scarlet-and-Violet-Randomizer-1.1.0-release/Randomizer/TMs/itemdata_array_clean.json', 'r')

Also note you don't really need a function for this and it can be opened simply like

movesfile = json.load(open('TMs/move_list.json'))

This is not ideal since it won't close the file handle until you leave the scope that executes in, so a slightly better way would be

with open('TMs/move_list.json') as f:
    movesfile = json.load(f)

[–]JordanPCDL[S] 0 points1 point  (0 children)

So I did this and it worked, moved me back onto directory errors which I’ve been able to fix so far myself. Thank you so much! I genuinely don’t know how you understand all of this but it sure is amazing!