[0.17.34] in events.on_player_setup_blueprint: player.cursor_stack.valid==true, but it's a lie!

Bugs that are actually features.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

[0.17.34] in events.on_player_setup_blueprint: player.cursor_stack.valid==true, but it's a lie!

Post by Qon »

Step 1:

Code: Select all

/c 
script.on_event(defines.events.on_player_setup_blueprint, function(event) 
	local cs = game.players[event.player_index].cursor_stack 
	if cs.valid then 
		game.print(cs.name) 
	end 
end)
Step 2: Make a blueprint.
Step 3: Enjoy your crash.

What I expect: If I check if something is valid then it should be safe to use immediately after if I don't modify anything. I don't expect a crash when I write valid code :?
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Bilka
Factorio Staff
Factorio Staff
Posts: 3619
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.17.34] in events.on_player_setup_blueprint: player.cursor_stack.valid==true, but it's a lie!

Post by Bilka »

I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: [0.17.34] in events.on_player_setup_blueprint: player.cursor_stack.valid==true, but it's a lie!

Post by Qon »

Thanks. Is this 'valid_for_read' just for LuaItemStack or are there more classes where .valid is useless and needs to be randomly replaced with another property just to mess with modders? ;)
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Post Reply

Return to “Not a bug”