Moderators IIYAMA Posted January 24, 2014 Moderators Posted January 24, 2014 Hey, I am trying to make a label text fit able, but I am ending up at an infinity loop. Anybody has a solution? local maxLabelSizeTable = {40,40,40,40,40} local makeTextFitForGrid = function (element,index) local text = guiGetText ( element ) local size = guiLabelGetTextExtent ( element ) outputChatBox(size) local maxSize = maxLabelSizeTable[index] if size > maxSize then repeat guiSetText( element,string.sub(text,1,-2)) size = guiLabelGetTextExtent ( element ) until maxSize > size local text = guiGetText ( element ) guiSetText( element, text .. "..") end end Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Sasu Posted January 25, 2014 Posted January 25, 2014 Because you have to update the variable "text" each time you change the gui text. Try this: local maxLabelSizeTable = {40,40,40,40,40} local makeTextFitForGrid = function (element,index) local text local size = guiLabelGetTextExtent ( element ) outputChatBox(size) local maxSize = maxLabelSizeTable[index] if size > maxSize then repeat text = guiGetText(element) guiSetText( element,string.sub(text,1,-2)) size = guiLabelGetTextExtent ( element ) until maxSize > size text = guiGetText(element) guiSetText( element, text .. "..") end end State: Inactive
Moderators IIYAMA Posted January 25, 2014 Author Moderators Posted January 25, 2014 oh lol Thanks! Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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