Einlander Posted June 28, 2017 Share Posted June 28, 2017 I started playing around with the networking in Leadwerks and found that I needed enums. So I wrote a function that will allow you to enumerate a table. function enumerate(array,indexstart) -- indexstart is optional if array == nil then return nil end local array2 = {} local count = tonumber(indexstart) ~= nil and tonumber(indexstart) or 0 for key,value in pairs(array) do array2[value] = count count = count + 1 end return array2 end This will take an array of strings and output a named table array. enum_netchat = enumerate({ "client", "team", "all", "servertoclient", "servertoteam", "servertoall" },1) This is the simplest way to make an enum enum_netchat.all 2 Quote Link to comment Share on other sites More sharing options...
Rick Posted June 29, 2017 Share Posted June 29, 2017 So this results in the below? enum_netchat = { client = 1, team = 2, all = 3, servertoclient = 4, servertoteam = 5, servertoall = 6 } Quote Link to comment Share on other sites More sharing options...
Einlander Posted June 29, 2017 Author Share Posted June 29, 2017 Correct Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.