BUG : blueprint returns nil direction

Things that we aren't going to implement
d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

BUG : blueprint returns nil direction

Post by d3x0r »

While working on this rails mod, I found that a curved rail that is direction 0 returns an entity with direction=nill

Code: Select all

          player.cursor_stack.create_blueprint{surface = surface, force = belt.force,area = a}
          local old_blueprint = player.cursor_stack.get_blueprint_entities()
All other directions seem to return their proper number; probably the test in C++ code is like if (!value ) entity.direction=nil; insteaed of if( value == null ) or if( value == 0 ) (which actually might be the same thing :( )
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: BUG : blueprint returns nil direction

Post by bobingabout »

Even in LUA, sometimes determining the difference between nil, false and 0 can be difficult.

"if not value then" will accept any of the 3.

There's even an error where if you use table.deepcopy on a value, it will copy it, unless it is 0 or false, in which case the result comes through as nil.
This was annoying because I was trying to copy a recipe line by line in a situation where I'm converting it from a standard recipe, to a difficulty split recipe, the easy way was to table.deepcopy every line, this was needed for lines such as ingredients which can be complex tables.
However, when attempting to copy the enabled line (Which is generally either false, or non existant because the default is true, therefore nil = true in this case, which means you're literally checking for false vs nil) the result was that EVERY converted recipe was enabled, and none were not enabled. After attempting to add a log file to every step, enabled errored with the "recipe.normal.enabled" not existing error, which is the same as it being nil. I solved the problem by simply copying the value for this one. I guess you could blame me for using a TABLE function on a nontable variable, but still, it should probably have been able to tell the difference between false and nil.

Code: Select all

recipe.normal.enabled = recipe.enabled
recipe.expensive.enabled = recipe.enabled
recipe.enabled = nil
vs

Code: Select all

recipe.normal.ingredients = table.deepcopy(recipe.ingredients)
recipe.expensive.ingredients = table.deepcopy(recipe.ingredients)
recipe.ingredients = nil
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15883
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: BUG : blueprint returns nil direction

Post by Rseding91 »

The direction key is excluded from the blueprint when it's default (north) because it wastes a lot of space to say "direction=north" for every single entity in a given blueprint string. Several things are excluded when default values in the string format.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Won't implement”