View Full Version : Removing commas from int_to_string?
muffins
04-28-2006, 08:27 PM
I'm trying to create a script that sends a variable amout of meat to each of my clanmates at the end of each daily run, but when I convert the int to a string and use it with the send function, it only sends the "second half" of the amount, i.e., if I were sending someone 1,234 meat, it would only send them 234 using cli_execute("send " + int_to_string(sendmeat) + " meat to playernamehere")
This causes the message send to fail, and the mafia ends up sending a less than three shaped box with the same amount of meat (meaning I've also lost 100 meat as well). :(
Is there any way to strip commas from the int_to_string, or is there another, better way that I could execute this?
Thanks in advance.
Edit: I did just realize I could just convert the meat to the equivalent amount of meat paste, but if at all possible, I would like to avoid such complications...
Tirian
04-28-2006, 08:56 PM
string my_int_to_string (int number)
{
string foo;
foo = int_to_string(number % 10);
while (number>10)
{
number = number/10;
foo = int_to_string(number % 10) + foo;
}
return foo;
}
void main()
{
print(int_to_string(1234567));
print(my_int_to_string(1234567));
}
muffins
04-29-2006, 12:58 AM
Ohhh, thank you!
efilnikufecin
04-29-2006, 05:51 AM
I see a second person has had the same problem with commas ;D I took my issue to the kol forums, and got pretty much the same answer.
Tirian
04-30-2006, 07:09 PM
It's true that this script is impacted by seeing Holatuwol's sample on the main forums. My original version wasn't quite this pretty.
However, my original version was more correct. ::) The script I posted earlier doesn't parse numbers like 1000 correctly. Gee, I was wondering why I was having trouble hitting my clan stash up for Meat maids. :) A corrected version is below.
Also, for what it's worth, it may be that Veracity just checked in a change so that the default behavior for int_to_string is commaless. If that is the case, then this function will be extraneous when 7.2 is released.
---
string my_int_to_string (int number)
{
string foo;
foo = int_to_string(number % 10);
while (number>=10)
{
number = number/10;
foo = int_to_string(number % 10) + foo;
}
return foo;
}
void main()
{
print(int_to_string(1234567));
print(my_int_to_string(1234567));
}
Veracity
04-30-2006, 07:40 PM
Also, for what it's worth, it may be that Veracity just checked in a change so that the default behavior for int_to_string is commaless.
It may be that I did that.
For whatever reason, I'm not too sympathetic to people trying to cons up raw URLs, but creating a cli "send" command on the fly like the original poster wanted to do doesn't annoy me.
This whole business of dynamically creating strings to pass to cli_execute bemuses me. That's the equivalent of calling (eval) in Lisp, and the general rule in that language is that doing so is almost always incorrect. However, ASH is not a strict superset of the regular CLI and we don't have (apply), so I guess that technique is necessary...
Hmm. I used to be a Lisp implementor. Perhaps that's what we should have, instead of ASH. What do you think? :D
Powered by vBulletin® Version 4.1.12 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.