Author Topic: API optional parameters: error using nil  (Read 3224 times)

0 Members and 2 Guests are viewing this topic.

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
API optional parameters: error using nil
« on: November 11, 2018, 03:08:49 AM »
I tried making a new surface and got a strange error:

bad argument #1 to create (number, string or no value expected, got nil)

The only way I've found to get around it is the following, but it's a bit awkward:
Code: (lua) [Select]
local surface = width and sol.surface.create(width, height) or sol.surface.create()
It's a bit strange that there'd be a distinction between a value of 'nil' and 'no value' when it comes to specifying optional values. Is there a better way to get around it while working purely in lua? i.e. is there a way to assign 'no value' to a lua variable?

For context, the value of width is being specified by a data file, and I'm wanting to use default values if the width is omitted in the data file.