| www.ClassicTW.com http://www.classictw.com/ |
|
| Removing a decimal http://www.classictw.com/viewtopic.php?f=15&t=33158 |
Page 1 of 1 |
| Author: | T0yman [ Thu Apr 12, 2012 6:28 am ] |
| Post subject: | Removing a decimal |
I was messing this morning since I have been playing alot lately with the cuttext command and figured this might snippet might solve the issue. If by chance the number has no decimal it will skip and setvar for you. I think this is what your asking. SteveH_66 wrote: It seems the game doesn't choke when you send it a number with a decimal point and a 0 in the decimal place, it seems to just ignore the decimal point and treat it like 2500 instead of 250.0 or whatever. Just thought I would mention that. As to the ship cap script, I guess I should post a new topic and ask if anyone else has trouble with single fig wave ship capping. Don't want to take this thread that far off topic lol. Code: setvar $maxfigs "250.2" getwordpos $maxfigs $pos "." if ($pos > "0") subtract $pos 1 cuttext $maxfigs $attack 1 $pos else setvar $attack $maxfigs end echo ANSI_15 "**" $attack "**" |
|
| Author: | SteveH_66 [ Thu Apr 12, 2012 7:10 am ] |
| Post subject: | Re: Removing a decimal |
Thanks Toyman, that's another way to do it. Code: setVar $enemyDefenseText ($enemyDefense + ($enemyFigs + $enemyShields)) replaceText $enemyDefenseText "." " " getWord $enemyDefenseText $enemyDefense 1 This replaces the . with a space, and then get's the first word which is the number you want. Haven't tested it to see how it reacts to not finding the . and a zero in the text, but it should be fine since I don't use this code in a script if I haven't setPrecision, and if I set precision then all numbers should have a . and zero or other number in the decimal place. |
|
| Author: | T0yman [ Thu Apr 12, 2012 7:34 am ] |
| Post subject: | Re: Removing a decimal |
Yea or I guess could just use striptext $var "." Lot's of options, just finding one that works for you |
|
| Author: | SteveH_66 [ Thu Apr 12, 2012 7:37 am ] |
| Post subject: | Re: Removing a decimal |
Very true Toyman. Edit : Oh, I don't think you would want to use stripText. It would strip out the period without replacing it with a space, so I think that would still leave your number that was in the decimal place wouldn't it? Which would make your number like 2700 instead of 270.0 or like 2354 instead of 235.4 or whatever. Haven't tested it, just a guess there. I think that was why I went with replaceText and getWord in my code instead of going with stripText. |
|
| Author: | SteveH_66 [ Thu Apr 12, 2012 8:21 am ] |
| Post subject: | Re: Removing a decimal |
Yes, just ran a simple test script, and if you used stripText it would just remove the decimal point and concatenate (if that is the programming term) the numbers in the decimal places to the whole number in front. Code: :part1 echo "*" "*" "*" setVar $test 257.75 echo "*" $test & " This is the number, with decimal places" stripText $test "." echo "*" $test & " This is the number after stripText" setVar $test2 129.00 echo "*" $test2 & " This is the number, with decimal places" stripText $test2 "." echo "*" $test2 & " This is the number after stripText" halt Script output from the test game : Code: 257.75 This is the number, with decimal places 25775 This is the number after stripText 129.00 This is the number, with decimal places 12900 This is the number after stripText Script terminated: C:\My Programs\TWXProxy 2_05\scripts\_test3.ts |
|
| Author: | T0yman [ Thu Apr 12, 2012 8:57 am ] |
| Post subject: | Re: Removing a decimal |
SteveH_66 wrote: Very true Toyman. Edit : Oh, I don't think you would want to use stripText. It would strip out the period without replacing it with a space, so I think that would still leave your number that was in the decimal place wouldn't it? Which would make your number like 2700 instead of 270.0 or like 2354 instead of 235.4 or whatever. Haven't tested it, just a guess there. I think that was why I went with replaceText and getWord in my code instead of going with stripText. Not if you do it this way, sometimes adding and subtracting to the $pos variable can cause flaky results, so just grabbing the "250." then stripping the "." is usually a more stable solution. NOTE: I added the if statement just in the case you get a number with no ".", it's a safety to keep script from misfiring and you ending in a pod Code: setvar $maxfigs "250.2" getwordpos $maxfigs $pos "." if ($pos > "0") cuttext $maxfigs $attack 1 $pos striptext $attack "." else setvar $attack $maxfigs end echo ANSI_15 "**" $attack "**" Using yours...slightly modded. Code: echo "***" setVar $test 257.75 getwordpos $test $pos "." cuttext $test $attack 1 $pos echo "*" $attack & " This is the number, with decimal places" stripText $attack "." echo "*" $attack & " This is the number after stripText" echo "***" Result: 257. This is the number, with decimal places 257 This is the number after stripText |
|
| Author: | SteveH_66 [ Thu Apr 12, 2012 10:06 am ] |
| Post subject: | Re: Removing a decimal |
Cool Toyman, taught this old dog a new trick I hadn't even thought of. So now, that's what 3 different ways we've worked out to do the same thing. I'll leave it to you and the other more experienced and skilled scripters out there to decide which would be best to use, I believe that's a bit beyond my rusty never were too good skills lol. |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|