Page 1 of 1

BUG : blueprint returns nil direction

Posted: Sun Jul 16, 2017 11:33 pm
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 :( )

Re: BUG : blueprint returns nil direction

Posted: Mon Jul 17, 2017 8:55 am
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

Re: BUG : blueprint returns nil direction

Posted: Mon Jul 17, 2017 9:33 am
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.