Jump to content

[SOLUTION IN TOPIC]Loading locale_game.txt raises KeyError


Recommended Posts

  • Premium

Hello,

When adding the bellow string to locale_game.txt

APPLY_ANTI_RESIST_MAGIC	Magic Pen: %d%%	SA

A key error is raised:
 

0613 21:44:08342 :: 
system.py(line:287) RunMainScript
system.py(line:204) execfile
prototype.py(line:3) <module>
system.py(line:151) __hybrid_import
system.py(line:116) _process_result
localeInfo.py(line:210) <module>
localeInfo.py(line:167) LoadLocaleFile

Run - <type 'exceptions.KeyError'>:'S'

0613 21:44:08343 :: ============================================================================================================
0613 21:44:08343 :: Abort!!!!

Without the SA at the end, the bonus name is not properly displayed in game
W/o the SA at the end, the bonus name is displayed as "UNKNOWN_NAME(93), the 93 is the index for the bonus in `enum EApplyTypes` from itemData.h

Any ideas?
 

LoadLocalFile py function:

Spoiler
def LoadLocaleFile(srcFileName, localeDict):

	def SNA(text):
		def f(x):
			return text
		return f

	def SA(text):
		def f(x):
			return text % x
		return f

	funcDict = {"SA":SA, "SNA":SNA}

	lineIndex = 1

	try:
		lines = open(srcFileName, "r").readlines()
	except IOError:
		import dbg
		dbg.LogBox("LoadLocaleError(%(srcFileName)s)" % locals())
		app.Abort()

	for line in lines:
		try:
			tokens = line[:-1].split("\t")
					
			if len(tokens) == 2:
				localeDict[tokens[0]] = tokens[1]
			elif len(tokens) >= 3:
				type = tokens[2].strip()
				if type:
					localeDict[tokens[0]] = funcDict[type](tokens[1]) #---------------- LINE 167 from error traceback
				else:
					localeDict[tokens[0]] = tokens[1]
			else:
				raise RuntimeError, "Unknown TokenSize"

			lineIndex += 1
		except:
			import dbg
			dbg.LogBox("%s: line(%d): %s" % (srcFileName, lineIndex, line), "Error")
			raise

 

 

Thanks!

EDIT:
SOLVED:

          Because of this stupid line of code `tokens = line[:-1].split("\t")` you gotta have an extra char(space/new line) after 'SA'  *only if its the last line in the file*
         

 

 

Edited by astroNOT
  • Metin2 Dev 2
Link to comment
Share on other sites

"Because of this stupid line of code `tokens = line[:-1].split("\t")` you gotta have an extra char(space) after 'SA'"

This is for remove the line break, just add an empty line if it's the last line of your file. Because if you add another line after this one, the script will take your space at function name also

Link to comment
Share on other sites

  • Premium
22 hours ago, PetePeter said:

"Because of this stupid line of code `tokens = line[:-1].split("\t")` you gotta have an extra char(space) after 'SA'"

This is for remove the line break, just add an empty line if it's the last line of your file. Because if you add another line after this one, the script will take your space at function name also

Indeed it removes the last char, in our chase the /n, aaand if its the last line in the file w/o a nl, then its doomed, updated the topic accordingly, thanks!

Edited by astroNOT
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.