Page 1 of 1

real number expected got nil.

Posted: Fri Jun 28, 2019 8:25 pm
by Tias
I am trying to update a TAS Playback mod to 0.17. I run into this error and can't figure out what causes it:
The complete Error Message
The complete Error Message
ErrorMsg.PNG (18.88 KiB) Viewed 2623 times
The complete code for the Event/function:

Code: Select all

script.on_event(defines.events.on_tick, function(event)  		--line 108
	if commandqueue and global.running then
		local tick = game.tick - global.start_tick
		local myplayer = global.myplayer
		local mycharacter = myplayer.character
		if not myplayer.connected then
			error("The runner left.")
		end
		if commandqueue[tick] then
			for k,v in pairs(commandqueue[tick]) do
				TAScommands[v[1]](v, myplayer)
			end
		end
		myplayer.walking_state = global.walkstate  		--line 121
		if not global.minestate then 
			myplayer.mining_state = {mining = false}
		else
			myplayer.update_selected_entity(global.minestate)
			myplayer.mining_state = {mining = true, position = global.minestate}
		end
		if tick == max_tick then
			end_of_input(myplayer)
		end
	end
end)
I tried with mycharacter instead of myplayer in line 121, and I am 98% certain that global.myplayer is a LuaPlayer (with a single attached character) when this is being called.

Re: real number expected got nil.

Posted: Fri Jun 28, 2019 8:28 pm
by DaveMcW
Yes, global.myplayer is a valid LuaPlayer. You can tell because it knows the expected type of walking_state (real number).

Your problem is global.walkstate is nil.

Re: real number expected got nil.

Posted: Fri Jun 28, 2019 8:34 pm
by Tias
DaveMcW wrote: Fri Jun 28, 2019 8:28 pmYour problem is global.walkstate is nil.
It's not though, it's a table that should be a valid walking_state.
The result of adding this:

Code: Select all

		util.debugprint(type(global.walkstate))
		util.debugprint(tostring(global.walkstate.walking))
is:
table
false

Re: real number expected got nil.

Posted: Fri Jun 28, 2019 8:36 pm
by DaveMcW
How about direction? That is a real number and required.

Code: Select all

util.debugprint(tostring(global.walkstate.direction))

Re: real number expected got nil.

Posted: Fri Jun 28, 2019 8:39 pm
by Tias
DaveMcW wrote: Fri Jun 28, 2019 8:36 pm

Code: Select all

util.debugprint(tostring(global.walkstate.direction))
Yes this is Nil, though I though if Walking is false that was not required.
Fixed now, thanks.

Re: real number expected got nil.

Posted: Sat Jun 29, 2019 10:36 am
by Bilka
Tias wrote: Fri Jun 28, 2019 8:39 pm Yes this is Nil, though I though if Walking is false that was not required.
The game was requiring it and then throwing it away. I fixed that for 0.17.53, it will no longer be required when setting walking to false.