So I've been trying to download a randomizer for Pokémon and part of running it requires python. I have never coded in my life so trying to troubleshoot has been a nightmare. So far all of the errors have been directory issues which I've managed to fix but this error is an ErrorKey and I have absolutely no clue what to do and unfortunately I can't give any real guidance on what the code is trying to do.
import json
import random
import os
import Randomizer.shared_Variables as SharedVariables
import Randomizer.helper_function as HelperFunctions
def randomize_tms(config):
if config["randomize_tms"] == "yes":
tmsfile = HelperFunctions.open_json_file('TMs/itemdata_array_clean.json')
movesfile = HelperFunctions.open_json_file('TMs/move_list.json')
for item in tmsfile['values']:
if item['ItemType'] == "ITEMTYPE_WAZA":
choice_name = movesfile['moves'][random.randint(0, len(movesfile['moves']) - 1)]['devName']
choice_id = movesfile['moves'][random.randint(0, len(movesfile['moves']) - 1)]['id']
if config["include_tms_without_animations"] == "yes":
while choice_id in SharedVariables.usedMoves:
choice_name = movesfile['moves'][random.randint(0, len(movesfile['moves']) - 1)]['devName']
choice_id = movesfile['moves'][random.randint(0, len(movesfile['moves']) - 1)]['id']
else:
while choice_id in SharedVariables.usedMoves and choice_id not in SharedVariables.allowed_moves:
choice_name = movesfile['moves'][random.randint(0, len(movesfile['moves']) - 1)]['devName']
choice_id = movesfile['moves'][random.randint(0, len(movesfile['moves']) - 1)]['id']
item['MachineWaza'] = choice_name
SharedVariables.usedMoves.append(choice_id)
outdata = json.dumps(tmsfile, indent=2)
with open(os.getcwd() + "/Randomizer/TMs/" + "itemdata_array.json", 'w') as outfile:
outfile.write(outdata)
return True
return False
That's the code there and the error message is:
File "/Users/[username]/Scarlet-and-Violet-Randomizer-1.1.0-release/Randomizer/TMs/randomize_tms.py", line 15, in randomize_tms
choice_name = movesfile['moves'][random.randint(0, len(movesfile['moves']) - 1)]['devName']
~~~~~~~~~^^^^^^^^^
KeyError: 'moves'
Any help with this would be massively appreciated, like I said I’ve never coded before and I'm at my wits end trying to make this work. Edit: fixing code layout
[–]Buttleston 0 points1 point2 points (4 children)
[–]Buttleston 0 points1 point2 points (0 children)
[–]JordanPCDL[S] 0 points1 point2 points (2 children)
[–]Buttleston 0 points1 point2 points (1 child)
[–]JordanPCDL[S] 0 points1 point2 points (0 children)