samedi 28 novembre 2015

IF statement using delayed expansion?

I have a piece of code that looks something like this(Delayed Expansion is enabled):

    for /l %%y in (1,1,%variable%) do (
     set /a rand=!random! * 100 / 32768 + 1
     echo !rand!
     if !rand! GEQ %chance% (
      set /a var=%var%+%varx%
     )
    )

the echo !rand! part displays the number, but if !rand! GEQ %chance% just sees !rand! as a string, not as its value. So even if !rand! is bigger than %chance% it still skips the command.

The weird part is no matter how many times !rand! is greater than %chance% at the end of the loop var increases by %varx% only once. What should be done here so that the IF statement sees !rand!'s value?

Aucun commentaire:

Enregistrer un commentaire