tigerman Posted March 20, 2011 Share Posted March 20, 2011 Hello dear community members, i need some help here i have table but i need to find from there single word, for example "car-infernus" could someone tell me function for that ? like to find from string i need string.find but what about tables ? -- Thanks Link to comment
Moderators Citizen Posted March 20, 2011 Moderators Share Posted March 20, 2011 Hi, There are no function for that ( except the string.find like you said ) You have to create a loop in which the server get 1 by 1 a word from the table then make a string.find if in a loop it return true, you can break the loop and make your instructions. Put here your table ( all we need for understand the table ) Link to comment
tigerman Posted March 20, 2011 Author Share Posted March 20, 2011 function test (thePlayer,commandname,map1) local mapTable = {} for i, maps in ipairs(exports.mapmanager:getMapsCompatibleWithGamemode(getResourceFromName("race"))) do table.insert(mapTable, getResourceInfo(maps, "name")) end end addCommandHandler("test",test) and now it has to find map from mapTable with that name what was in command Link to comment
Callum Posted March 20, 2011 Share Posted March 20, 2011 You can set the item key as a string, and then call the string later on like 'tableName["item"]', instead of looping the whole table every time. Link to comment
Moderators Citizen Posted March 20, 2011 Moderators Share Posted March 20, 2011 You want to get the resource to start ? whith his name ? Link to comment
tigerman Posted March 20, 2011 Author Share Posted March 20, 2011 just name to outputChatBox would be nice.. then i can continue by myself Link to comment
Moderators Citizen Posted March 20, 2011 Moderators Share Posted March 20, 2011 ok try this but what do you want to do exactly ? function foundMap( thePlayer, commandName, map ) if map then local mapName = tostring( map ) for k,i in ipairs ( mapTable ) do outputChatBox( "if "..i[1].." == "..mapName, thePlayer ) if ( tostring(i[1]) == tostring(mapName) ) then outputChatBox( "I found ! It's "..tostring(i[1]), thePlayer, 180, 0, 0 ) break end end else outputChatBox("/test2 [mapName]" ) end end addCommandHandler("test2",foundMap) Link to comment
tigerman Posted March 21, 2011 Author Share Posted March 21, 2011 line 5 says error "attempt to concatenate field '?' (a nil value)" Link to comment
Dre-+- Posted March 21, 2011 Share Posted March 21, 2011 function table.find(tabl,word) if type(tabl) ~= "table" or word == nil then return false else local ret = false for k,v in pairs(tabl) do if v == word then return k end end end end Now you can use: table.find(yourtable,whatfind) Link to comment
tigerman Posted March 21, 2011 Author Share Posted March 21, 2011 Thanks Dre, works perfect also thanks to Citizen for trying to help me this forum would be useless without you 2 Link to comment
Castillo Posted March 22, 2011 Share Posted March 22, 2011 "this forum would be useless without you 2" I don't think that's correct, many others are helping in the forum, not just them. Link to comment
Moderators Citizen Posted March 22, 2011 Moderators Share Posted March 22, 2011 Haha Yeah tigerman forgot you SolidSnake But he can't know every scripters who helping others Link to comment
Castillo Posted March 22, 2011 Share Posted March 22, 2011 I won't him to name every scripter here, just is unfair to say just two are helping 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