Jump to content

If statments are starting to piss me off.... ARG


Recommended Posts

Firstly, my code

consolewrite("   Soldiers:  Elites: Min:    " & @crlf);put in to check if the vars are right, they are
if int($oSoldiers*.25) > int($min) then 
    ConsoleWrite("A  " & $oSoldiers*.25 & " " & $oElites*0 & "  " & $min & @crlf)
_IEFormElementSetValue($oSoldiersInput, round($oSoldiers * .25 ,0))
_IEFormElementSetValue($oElitesInput, round(0 , 0))
elseif int($oSoldiers*.25 + $oElites *.25) > int($min) then 
    ConsoleWrite("B  " & $oSoldiers*.25 & " " & $oElites*.25 & "    " & $min & @crlf)
_IEFormElementSetValue($oSoldiersInput, round($oSoldiers * .25 ,0))
_IEFormElementSetValue($oElitesInput, round($oElites * .25 , 0))
Elseif int($oSoldiers) > int($min) then 
    ConsoleWrite("C  " & $oSoldiers*1 & "   " & $oElites*0 & "  " & $min & @crlf)
_IEFormElementSetValue($oSoldiersInput, round($min,0))
_IEFormElementSetValue($oElitesInput, round(0 , 0))
Else
    ConsoleWrite("D  " & $oSoldiers*1 & "   " & $oElites*1 & "  " & $min & @crlf)
_IEFormElementSetValue($oSoldiersInput, round($oSoldiers ,0))
_IEFormElementSetValue($oElitesInput, round($min-$oSoldiers , 0))
EndIf

console message is thusly:

Soldiers: Elites: Min:

A 1094.25 0 1,100

Values are as such:

$oSoldiers = 4377

$oElites = 0

Whats happening:

The script goes through its phases as normal, but for some unknown reason when it hits this part it stays on section A of the if statments, where with the avaliable info it should move on to C

but it doesnt, and im at my wit's end. What am i doing wrong?!?

Edited by pileot
Link to comment
Share on other sites

Why would it ever go to C???

If $oSoldiers equals 4377, that makes the following ($oSoldiers*.25) equal 1094.25.

if int($oSoldiers*.25) > int($min) then

To get to C, $oSoldiers*.25 would have to be less than $min, and from what you've shown I can't tell if $min is 1,100 or 100 because you have a comma here but not in your actual code:

A 1094.25 0 1,100

Edited by weaponx
Link to comment
Share on other sites

$oSoldiesrs is a numeric value, in this case 4377

I think maybe whats screwing it up is the comma in $min ?

maybe it sees the number before the comma and thinks its 1 instead of 1100?

its supposed to check if the calculated value of 4377*.25 > 1100 ($oSoldiers*.25 > $min)

If its the comma screwing everything up, that might explain everything... How would i remove it? whats the best way?

Link to comment
Share on other sites

Lol added a stringreplace to get rid of the comma, and its working now...

aparently if statments dont like working with numbers in the 123,456 format :/

Thanks for the help

Edited by pileot
Link to comment
Share on other sites

Lol added a stringreplace to get rid of the comma, and its working now...

aparently if statments dont like working with numbers in the 123,456 format :/

Thanks for the help

You shouldn't be working with numbers containing commas from the beginning. Where are they coming from?

StringReplace() may typecast your numbers as strings. Also since your ConsoleWrite() is showing the number with commas, this makes me think your condition might be screwed up, maybe try:

ConsoleWrite("A: " & $oSoldiers*.25 & ": " & $oElites*0 & ": " & Int($min) & @crlf)

Do you see the correct number?

Edited by weaponx
Link to comment
Share on other sites

Theyre coming from an online game, i found i was constantly using 25% of my resources, so i made a program to automatically do the math for me. it never occurred to me the site's use of commas might screw stuff up.

$min = StringReplace($min,",","")

thats what im using, whta do you mean typcast as a string?

after i added that line it seemed to work, but i might come across this sort of problem again...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...