Posted: Sat Jun 27, 2026 3:38 am Post subject: Bypass error for non-existing item in table
Before anything else, I've posted my solution below. But my guts feeling tells me this can be done far more easily ?! Did some googling, but nothing workable came around (or my wording is just "off")...
Type of table:
aMaterials = {
{'Fuel Resources',0x0}, {'Biological Material',0x4}, {'Common Metal',0x8},
{'Minor Metal',0xC}, {'Precious Metal',0x10}, }
Here is my problem: to get particular info from an item, i obtain it by using the format: sDescr = aMaterials[0x4][1] (for example)
=> items are added per 'id' here: eg aMaterials[0x4] = { ... }
Unfortunately, this 'Id' value is collected from the item's memory_record. and while ok in 99% of the cases, it is that 1% causing the error !
My approach: i use pcall to check/handle error (see below)?!
Unfortunately, i can not remember the exact error (not nil - but either 'index'-error or ?field- error ? or something )
=> i can get you the original error if needed though
-----------
Solution:
local function chkArray(aArray, iVal) return aArray[iVal][1] end
local sVal = "<None>"
local status, err = pcall(function() chkArray(aBlueprnt, Dev_Req_Bluepr) end)
if status then sVal = aBlueprnt[Dev_Req_Bluepr][1] end
f.Dev_Req_Bluepr_cb.Text = sVal
local material = aBlueprnt[Dev_Req_Bluepr]
if not material then
-- material does not exist in the table: either get that info or do something else
f.Dev_Req_Bluepr_cb.Text = "<None>"
else
f.Dev_Req_Bluepr_cb.Text = material[1]
end
_________________
I don't know where I'm going, but I'll figure it out when I get there.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum