real number expected got nil.

Place to get help with not working mods / modding interface.
Post Reply
Tias
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed May 11, 2016 5:10 am
Contact:

real number expected got nil.

Post 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 2168 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.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: real number expected got nil.

Post 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.

Tias
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed May 11, 2016 5:10 am
Contact:

Re: real number expected got nil.

Post by Tias »

DaveMcW wrote:
Fri Jun 28, 2019 8:28 pm
Your 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

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: real number expected got nil.

Post by DaveMcW »

How about direction? That is a real number and required.

Code: Select all

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

Tias
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed May 11, 2016 5:10 am
Contact:

Re: real number expected got nil.

Post 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.

Bilka
Factorio Staff
Factorio Staff
Posts: 3140
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: real number expected got nil.

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding help”