Nonameman Posted July 14, 2011 Share Posted July 14, 2011 Hey! I have more than 40 pictures in my resource's image folder, and I wanna create them when a client player clicks on a gui button. I want to show only 1 picture in the same time, from a table, but I dunno how to fill up it first. (the table would contains the name of the files, without ".png") How can I do the filling? Thanks Nonameman Link to comment
JR10 Posted July 14, 2011 Share Posted July 14, 2011 filling?, once you made the table no need for filling. You want it random? If so here how you can get a random element from a table: local randomElement = theTable[math.random(#theTable)] Link to comment
Nonameman Posted July 14, 2011 Author Share Posted July 14, 2011 On filling I mean that you said, creating the table with the variables. So my problem is the creation of it, how to get the picture names from the folder. Manually, it'd take a long time. Link to comment
#Paper Posted July 14, 2011 Share Posted July 14, 2011 filling?, once you made the table no need for filling.You want it random? If so here how you can get a random element from a table: local randomElement = theTable[math.random(#theTable)] how said JR10, u can use a random: this can be the img path: "img/"..theTable[math.random(#theTable)]..".png" Link to comment
JR10 Posted July 14, 2011 Share Posted July 14, 2011 Something like this: local images = {} for i, image in ipairs(getResourceFiles(getThisResource(), ".png")) do table.insert(images, image) end triggerClientEvent("recieveImagesTable", root, images) function getResourceFiles(resource, ext) local filesTable = {} ext = ext or "" local meta = xmlLoadFile(":"..getResourceName(resource).."/meta.xml") if meta then local i = 0 while xmlNodeGetChildren(meta, i) ~= false do local node = xmlNodeGetChildren(meta, i) local src = xmlNodeGetAttribute (node, "src") if src then if src:lower():find(ext) then table.insert(filesTable, src) end end i = i + 1 end xmlUnloadFile(meta) end return filesTable end Link to comment
Nonameman Posted July 14, 2011 Author Share Posted July 14, 2011 Uhh, yes, thanks a lot! I have only one questions about this code: if src:lower():find(ext) then What's that? I've never seen ':' in lua, so I do not how is it works. Link to comment
JR10 Posted July 14, 2011 Share Posted July 14, 2011 Well look at this code: string.find("blabla", "bla") string.lower("BLABLA") Which is exactly the same as local str = "blabla" str:find("bla") local str = "BLABLA" str:lower() And here strings tutorial: http://lua-users.org/wiki/StringLibraryTutorial Link to comment
Nonameman Posted July 14, 2011 Author Share Posted July 14, 2011 So str:lower():find("xyz") has 2 string operation in 1. Thanks again, and sorry for noobish questions. 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