User win

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: User win

#31 Post by ShadowThief » 14 Jul 2015 02:52

There's an example in my above post where it says example, but another example couldn't hurt.

Code: Select all

echo Will you [i]gnore or [e]ducate the student?
choice /C:IE

:: if the user presses i, errorlevel is set to 1
:: if the user presses e, errorlevel is set to 2
:: because checking the errorlevel returns true if the current error level is equal to or greater than the value specified, the options have to be in reverse order
if errorlevel 2 call :educate
if errorlevel 1 goto Menu

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#32 Post by 117Mickey » 14 Jul 2015 03:43

I get it, thanks very much. How do we put a space between the options Educate and ignore, particularly ignore with the [I, E]

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#33 Post by 117Mickey » 14 Jul 2015 03:47

Also, i tried switching the I and E around since Educate is first and Ignore is next but it didn't work. ??

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: User win

#34 Post by ShadowThief » 14 Jul 2015 11:06

117Mickey wrote:I get it, thanks very much. How do we put a space between the options Educate and ignore, particularly ignore with the [I, E]

You can't, but you can say

Code: Select all

choice /C:IE /M "I or E? " /N

and then choice will print "I or E? " and then not include the [I,E] part altogether.

117Mickey wrote:Also, i tried switching the I and E around since Educate is first and Ignore is next but it didn't work. ??

Did you also remember to swap around the call and goto statements? Errorlevel is equal to where the button is in the order of the list of available buttons, so when you have /C:IE, I is 1 and E is 2, but when you have /C:EI, E is 1 and I is 2.

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#35 Post by 117Mickey » 14 Jul 2015 18:01

Ok, thanks. thanks very much.

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#36 Post by 117Mickey » 14 Jul 2015 18:26

I put this into the main menu but it didn't work. maybe more than 2 errorlevels dont work.

choice /C:NESWXA /M "N, E, S, W, X or A? " /N
echo.
if errorlevel 1 call :North
if errorlevel 2 call :East
if errorlevel 3 call :South
if errorlevel 4 call :West
if errorlevel 5 call :Exit
if errorlevel 6 call :Subscribe

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: User win

#37 Post by foxidrive » 14 Jul 2015 19:52

Reverse the order of the errorlevel checks.

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#38 Post by 117Mickey » 14 Jul 2015 20:35

i did this but it didn't work

echo.
choice /C:NESWXA /M "N, E, S, W, X or A? " /N
if errorlevel 6 call :Subscribe
if errorlevel 5 goto :Exit
if errorlevel 4 call :West
if errorlevel 3 call :South
if errorlevel 2 call :East
if errorlevel 1 call :North

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: User win

#39 Post by foxidrive » 14 Jul 2015 23:23

117Mickey wrote:i did this but it didn't work

echo.
choice /C:NESWXA /M "N, E, S, W, X or A? " /N
if errorlevel 6 call :Subscribe
if errorlevel 5 goto :Exit
if errorlevel 4 call :West
if errorlevel 3 call :South
if errorlevel 2 call :East
if errorlevel 1 call :North


How did it fail?

You may like to replace all the call keywords with goto

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#40 Post by 117Mickey » 15 Jul 2015 00:04

Sorry, it worked just after i posted it. I'll see how i am going. Thanks

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#41 Post by 117Mickey » 15 Jul 2015 00:52

My new code, is now that you can play as a student or teacher.

I inserted this into the student thread.
i put a S after win so the computer dosn't mix it with the one for teachers. Thanks

:Student
set winS=0
. . .

:Title1
if %winS% lss 2 (set /A winS+=1) else set winS=0
...

:Title 2
set winS=0
. . .

:Title 3
if %winS% geq 2 set /A winS+=1
if %winS% equ 5 echo You won & goto :WINWINS
. . .

:Title 4
set winS=0
. . .

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#42 Post by 117Mickey » 16 Jul 2015 18:52

Please someone

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#43 Post by 117Mickey » 18 Jul 2015 20:48

...

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: User win

#44 Post by ShadowThief » 18 Jul 2015 23:12

I'm confused. Where in your script did you put those new lines?

117Mickey
Posts: 39
Joined: 19 Jun 2015 05:33

Re: User win

#45 Post by 117Mickey » 19 Jul 2015 02:18

So i made a student side and a teacher side. But the main problem is the now winning cannot be achieved. It doesn't work on both sides.

Locked