|
| 07 Dec 2015 09:46 PM |
A few months ago I had someone help with with a little function to display numbers from ImageLabels instead of TextLabels.
It had something to do with the asset ids in a table or something, and tostring or tonumber. I don't remember what it was. I know I saved it, but for the life of me I can't seem to find it. Can anyone help me here?
Like if a value is 5, then the decal for 5 is shown. If the value is 12, then 2 decals are shown, images displaying custom fonts for 1 and 2 to show 12. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 07 Dec 2015 11:23 PM |
local Create -- simple create utility I made
do local Items = {} local Set = function(p,n,v) p[n] = v end Create = function(n) if Items[n] then return Items[n] else if pcall(Instance.new,n) then local i = function(args) local n = Instance.new(n) for i,v in next, args do pcall(Set,n,i,v) end return n end Items[n] = i return i end end end end
local NewImageLabel = Create("ImageLabel") local NewFrame = Create("Frame")
local ConvertTextToGui = function(text,pics,x,y) local Base = NewFrame{ Size = UDim2.new(0,0,0,0), Name = text, BackgroundTransparency = 1, } local YLevel = 0 local XLevel = 0 local XExtent = 0 local LSize = UDim2.new(0,x,0,y) for l in text:gmatch(".") do if l == "\n" then YLevel = YLevel + 1 XLevel = 0 elseif l == " " then -- space XLevel = XLevel + 1 if XLevel > XExtent then XExtent = XLevel end elseif l == "\t" then -- tab XLevel = XLevel + 4 if XLevel > XExtent then XExtent = XLevel end elseif pics[l] then local L = NewImageLabel{ Parent = Base, Name = l, Size = LSize, BackgroundTransparency = 1, Image = pics[l], Position = UDim2.new(0,x*XLevel,0,y*YLevel) } XLevel = XLevel + 1 if XLevel > XExtent then XExtent = XLevel end end end Base.Size = UDim2.new(0,x*XExtent,0,y*(YLevel+1)) return Base end
local GuiText = ConvertTextToGui( "Some text thing", { ["S"] = "rbxassetid://someimageid", ["o"] = "rbxassetid://someimageid", ["m"] = "rbxassetid://someimageid", ["e"] = "rbxassetid://someimageid", ["t"] = "rbxassetid://someimageid", ["x"] = "rbxassetid://someimageid", ["h"] = "rbxassetid://someimageid", ["i"] = "rbxassetid://someimageid", ["n"] = "rbxassetid://someimageid", ["g"] = "rbxassetid://someimageid", }, 20, -- 20 pixels wide 20 -- 20 pixels tall )
GuiText.Parent = SomeGuiRenderingLocation |
|
|
| Report Abuse |
|
|
|
| 08 Dec 2015 09:05 AM |
This doesn't look familiar at all, and I don't understand it one bit. I'm not trying to sound picky, I just don't think it has to be that complicated. I don't remember the last one being so long.
It got the length of the IntValue, found the numbers, and then grabbed assets from a table to dynamically create ImageLabels to represent the numbers.
If the value was 5, it used a for loop to create 1 image with the number 5 drawn on it. If the value was 12 it used the same for loop to create two images with the numbers 1 and 5 drawn on them respectively, placing the second image Size.X.Offset to the right of the first image.
I believe it was you Chimmihc, who did it for me the first time. do you not remember how you did it? It was so simply made yet it worked wonderfully. |
|
|
| Report Abuse |
|
|
|
| 08 Dec 2015 09:15 AM |
Please don't mistake my disagreement with ungratefulness. I know you took time out of your day to help me, but even so I must respectfully refuse this. I simply cannot use code that I do not understand. It would make updating impossible lol
I will save it, however, and as I understand Lua more I might even understand this. |
|
|
| Report Abuse |
|
|
|
| 08 Dec 2015 09:19 AM |
| I guess I'll have to try to recreate it. string.len works on IntValues, but how do I "detect" what the numbers actually are? |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 08 Dec 2015 10:15 AM |
It works with numbers as well, just tostring the value when passing it as an arg.
local Numbers = { ["1"] = "rbxassetid://someimageid", ["2"] = "rbxassetid://someimageid", ["3"] = "rbxassetid://someimageid", ["4"] = "rbxassetid://someimageid", ["5"] = "rbxassetid://someimageid", ["6"] = "rbxassetid://someimageid", ["7"] = "rbxassetid://someimageid", ["8"] = "rbxassetid://someimageid", ["9"] = "rbxassetid://someimageid", ["0"] = "rbxassetid://someimageid", }
local GuiText = ConvertTextToGui( tostring(intvalue.Value), Numbers, 20, -- 20 pixels wide 20 -- 20 pixels tall )
GuiText.Parent = SomeGuiRenderingLocation |
|
|
| Report Abuse |
|
|
|
| 08 Dec 2015 10:20 AM |
I have no doubt that it works, Chi. You're good at what you do but I can't use it because I don't understand it. You used so many variables and... I have no idea. It's absolutely confusing and just completely fries my brain when I try to read it.
http://forum.roblox.com/Forum/ShowPost.aspx?PostID=179316536
Take a look at this instead. I've already got the start of something going but without a way to call for the digits themselves it's pretty stuck. |
|
|
| Report Abuse |
|
|