IronFlame
IronFlame

Reputation: 29

Randomize batch variables

I am trying to make a Yahtzee game and I need to randomize number 1-6 in order to make it echo the specific dice face.

    :gameplay
    cls
    pause
    SET /A dice=%RANDOM% %%6+1
    if %dice%==1
    echo %dice1a%
    echo %dice1b%
    echo %dice1c%
    echo %dice1d%
    echo %dice1e%
    echo %dice1g%
    pause

This is the code I developed. Its not completed yet, this was just a test of the randomizer. Every time I run this, it gets to the first pause, then it quits the program. If you guys know what the problem is, can you tell me, and also I was wondering if it was possible to store multiline variable so I don't have to constantly echo multiple variables. If you guys know anything please tell me. Thanks

EDIT: I tried what you suggested and did this:

    :gameplay
    cls
    pause
    SET /A dice=%RANDOM% %%6+1
    if %dice%=1
    echo Hi
    pause
    echo %dice1a%
    echo %dice1b%
    echo %dice1c%
    echo %dice1d%
    echo %dice1e%
    echo %dice1g%
    pause

It didn't follow through to the 2nd pause so I think the variable isn't set properly. I barely noticed this time that it says invalid command syntax right before it quits. Thanks for the suggestion though.

Upvotes: 1

Views: 69

Answers (1)

IronFlame
IronFlame

Reputation: 29

Thanks guys I figured it out, I just was missing the double and quadruple spaces as well as the parenthesis in the if then statement.

    SET /A dice=%RANDOM% %%6 +1
      if %dice%==1 (
        echo %dice1a%
        echo %dice1b%
        echo %dice1c%
        echo %dice1d%
        echo %dice1e%
        echo %dice1f%
        echo %dice1g%
      )

I really appreciate everyone who attempted to help me, even if it was just me being stupid, and I really appreciate yacc for helping me the whole way. If you want my game once its finished, I will copy it on to the about me section.

Upvotes: 1

Related Questions