SkatCh Posted January 20, 2015 Share Posted January 20, 2015 Hi guys please i need a little help , how can i calculate characters per line and after each 20 characters i need to return to the next line . i'm sorry about my english Link to comment
n3wage Posted January 20, 2015 Share Posted January 20, 2015 Use this function: function string.split ( str, count ) if count > string.len(str) then return false end local Linhas = {} local LC = 1 while LC < string.len ( str ) do local linha = string.sub ( str, LC, LC + count -1 ):gsub(" ","") table.insert ( Linhas, linha ) LC = LC + count end return Linhas end Example: myString = "1234567891011121314151617181920abcdefghi" -- 40 Characters allLines = string.split ( myString, 20 ) for _, line in ipairs ( allLines ) do print ( line, line:len() ) end --[[ print: 12345678910111213141 20 51617181920abcdefghi 20 --]] Link to comment
SkatCh Posted January 20, 2015 Author Share Posted January 20, 2015 i don't know why didn't work with dxDrawText just one line appear , all what i need how to resize the dxRectangle i tried this but did work. just a part from my script: -- Your example ofc with string.split function myString = "1234567891011121314151617181920abcdefghi" -- 40 Characters allLines = string.split ( myString, 20 ) function testDx() for _, line in ipairs ( allLines ) do -- i add my code here to call the Dx function end addCommandHandler("test",testDx) -- And i add this to get the text width (it's correct or not) -- settings tabe (bla , bla) local X = dxGetTextWidth(string.gsub(line,"%#%x%x%x%x%x%x",""),settings.fontHeight,settings.font)+20*settings.scale local Y = dxGetFontHeight(settings.fontHeight,settings.font)*2+40*settings.scale Link to comment
.:HyPeX:. Posted January 20, 2015 Share Posted January 20, 2015 Search down this forum,i remember there was a topic about this. And by the way, string.split is a useful function, you added it into the script? (Also check debug) 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