ListView - get other parameters

Hi,

I am using tableView to get a new list of items, on my onRelease command I am then running a function however from all the help i’ve seen online the function only has event.target.id available.

What if I want to pass for example a scene and an id so my data would be:

[lua]local data = {}
data[1] = {}
data[1].title = ‘Option 1’
data[1].scene = ‘start’
data[1].passedId = 7
data[2] = {}
data[2].title = ‘Option 2’
data[2].scene = ‘another’
data[2].passedId = 15[/lua]

How would I access the .scene and .passedId options in the onRelease function??

Thanks

Kevin [import]uid: 72726 topic_id: 13954 reply_id: 313954[/import]

Now I’m fairly new to this so I’m guessing you probably have something different in mind, but when I’m trying to access table data through tableview I would use:

data[event.target.id].title
data[event.target.id].sandwichtype
data[event.target.id].portfolio
…etc

eg:

if data[event.target.id].sandwichtype == rye then blargh() end

If my hazy morning memory recalls, when you tap on the list entry, event.target.id = the table entry id for whatever you tapped on.

The only trick to remember is that you need to define the onRelease function(s) before you define the onRelease part of the table. [import]uid: 41884 topic_id: 13954 reply_id: 51337[/import]

[lua]local function changeScene( event )
self = event.target
print(data[self.id].scene)
end

– Create List Data
local data = {}
data[1] = {}
data[1].title = ‘Option1’
data[1].scene = ‘options’
data[2] = {}
data[2].title = ‘Option2’
data[2].scene = ‘settings’

local myList = tableView… [/lua]

On the above, when I click on one of the options in the table view it is telling me that data is not a global variable which it wouldn’t be.

Would I have to set the function after the data creation? If so then surely i’d need the function before the tableview call?
[import]uid: 72726 topic_id: 13954 reply_id: 51338[/import]

Just so you know, yes your way worked IF i move the changeScene function underneath the local data creation.

Shouldn’t be a problem doing it this way though!

Thanks for your help buddy! :slight_smile: [import]uid: 72726 topic_id: 13954 reply_id: 51341[/import]

Try

[code]
local data = {}

local function changeScene( event )
self = event.target
print(data[self.id].scene)
end

– Create List Data

data[1] = {}
data[1].title = ‘Option1’
data[1].scene = ‘options’
data[2] = {}
data[2].title = ‘Option2’
data[2].scene = ‘settings’

local myList = tableView…
[/code] [import]uid: 19626 topic_id: 13954 reply_id: 51345[/import]

Yeah, the problem with making your table first is that if you refer to any functions/variables that aren’t declared yet, they become nil. So I have to do stuff like this, sometimes:

[code]
data = { tablestuff }

myfunction = function()
– dostuff
end

– This basically goes back and injects onRelease into the table.
for i=1,table.maxn(data)
data[i].onRelease = myfunction
end[/code] [import]uid: 41884 topic_id: 13954 reply_id: 51348[/import]

Depends on who’s/which version of ListView you are using, but several of them actually store the data table under:

event.target.data.[any attr of orig data table] [import]uid: 6175 topic_id: 13954 reply_id: 51416[/import]

Is there a list of standard libraries? I seem to stumble across them but don’t actually know where all of them are?

I am using the standard tableview.lua file as far as i know :slight_smile: [import]uid: 72726 topic_id: 13954 reply_id: 51506[/import]