 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
paul44 Expert Cheater
Reputation: 3
Joined: 20 Jul 2017 Posts: 221
|
Posted: Sat Jun 27, 2026 3:38 am Post subject: Bypass error for non-existing item in table [Solved] |
|
|
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
Last edited by paul44 on Sun Jun 28, 2026 7:35 am; edited 1 time in total |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 155
Joined: 06 Jul 2014 Posts: 4774
|
Posted: Sat Jun 27, 2026 12:23 pm Post subject: |
|
|
| paul44 wrote: | | Unfortunately, i can not remember the exact error |
Attempt to index a nil value
Check if it's nil
| Code: | 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. |
|
| Back to top |
|
 |
paul44 Expert Cheater
Reputation: 3
Joined: 20 Jul 2017 Posts: 221
|
Posted: Sun Jun 28, 2026 7:34 am Post subject: solved... |
|
|
Just did a quick test and working.
I actually did check for nil... on 'aBlueprnt[Dev_Req_Bluepr][1]'. and if my logic is right, my check came in a bit too late ?!
=> Lua falls over the "previous" object, being 'aBlueprnt[Dev_Req_Bluepr]'
yep, a lot simpler and surely "faster"
thx
ps: error 'attempt to index a nil value (?field)' (or something in those lines)
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 155
Joined: 06 Jul 2014 Posts: 4774
|
Posted: Sun Jun 28, 2026 12:03 pm Post subject: |
|
|
| paul44 wrote: | | I actually did check for nil... on 'aBlueprnt[Dev_Req_Bluepr][1]'. and if my logic is right, my check came in a bit too late ?! | Yes. The `[1]` tries to index a nil value. That's why you need to check if `aBlueprnt[Dev_Req_Bluepr]` is nil.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
|
|
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
|
|