passing a table's 'address' as a function argument

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

passing a table's 'address' as a function argument

Postby parthmbhatt » Tue May 29, 2018 1:04 pm

I'm trying to create a simple function that repopulates a table in crank based on which table name is passed on to the function as an argument

How I'm trying to go about this is:
1) I have a script that stores 3 tables in a larger table ALL_SCROLLING_LISTS
2) In the crank storyboard interface, I have the lua Function CBRefreshTable with argument scrolling_table_1 fire when the screenshow.pre event occurs, like so:
Capture.JPG
Capture.JPG (19.7 KiB) Viewed 421 times


3) I'm using the for in pairs loop to fill the local table tablePressed with the values from the required table (this is where I'm failing)
4)I want to use this table to then populate the crank table

this is the code I'm using:

Code: Select all
require("table_data")


--Function to re draw table. argument should be table name
function CBRefreshTable(dat)
local tablePressed={}
for i,v in pairs(All_SCROLLING_LISTS.dat) do
tablePressed[i] = v
end

--I'm printing this value because it tells me whether or not tablePressed has taken on the values of the table I need
 print(#tablePressed)
--print(tablePressed)
--print(All_SCROLLING_LISTS[scrolling_table_1])

--Assign table parameters based on the selected table
local table_data = {}
table_data["rows"] = #tablePressed
gre.set_table_attrs("Scroll_layer.scroll_table",table_data)

--iterate through the table and assign the values to the crank table "Scroll_layer.scroll_table"
for i=1,table_data.rows do
gre.set_value("Scroll_layer.scroll_table.text."..i..".1",tablePressed[i])

end

end



I'm having trouble finding the right syntax to be able to dynamically populate the table based on which argument is passed to the function (I'd like to have it so that if I go to the next screen, the argument becomes scrolling_table_2 and so on

Thank you for your help!
Attachments
Scrollbar test.zip
(83.58 KiB) Downloaded 35 times
parthmbhatt
 
Posts: 5
Joined: Tue May 29, 2018 12:38 pm

Re: passing a table's 'address' as a function argument

Postby MikeMarchand » Tue May 29, 2018 2:33 pm

If I understand correctly, you are having trouble accessing the argument which you passed into your Lua Action callback.

Code: Select all
--- @param gre#context mapargs
function CBRefreshTable(mapargs)
  local tableName = mapargs.NewArg
  print(tableName, ALL_SCROLLING_LISTS[tableName])
end


Lua Action callback functions receive one parameter, a table which contains all the relevant context for the current action, this table also contains all the arguments which are passed into the Lua Action. In your case there is one Action, it is called NewArg and the value is a "scrolling_table_1". These arguments are always strings.

Hopefully this helps.
-Mike
MikeMarchand
 
Posts: 27
Joined: Wed Jan 21, 2015 3:33 pm

Re: passing a table's 'address' as a function argument

Postby parthmbhatt » Tue May 29, 2018 3:39 pm

Hi Mike!

This solved it! thanks!
parthmbhatt
 
Posts: 5
Joined: Tue May 29, 2018 12:38 pm


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron