Is there a way to break down a 4-digit number into 4 separate digits?
ie. turn var/something=1746 into
var/somea=1
var/someb=7
var/somec=4
var/somed=6
Thanks.
ID:165875
Oct 20 2006, 10:46 pm
|
|
In response to Jp
|
|
That lost me.
setmoney(n as num) Eh? Before that it was: setmoney(n as num) |
In response to FireEmblem
|
|
FireEmblem wrote:
It's been about 15 hours.. So it has and why are you bumping the topic.. People have better things to do than refreshing byonds forum page to answer questions just be patient |
In response to A.T.H.K
|
|
I know that, I've been here long enough to know something as simple as that, but it was on page 2, so I was just bumping it.
|
In response to FireEmblem
|
|
The rules are actually that you have to wait till it's off the front page AND it's been 24 hours.
As for your problem, Jp's proc returns a list of digits. You're not meant to combine it into your moneycheck() proc, you're meant to create a list in your moneycheck() proc and have that list equal to Jp's proc like so:
var/list/digits = breakup(n,digits)
And use that list in order to do what ever it is you want to. |
In response to DeathAwaitsU
|
|
mob That gave me the runtime error: runtime error: list index out of bounds |
In response to FireEmblem
|
|
I think Jp's proc doesn't work. Here's something I quickly wrote up:
proc Then applying this to your verb would be: mob *Edit* Changed the num2text() SigFig argument a bit. Also, I just realised this won't work at all for non-integer numbers or for negative numbers. For negative numbers, I suggest editing get_digits() to check if the number is less than 0. If it is, abs() the whole number and do everything as normal. But before returning the list, make the first element in the list negative. But you may want to make everything in the list negative - it really depends on how you want to do it. For non-integer numbers, work out where the decimal point is. After doing so, multiply the number by 10^n, where n represents where the decimal point is, and then use get_digits() on the new number. So if your number was 6345.6778, you'd want to multiply it by 10^4 which would result in 63,456,778. *Edit 2* If you want some help on working out where the decimal point is, num2text() the number first. Then use findtext() to locate the decimal point, which would just be ".". *Edit 3* I think I'll just point this out before someone comments on it. mob That will give you a "list index is out of bounds" runtime error if the digits list isn't long enough (which means the number you put in was less than 1000, assuming we're dealing with positive real integer numbers). I'll leave it up to you to figure out how to modify usr.ru based on digits.len. |
In response to DeathAwaitsU
|
|
Thanks! One thing though, do I need to make a new proc and verb for each amount of money (there won't actually be verbs to gain money, just testing) for different numbers of digits? For example, I can't enter in 999, 99 or 9.
|
In response to FireEmblem
|
|
FireEmblem wrote:
Thanks! You're welcome. One thing though, do I need to make a new proc and verb for each amount of money (there won't actually be verbs to gain money, just testing) for different numbers of digits? For example, I can't enter in 999, 99 or 9. I don't get what you mean. get_digits() should return individual digits for 999, 99 and 9. You don't need to tell it how many digits your number has. |
In response to DeathAwaitsU
|
|
Oh wait. I see how to fix this. Nevermind. Thanks again.
|
In response to DeathAwaitsU
|
|
.len? Wha? I was just thinking that I'd do a check to see if it's a 3 digit number, 2 digit number, etc with if()s and then choose to exclude ru4 if it's 3 digits, ru3 if it's 2 digits, etc..
|
In response to FireEmblem
|
|
You could do that, but there are other less if()fy ways.
|
There may be something better, I just hacked that up then. :P