Wei Posted June 23, 2012 Share Posted June 23, 2012 local sTations = { { "Power 181", "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription=" }, } addEventHandler( "onClientResourceStart", getRootElement( ), function () for i, n in pairs ( sTations ) do local row = guiGridListAddRow ( stationGridList ) guiGridListSetItemText ( stationGridList, row, column, n[1], false, false ) end end ) function test() local statioN = guiGridListGetItemText ( stationGridList, guiGridListGetSelectedItem ( stationGridList ), 1 ) if station == n[1] then playSound( n[2] ) end end addEventHandler("onClientGUIClick", player, test ) how can I make this work ? I tryed but failed... Link to comment
Castillo Posted June 23, 2012 Share Posted June 23, 2012 You should set the URL as item data. local sTations = { { "Power 181", "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription=" }, } addEventHandler( "onClientResourceStart", getRootElement( ), function ( ) for i, n in pairs ( sTations ) do local row = guiGridListAddRow ( stationGridList ) guiGridListSetItemText ( stationGridList, row, column, n [ 1 ], false, false ) guiGridListSetItemData ( stationGridList, row, column, n [ 2 ], false, false ) end end ) function test ( ) local statioURL = guiGridListGetItemData ( stationGridList, guiGridListGetSelectedItem ( stationGridList ), 1 ) playSound ( stationURL ) end addEventHandler ( "onClientGUIClick", player, test ) Link to comment
Flaker Posted June 23, 2012 Share Posted June 23, 2012 (edited) Try this: (More simple and optimal code.) local sTations ={ ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; } addEventHandler( "onClientResourceStart", getRootElement( ), function () for StationName, StationAdress in pairs ( sTations ) do local row = guiGridListAddRow ( stationGridList ) guiGridListSetItemText ( stationGridList, row, 1, StationName, false, false ) end end ) function test() if source == stationGridList then local row, col = guiGridListGetSelectedItem ( stationGridList ) if ( row and col and row ~= -1 and col ~= -1 ) then local statioN = guiGridListGetItemText ( stationGridList, row, 1 ) playSound( sTations[statioN] ) end end end addEventHandler("onClientGUIClick", getRootElement( ), test ) Edited June 23, 2012 by Guest Link to comment
Wei Posted June 26, 2012 Author Share Posted June 26, 2012 How can I set 2 grid List item data ? Link to comment
Guest Guest4401 Posted June 27, 2012 Share Posted June 27, 2012 How can I set 2 grid List item data ? You can make a table and set multiple item datas as an encoded string, and retrieve as table using toJSON fromJSON Link to comment
Castillo Posted June 27, 2012 Share Posted June 27, 2012 You can save lua tables as item data as well, no need for JSONs. Link to comment
Guest Guest4401 Posted June 27, 2012 Share Posted June 27, 2012 You can save lua tables as item data as well, no need for JSONs.Ok, then the wiki is wrong? Because it's saying bool guiGridListSetItemData ( element gridList, int rowIndex, int columnIndex, string data ) Fourth argument is string and not var Link to comment
Castillo Posted June 27, 2012 Share Posted June 27, 2012 Has to be, I've saved Lua tables before without problems. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now