0

I'm developing a batch game, and I have come across an error during testing. It's best if I show you the code:

:move
set /a chance=%RANDOM% % 4 + 1
if %chance% == 1 goto randomitem
if %chance% == 2 goto randommonster
if %chance% == 3 goto safe
if %chance% == 4 goto trap
:randomitem
cls
echo You found an item!
echo Sorry! The items mechanism hasn't been added yet!
goto main
:randommonster
cls
echo A random monster attacks you!
echo Sorry! The monsters mechanism hasn't been added yet!
goto main
:safe
cls
echo You enter another dark room with 4 corridors.
goto main
:trap
cls
echo You fall into a trap!
echo Sorry! The traps mechanism hasn't been added yet!
goto main

For some reason, instead of having a chance of doing all 4 paths, it is only doing randomitem. I don't know how to fix this, please help me!

Thanks!

1 Answer 1

2

You need to double the % used as a mod operator.

set /a chance=%RANDOM% %% 4 + 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.