lua - Check if table value starts with -


local maps = find.file("maps/*.bsp", "game") map = (maps[math.random( #maps )])     print("map randomized " .. map ) 

this code above works on "ulx" on garry's mod, uses find.file read directory of garrysmod/maps , return (in table) of files in ending .bsp (all of maps), not wan't include maps begin parts, "arena_" , "gm_", there way can go removing them and/or making keep checking until gets map not beginning that.

any way this? , preferable pure lua please. oh , site i'm using test moaifiddle

it looks function meant file.find instead of find.file. http://wiki.garrysmod.com/page/file/find

the following should work in garry's mod.

local maps = {} local ignoredprefixes = {"gm_","arena_"}  _,map in ipairs(find.file("maps/*.bsp", "game"))do   local hasprefix=false   _,prefix in ipairs(ignoredprefixes)do     if string.left(map,string.len(prefix)) == prefix       hasprefix=true       break     end   end   if not hasprefix     table.insert(maps,map)   end end  local randommap = table.random(maps);  print("map randomized "..randommap) 

what read maps in maps/ , add maps not have prefix, defined in ignoredprefixes, maps table. when done doing so, random map selected table.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -