4

I'm new on the moon and I wonder how I can take a function check if the value contained is on a table.

local extraItem = {
  Interior = {from = {1602; 2064; 2070; 2108};
          to = {1808; 2065; 2079; 2119};
          id = {2034; 2180; 2192; 2594}}
}

local function onOptionChange(widget, optText, optData)
  if optData >= 16 then
    print(optText)
    for a, v in ipairs(extraItem.optText.from) do
      for i = extraItem.optText.from[a], extraItem.optText.to[a] do
        local widget = g_ui.createWidget('PaletteItem', paletteList)
        local itemid = g_things.getItemType(i)
        widget:setItemId(itemid:getClientId())
      end
    end
    for a, v in ipairs(extraItem.optText.id) do
      local widget = g_ui.createWidget('PaletteItem', paletteList)
      local itemid = g_things.getItemType(v)
      widget:setItemId(itemid:getClientId())
    end
  end
end

the print(optText) print Interior and extraItem.optText.from return nul, how fix it?

1 Answer 1

2

Use extraItem[optText] instead of extraItem.optText.

extraItem.optText is equivalent to extraItem["optText"].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.