samedi 5 août 2017

An If statement in my .bat script isn't working as expected

What is supposed to happen is that you input a number between 1 and 1,048,567. The program checks if your input is actually a number between 1 and 1,048,567. If your input is a valid number then it will continue onto the next bit of code. If the input is invalid then it will display a message saying it is invalid then loop back and ask you for input again. When I run this however, I input anything and it says invalid input even if I did input a number between 1 and 1,048,567.

Code:

:setup
@echo off
title Pokemon Shiny Sim
set delay = nul
set count = 0
set chance = 4096

:settings
:setChance
cls
echo Set shiny chance (1 in x). Range: (1-1,048,567)
echo Leave blank for 1 in 4096.
set /p chance = Input: 
set /a chance = %chance%+0
if %chance% GEQ 1 (
    if %chance% LEQ 1048567 (
        goto setDelay
    )
)
echo Invalid Input.
pause
goto setChance
:setDelay
cls
echo Set delay between attempts in seconds. Range: (1-60).
echo Leave blank for no delay.
set /p delay = Input: 
set /a delay = %delay%+0
if %delay% == nul (
    goto loopStart
)
if %delay% GEQ 1 (
    if %delay% LEQ 60 (
        cls
        goto loopStart
    )
)
echo Invalid Input.
pause
goto settings

:loopStart
set /a count = %count%+1
set /a rand = %random% %% %chance%+1
if %rand% == 1 (
    echo Attempt: %count% | Shiny: Yes!
    pause
)
else (
    echo Attempt: %count% | Shiny: No
)
goto loopStart

Aucun commentaire:

Enregistrer un commentaire