Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 10:43 PM |
| I've already created a way to do this, but I want to see if others think of something simpler. I need to retreive, lets say the 9, from 12493. Can anyone think of anyway to retreive such in a flexible way, allowing for the easy retreival of other values from this #? |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 10:50 PM |
function GetDigit(num, digit) return tonumber(tostring(num):match(tostring(digit))) end
Now you can do:
print(GetDigit(12493, 9))
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 10:53 PM |
Okay. Now how do you retrieve multiple digits? Hehehe my system allows such. |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 10:57 PM |
| Also, you need headers for specifying if something is negative or positive, & where the decimal place would be. |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 10:58 PM |
function GetDigits(num, ...) local args = {...} local digits = {} for k,v in pairs(args) do if tostring(num):match(tostring(v)) then table.insert(digits, v) end end return unpack(tempdigits) end
print(GetDigits(123456789, 3, 4, 5)) |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 11:00 PM |
Why? That function returns all digits in a number regardless of whether it's negative or positive and where the decimal point is.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:07 PM |
Uuh, because you can't extract digits from something like this:
1234.-25025.025 |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:12 PM |
| Lets say I have a 20 digit long whole number which I am using to store four 3 digit values in. 2 digits before each set of 3 would act as a header, with the first digit giving whether the value stored is positive or negative and whether the value used to locate the decimal is positive or negative as well. The second digit would be used to actually locate the decimal. |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:15 PM |
| Of course a system that only allows storing 3 digit values would be ineffective, so one digit to the left of everything before the beginning of a header/value set would specify such. |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:16 PM |
I need to clarify. I'm exausted and I'm leaving details out. 'Such' in the last sentence would be the max # of digits a stored value may consist of. |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:19 PM |
| I must admit, when I originally created this it wasn't with Lua. |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 11:22 PM |
But that's hardly necessary. The function will take digits from any number, positive or negative, decimal or integer.
function GetDigits(num, ...) local args = {...} local digits = {} for k,v in pairs(args) do if tostring(num):match(tostring(v)) then table.insert(digits, v) end end return unpack(tempdigits) end
print(GetDigits(123, 1, 2)) print(GetDigits(1.222223, 1, 3)) print(GetDigits(-5.5789, 7, 9))
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 11:23 PM |
Oh, but just change the function to:
function GetDigits(num, ...) local args = {...} local digits = {} for k,v in pairs(args) do if tostring(num):match(tostring(v)) then table.insert(digits, v) end end return unpack(digits) end
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:27 PM |
| (1234.-25025.025 is interpetted as -23791.025) |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 11:31 PM |
1234.-25025.025?
That isn't even a number.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:37 PM |
9101050000900
First header digit 1 = stored value is positive, value at 2&3 positive 2 = stored value is positive, value at 2&3 negative 3 = stored value is negative, value at 2&3 positive 4 = stored value is negative, value at 2&3 negative
Now copy pasta from the second digit to the last (right most) digit the stuff present until you have a desireable number of addresses. If you go with 5, you will end up with a storage (notice storage not stored) value length in digits of 61, although I'd recommend unincluding the very first digit from that count (so it'd be 60). |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:37 PM |
Exactly. Yet you've asked users of your examples to store stuff without headers to define certain aspects about it. |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:38 PM |
| Left most value in the example is the # of digits in a stored value in storage. There are two header digits used for defining where the decimal place should be. |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 11:39 PM |
Just for the record, RBLX.Lua doesn't have header files.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:40 PM |
| KK. Now stop being lazy and use the digits in the numbers as substitudes. |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 11:42 PM |
WHY? The string.match function returns the digit just by registering it in the overall number. There's NO reason to find out other properties of those digits.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:46 PM |
Lemme help you by spacing out the example of storage values in my system for retreiving such.
9|1|01|050000900|1|01|050000900 First section houses 1 digit, which is used to define for the entire storage value how long each stored value (in digits) is. Second section through fourth sections is an address, starting at the first digit in such. The second section itself is a header with a single digit, which is used to define what is positive and negative. The third section is a header with two digits used to define where the decimal for the stored value should be. The fourth section is the stored value, which in this case is 9 digits long. Another address, sections five through seven. |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2012 11:49 PM |
What language are you even using? There are no headers in RBLX.Lua.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:49 PM |
| *If there is a misinterpretation on my part on your work, you should probably warn me before I continue to spam examples, probably by spamming your own* |
|
|
| Report Abuse |
|
|
Draeton
|
  |
| Joined: 04 Jun 2012 |
| Total Posts: 4269 |
|
|
| 06 Sep 2012 11:50 PM |
| Hey man, why do you keep defining headers in such a sense? You gotta think broader. |
|
|
| Report Abuse |
|
|