View unanswered posts | View active topics It is currently Sat Apr 18, 2026 9:22 am



Reply to topic  [ 7 posts ] 
 Removing a decimal 
Author Message
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post 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 "**"

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Thu Apr 12, 2012 6:28 am
Profile ICQ YIM WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: Removing a decimal
Thanks Toyman, that's another way to do it. :D When I did it in my script I used replaceText and getWord, like this small code snippet example :

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.


Thu Apr 12, 2012 7:10 am
Profile
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post Re: Removing a decimal
Yea or I guess could just use striptext $var "."

Lot's of options, just finding one that works for you :)

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Thu Apr 12, 2012 7:34 am
Profile ICQ YIM WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: Removing a decimal
Very true Toyman. :D

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.


Thu Apr 12, 2012 7:37 am
Profile
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post 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


Thu Apr 12, 2012 8:21 am
Profile
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post Re: Removing a decimal
SteveH_66 wrote:
Very true Toyman. :D

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 :lol:


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

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Thu Apr 12, 2012 8:57 am
Profile ICQ YIM WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: Removing a decimal
Cool Toyman, taught this old dog a new trick I hadn't even thought of. :lol: Very nice. :D

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.


Thu Apr 12, 2012 10:06 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.