Scripting Moderators srslyyyy Posted January 28, 2019 Scripting Moderators Share Posted January 28, 2019 (edited) Hey, today a problem appeared, i need to do something but i don't know how i can solve it. 1. How can i get text length of everything what's in the table. 2. If length atleast of one value from table will be >= 25 then do something for everything. Code: local textTable = { "abcdefghijklmnopqrstu", -- 21 "abcdefghijklmnopqrstu123", -- 24 "abcdefghijklmnopqrstu124", -- 25 } addEventHandler("onClientRender", getRootElement(), function() if getPedOccupiedVehicle(getLocalPlayer()) then return end for k, v in pairs(textTable) do dxDrawingColorTextMenuScroll(v, 6, 350 + k * boxSpace, 6, 350 + (k + 1) * boxSpace, tocolor(255, 255, 255, 255), 170, 1, "sans", "left", "center") if string.len(v) >= 25 then -- problem is here, this works only for the value which have text >= 25 -- do something for everything in table else -- otherwise end end end) Edited January 28, 2019 by majqq Link to comment
nurfaizfy19 Posted January 28, 2019 Share Posted January 28, 2019 22 minutes ago, majqq said: local textTable = { "abcdefghijklmnopqrstu", -- 21 "abcdefghijklmnopqrstu123", -- 24 "abcdefghijklmnopqrstu124", -- 25 -- this string length is the same as above } I think your code is correct, but you missed one string Link to comment
Scripting Moderators srslyyyy Posted January 28, 2019 Author Scripting Moderators Share Posted January 28, 2019 Just now, nurfaizfy19 said: I think your code is correct, but you missed one string What? Code is correct, but i need to make it on other way, this is no answer for my questions. Link to comment
Moderators DNL291 Posted January 28, 2019 Moderators Share Posted January 28, 2019 I really didn't understand what your issue is. What exactly do you want to do in the scope at line 12? Link to comment
Scripting Moderators srslyyyy Posted January 28, 2019 Author Scripting Moderators Share Posted January 28, 2019 1 minute ago, DNL291 said: I really didn't understand what your issue is. What exactly do you want to do in the scope at line 12? I need to get length of all values from table. If atleast one value text length it's >= 25 then i need to do something. Sorry i can't explain it better for now. Link to comment
Moderators DNL291 Posted January 28, 2019 Moderators Share Posted January 28, 2019 I think I understood it now. Getting the length of all values from table: local totalLength = 0 for _,s in ipairs(textTable) do totalLength = totalLength + s:len() end print( totalLength ) Checking if at least one value is >= than 25: local textTable = { "abcdefghijklmnopqrstu", "abcdefghijklmnopqrstu123", "abcdefghijklmnopqrstu124", } local lengthsGreaterThan25 = 0 for _,s in ipairs(textTable) do if s:len() >= 25 then lengthsGreaterThan25 = lengthsGreaterThan25 + 1 end end print( lengthsGreaterThan25 ) 1 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