Archive for September, 2009

Batch files, checking validity of user input

Monday, September 14th, 2009

Well, today I decided to add to my Minecraft server‘s backup script.

Before it would just make a copy of the server_level.dat and rename it with the time and date. I extended it to be a bit more interactive, adding a selection for the server’s current mode. (ie, Sunken or Preflood. I run an underwater build server.) And of course, I wanted to add a validity of user input check. I figured I could just do a if '%userinput%' != '0' || '1' || '2' goto invalidinput but I was wrong. So I found a hack around this, and I’m sharing it for anyone who may need it.

@echo off
:getnum
set /p mytestvar="Input 3, 4, or 23 please: "
echo.

rem the workaround
if '%mytestvar' == '3' goto isvalid
if '%mytestvar' == '4' goto isvalid
if '%mytestvar' == '23' (
goto isvalid
) else (
goto isnotvalid
)

:isvalid
echo it's valid!
pause
rem need this so it doesn't go over into isnotvalid
exit

:isnotvalid
echo it's not valid!
goto getnum

The valid numbers, or strings even, can be listed in any order. It’ll still work.
A bit tedious, listing each valid input option with its own if statement, but it’s better than having it just exit if the input is invalid.

So there. My 7-lined backup script bumped up to 45 lines, just to add the mode of the server automatically.
God, I love automation.

The Lettere E

Friday, September 11th, 2009

I gote borede, sittinge ine Frenche, one daye. Thise thoughte floatede intoe mye minde.. The lettere E cane be placede one nearlye anye worde note endinge ine E, ande the worde cane stille be pronouncede prettye muche the same. Whate doe youe thinke?