Strange exception in user_prop_add_enum

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

Message
Author
User avatar
WillemijnL
Posts: 107
Joined: Sat Jan 30, 2016 1:14 pm

Strange exception in user_prop_add_enum

#1 Post by WillemijnL »

The function user_prop_add_enum works fine except in one case. When data is loaded from json with static_data_load and after that you go through the table with a for-loop, then user_prop_add_enum is not working. When the table is created in LUA instead of from the data load, than user_prop_add_enum works fine. It looks like (inside) iterators on tables created by Air Manager have a conflict.

user_prop_add_enum is called after processing the data load, because the data from the data load has to be used in user_prop_add_enum.

Steps without exception:
1. Create table in LUA
2. Loop over the table with a for-loop
3. Call user_prop_add_enum --> user property is available

Steps with exception:
1. Load data with static_data_load to create same table
2. Loop over the table with a for-loop
3. Call user_prop_add_enum --> nil value exception

Log:
ERROR InstrumentScanner - * DEV - My instrument: Error loading instrument script: attempt to index a nil value

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Strange exception in user_prop_add_enum

#2 Post by Keith Baxter »

Hi,

It will always throw out an error msg. You must have error handling.

Code: Select all

my_new_data =static_data_load("data.json")

if my_new_data ~= nil then
	print("Static Data loaded")
else
	print("Static Data NOT loaded")
end)


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
WillemijnL
Posts: 107
Joined: Sat Jan 30, 2016 1:14 pm

Re: Strange exception in user_prop_add_enum

#3 Post by WillemijnL »

I know data load can return nil. But that is not the case. It's all cheched. After the data load the table is available with correct data and the for-loop after the data load is processing the loaded data correctly (step 2). But after that it's going wrong in step 3.

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Strange exception in user_prop_add_enum

#4 Post by Keith Baxter »

Hi,

Yes and on first load the enum is empty, hence the error. It is only populated after the data has loaded on the first pass. You can create a table var to stop this.

Code: Select all

my_new_data ={}
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Strange exception in user_prop_add_enum

#5 Post by Sling »

What you want to do won’t work. User property scanning waits for no one and therefore the data has to be already immediately available. Therefore it has to be hard coded in. Pretty sure this has been discussed on this forum before if you are interested in why.

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Strange exception in user_prop_add_enum

#6 Post by Keith Baxter »

Hi,

It also might be due to calling a incorrect index.
This works in AM4.2 beta13. Not sure if Corjan fixed what Tony says.
arb_data.json
(47 Bytes) Downloaded 39 times

Code: Select all

data = static_data_load("arb_data.json")

if data ~= nil then
  -- Print data
  print(data)
end


-- Let's give our instrument three properties
choice_prop = user_prop_add_enum("Choices", data["1"],data["2"],data["3"], data["1"], "You can choose one of these three choices")

If you change one of the indexes say data["1"] to data["5"] you will get nil error.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
WillemijnL
Posts: 107
Joined: Sat Jan 30, 2016 1:14 pm

Re: Strange exception in user_prop_add_enum

#7 Post by WillemijnL »

That's doesn't help. Even tested user_prop_add_enum with only static strings, so there was no relationship between the data from the data load and user_prop_add_enum. But same behaviour.

But this one removes the nil value exception:

Code: Select all

my_table = static_data_load("my-data.json") or {}
Still missing data for user_prop_add_enum. Going to figure out how I best can fill user_prop_add_enum with kind of flexible data. In case it's not going to work from a json file I have to move the data to a library file, such as this:

Code: Select all

my_table = 
{
    {
        foo="string 1a",
        bar="string 2a"
    },
    {
        foo="string 1b",
        bar="string 2b"
    }
}
Thanks.

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: Strange exception in user_prop_add_enum

#8 Post by SimPassion »

WillemijnL wrote: Thu May 04, 2023 12:17 pm Still missing data for user_prop_add_enum. Going to figure out how I best can fill user_prop_add_enum with kind of flexible data.
We have to handle it inside a function
Here's what I've done using CSV data, though this is the same with JSON file :

Code: Select all

local acf_ident			= {}
local acf_idx			= 0
local cols			= 26

for idx = 1,cols,1
do
	acf_ident[idx]={}
end

function data_loading(data)
	if data == nil then
		if local_debug then
			print("===================================================")
			print("					Aircrafts Data loading issue")
			print("===================================================")
		end
		return
	end
		if local_debug then
			print("===================================================")
			print("					Aircrafts Data loaded")
			print("===================================================")
		end
	for key,value in pairs(data) do
		acf_idx = acf_idx + 1
		acf_ident[1][acf_idx] = value["nr"]
		acf_ident[2][acf_idx] = value["acfdesc"]
		acf_ident[3][acf_idx] = value["paneltype"]
		acf_ident[4][acf_idx] = value["cablightcolor"]
		acf_ident[5][acf_idx] = value["primer"]
		acf_ident[6][acf_idx] = value["carbheataltair"]
		acf_ident[7][acf_idx] = value["hsi"]
		acf_ident[8][acf_idx] = value["spd_u"]
		acf_ident[9][acf_idx] = value["low_s"]
		acf_ident[10][acf_idx] = value["hi_s"]
		acf_ident[11][acf_idx] = value["grd_s"]
		acf_ident[12][acf_idx] = value["lbl_s"]
		acf_ident[13][acf_idx] = value["wht_s"]
		acf_ident[14][acf_idx] = value["wht_e"]
		acf_ident[15][acf_idx] = value["grn_s"]
		acf_ident[16][acf_idx] = value["ylw_s"]
		acf_ident[17][acf_idx] = value["vne"]
		acf_ident[18][acf_idx] = value["rrv"]
		acf_ident[19][acf_idx] = value["rrs"]
		acf_ident[20][acf_idx] = value["brv"]
		acf_ident[21][acf_idx] = value["brs"]
		acf_ident[22][acf_idx] = value["author"]
		acf_ident[23][acf_idx] = value["manufacturer"]
		acf_ident[24][acf_idx] = value["model"]
		acf_ident[25][acf_idx] = value["hp"]
		acf_ident[26][acf_idx] = value["acfname"]

		-- check_data()

	end

	-- display_data()

end

resource_filename = "aircrafts_data.csv"
resource_meta = resource_info(resource_filename)

if resource_meta ~= nil then
	acf_refs = static_data_load(resource_filename)
	data_loading(acf_refs)
else
	if local_debug then
		print("===================================================")
		print("			Aircrafts Data resource file not found")
		print("===================================================")
	end
end


SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: Strange exception in user_prop_add_enum

#9 Post by SimPassion »

Hi @Ralph, I guess there's some small typos there :

https://siminnovations.com/wiki/index.p ... _data_load

Code: Select all

-- person.json is location int he resources folder

-- cars.csv is location int he resources folder

-- cars.txt is location int he resources folder
have to be updated for both Asynchronous and Synchronous sections each time, to :

Code: Select all

-- person.json is located in the resources folder

-- cars.csv is located in the resources folder

-- cars.txt is located in the resources folder
 

User avatar
Ralph
Posts: 7917
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Strange exception in user_prop_add_enum

#10 Post by Ralph »

Fixed, thanks!

Post Reply