Solved how do I have a random event

May 27, 2017 at 23:37:40
Specs: Windows 10
I am making a text based adventure/roguelike game on notepad so I am using batch and I am stuck on how to make a 50/50 chance. I am trying to do you encounter a monster or You didn't see anything. If you could help me I would be gratefull

See More: how do I have a random event

Reply ↓  Report •

#1
May 28, 2017 at 00:37:43
✔ Best Answer
Get a random number and use modulo to make it either 0 or 1.

set /a chance=%random% %% 2
if %chance%==1 (
	echo It happened
) else (
	echo It didn't happen
)

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Reply ↓  Report •

#2
May 28, 2017 at 00:38:28
@echo off & setLocal enableDELAYedeXpansioN

set/a Z=!RANDOM!%%2
echo.!Z!

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#3
May 28, 2017 at 01:23:02
If you want to try version 0.00000001 here it is
@echo off
title Arcanerite
echo YOU HEAR A MYSTERIOUS VOICE
pause
cls
echo Hello wonderer I must not tell you my name right now
pause
cls
echo But you are "The Chosen One"
pause
cls
echo The chosen one only appears every thousand years
pause
cls
echo So do what you must and defeat the evil Orc king
pause
goto menu

:menu
cls
echo Arcanerite
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo + choose what to do +
echo + 1.Go into the disturbed land you can fix +
echo + 2.Exit the game and be banished(not really banished) +
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
set/p menu=

if %menu% == 1 goto game
if %menu% == 2 goto exit

:game
cls
echo Good now you can fight monsters and gear up
pause
cls
echo Now that I know you wont quit, this place is called Arcanerite
pause
cls
echo To move type 1
set/p move=

if %move% == 1 goto game 1

:game 1
cls
echo great you have moved once
pause
cls
echo To move type 1
set/p move=

if %move% == 1 goto game 2

:game 2
cls
echo Now you are going to have a 50 percent chance to encounter a monster everytime you move
pause
cls
echo To move type 1
set/p move=%random% %%2

if %move%==0 goto fight0
if %move%==1 goto game 3

:fight0
cls
echo You have encountered a monster if you get hit by it or miss it you die
set/p punch=%random% %% 2

if %punch%==0 goto menu
if %punch%==1 goto game 3

:game 3
cls
echo Did you encounter a monster if not dont worry there will be plenty more times
pause


Reply ↓  Report •
Related Solutions


Ask Question