generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Game Design
Home Search
 

Re: Finding the value of each individual digit?

Previous Thread :: Next Thread 
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 09:36 AM
string.len can get the length of an IntValue, thankfully. a value of 4735 has a length of 4. 853 has a length of 3, etc etc

Like some kind of For Loop where it uses string.len to decide how many times it needs to cycle through.

Like this, I tested this out in studio.

> for i = 1, (string.len(game.Workspace.TestValue.Value)), 1 do print("Test #"..i) end
Test #1
Test #2
Test #3
Test #4

So somehow, during the For Loop, there's got to be a function or method or whatever to use i from the for loop to call for the digit in that place of the value and tell me what it is.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 09:40 AM
For example, if the Value was 1337, the length would be 4 digits long. Therefore my little test has a FOR loop that goes from 1 to 4, and then during each loop cycle it uses i to find each value place, like if i == 2, then the value would be 3 or if i == 4 then the value of the digit would be 7. See where I'm going with this?

There's gotta be some method I'm missing to call for individual digits in a value. My gut tells me it has something to do with string.??? and the %d thingy or something. I have no idea...
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 09:51 AM
I can't find the index in the wiki on strings with the chart that explains % and d and everything.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 09:57 AM
Ok I found the wiki page on string patterns but it didn't help at all.

Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 10:23 AM
So what I'm thinking is something that uses the value of i to get the digit corresponding to the value of i, but I have no idea how. I know there's a way. I've seen it before but I just can't remember it.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
08 Dec 2015 10:31 AM
You could do something like this:

local Text = tostring(game.Workspace.TestValue.Value) -- we have to convert it to a string so we can use string.sub with it

for i = 1,#Text do -- # is faster than string.len but only works with tables and strings.
print("Place #" .. i .." = ",string.sub(Text,i,i))
end
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 10:37 AM
Now see that looks familiar. I'll check it out
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 10:42 AM
ok well it certainly works but I have absolutely no idea how to call for the value still.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 10:43 AM
Unless... hold on let me try something. Don't give me the whole answer lol
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 10:49 AM
local Text = tostring(game.Workspace.TestValue.Value)

for i = 1,#Text do
print("Place #" .. i .." = ",string.sub(Text,i,i))

local FakeDigit = tonumber(string.sub(Text,i,i))
if FakeDigit == 7 then
print("We got a 7!") end

end

Place #1 = 1
Place #2 = 3
Place #3 = 3
Place #4 = 7
We got a 7!


Ok, well it doesn't feel exactly the same as the last time I got help on this, but I think it might actually work.
I can use the if statement to check for zeros lol because I think tables only go from 1 to inifinity. Table[1], Table[2], etc etc

I greatly appreciate this and thank you for putting up with me. If roblox had a wider range of fonts this wouldn't even be necessary... lol...
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
08 Dec 2015 11:27 AM
Yup! Got it! lol


local Img1 = script.Parent:GetChildren()
for i = 1, #Img1 do if Img1[i].className == "ImageLabel" then
Img1[i]:Destroy() end end

local Text = tostring(game.Workspace.TestValue.Value)
local Table = {
"http://www.roblox.com/asset/?id=177229884",
"http://www.roblox.com/asset/?id=177229863",
"http://www.roblox.com/asset/?id=177229834",
"http://www.roblox.com/asset/?id=177229807",
"http://www.roblox.com/asset/?id=177229781",
"http://www.roblox.com/asset/?id=177229714",
"http://www.roblox.com/asset/?id=177229681",
"http://www.roblox.com/asset/?id=177229652",
"http://www.roblox.com/asset/?id=177229619",
"http://www.roblox.com/asset/?id=177229909"
}

BPosi = 100
BSize = 60

for i = 1,#Text do

local FakeDigit = tonumber(string.sub(Text,i,i))

if FakeDigit == 0 then
local Img2 = Instance.new("ImageLabel")
Img2.Parent = script.Parent
Img2.Size = UDim2.new(0, BSize, 0, BSize)
Img2.Position = UDim2.new(0, BPosi+(Img2.Size.X.Offset*0.6)*i, 0, 20)
Img2.BackgroundTransparency = 1
Img2.Image = Table[10]
else
local Img2 = Instance.new("ImageLabel")
Img2.Parent = script.Parent
Img2.Size = UDim2.new(0, BSize, 0, BSize)
Img2.Position = UDim2.new(0, BPosi+(Img2.Size.X.Offset*0.6)*i, 0, 20)
Img2.BackgroundTransparency = 1
Img2.Image = Table[FakeDigit]
end
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image