
What I want to do, is to read the waypoints directory and print out that files in three columns. (goal is to select a path from the list)
Now I have the strange result, that column 1 is empty and column 2 disapers (= nil) and only column 3 works. And in column 3, at the last line there is as a strange content the value "column_nr" ( Thats the name I use as I define the table).
If someone could give me a hand. Just enter that code in bot.lua before line 231
Code: Select all
load_paths(wp_to_load, rp_to_load); -- load the waypoint path / return path
Code: Select all
-- ********** BEGIN OF NEW STUFF
-- choose a path from the waypoints folder
local dir = getDirectory(getExecutionPath() .. "/waypoints/");
local pathlist = { }
printf("Waypoint files in %s:\n", getExecutionPath());
-- copy table dir to table pathlist
-- select only xml files
local hf_counter = 0;
for i,v in pairs(dir) do
if( string.find (v,".xml",1,true) ) then
hf_counter = hf_counter + 1;
pathlist[hf_counter] = v;
end
end
local hf_max_rows = math.ceil(table.getn(pathlist) / 3 ); -- how many rows to output by 3 column
hf_print_table = { row = { column = { column_nr = { } } } }; -- DEFINE1
local hf_row = 0;
local hf_column = 1; -- start in column 1
-- copy entrys from table pathlist to a new table 'hf_print_table'
-- arrange in three columns
for i,v in pairs(pathlist) do
hf_row = hf_row + 1;
if( hf_row > hf_max_rows ) then -- switch column after maxrow
hf_column = hf_column + 1;
hf_row = 1;
end
hf_print_table[hf_row] = { column = { {} } };
hf_print_table[hf_row].column[hf_column] = { };
-- I don't understand why I need the two lines above???
-- shouldn't the table be defined through the DEFINE1 line?
hf_print_table[hf_row].column[hf_column].nr = i; -- remember nr of the entry
hf_print_table[hf_row].column[hf_column].filename = v; -- waypoint filename
printf("i %s, row %s, col %s: %s \n", i, hf_row, hf_column, hf_print_table[hf_row].column[hf_column].filename);
end
printf("tentrys %s\n", table.getn(hf_print_table) ); -- number of entries in table
-- printout the table with the columns
for i,v in pairs(hf_print_table) do
printf("test row %s \n", i );
local line = "";
-- if( v.column[1].filename ~= nil ) then
-- line = v.column[1].nr..": "..v.column[1].filename;
-- end
-- if( v.column[2].filename ~= nil ) then
-- line = line .. v.column[2].nr..": "..v.column[2].filename;
-- end
for h,cols in pairs(v.column) do
printf("test column %s \n", h );
-- problem here:
-- column 1 is empty
-- column 2 is nill
-- only column 3 has the right values, but also at the end there are strange values: string "column_nr"
if( cols.filename ~= nil ) then
printf("row %s column %s filenr %s %s\n", i, h, cols.nr, cols.filename );
end
-- if( v.column[3].filename ) then
-- line = line .. v.column[3].nr..": "..v.column[3].filename;
-- end
end
end
printf("Enter the number of the path you want to use:\n");
-- later, if the table works :-(
-- ********** END OF NEW STUFF
load_paths(wp_to_load, rp_to_load); -- load the waypoint path / return path
-- special option for use waypoint file from profile in a reverse order / not if forced path
if( settings.profile.options.WAYPOINTS_REVERSE == true and
not forcedPath ) then
__WPL:reverse();
end;