trAInsported icon indicating copy to clipboard operation
trAInsported copied to clipboard

Game crashes if I try to start challenge with new files

Open mgtaboada opened this issue 7 years ago • 2 comments

Hello, I have just finished to write my first ai but when I try to start a challenge with its file, I get the follownig error:

Error: table: 0x406503d8
stack traceback:
	[C]: in function 'error'
	Scripts/ai.lua:43: in function <Scripts/ai.lua:35>
	Scripts/misc.lua:406: in function 'myRandom'
	Scripts/mapUtils.lua:869: in function 'renderMap'
	Scripts/map.lua:1268: in function 'render'
	Scripts/map.lua:408: in function 'generate'
	main.lua:617: in function 'update'
	[string "boot.lua"]:464: in function <[string "boot.lua"]:436>
	[C]: in function 'xpcall'

I suppose it's my code's fault, but I don't know why

mgtaboada avatar Jan 03 '18 16:01 mgtaboada

Can you show me your AI?

An AI should not be able to crash the game, so that's my fault...

Germanunkol avatar Jan 09 '18 09:01 Germanunkol

Looks like It's because I defined variables outside a function definition. the piece of code looked like

linkedList = {}
function linkedList.new()
--...
end
--...
function ai.init()
--...

I changed it to define variables inside function definitions and now it doesn't crash.

mgtaboada avatar Jan 09 '18 09:01 mgtaboada