1.

Solve : complicated question?

Answer»

ok, here's the thing, perhaps anoyne in amerika looks to the tv serie lost (www.lost.abc.com). In the "hatch" there is a computer where you have to enter a code correctly and on time every 108 minutes... I was wondering if it is possible to do such thing in batch to. This is what the batch should do:


count down every 108 minutes to zero, if you enter the CORRECT code (example: it should recaunt from 108 minutes. If you don't enter the (correct) code within 108 minutes it has to say "boom" or something.

I now it isn't just "a question" and I ask here a half/whole script, but i would appreciate it if someone tels me how you do such thing or is it impossible to do that in batch?

greetz

blackberry 8-)The only thing I can think of is using the shutdown prompt, and just changing the amount of time you have.Quote

The only thing I can think of is using the shutdown prompt, and just changing the amount of time you have.

not such bad idea, but than i still don't have, the thing if you enter the code that it don't shut down. Anybody other ideas?You really need something other than a batch file for this. A HTML Application (HTA) would be a likely solution; the window object has a setinterval method that might be helpful.

The problem here is you need two threads (windows) which need some common point of communication. You ask for a dinky batch solution, so I put forth dinky:

Boom.bat
Code: [Select]@echo off
echo 0 > boom.txt
set count=0
:tag
sleep 1
for /f %%i in (boom.txt) do (
call set /a count=%%i+1
if %count%==6480 (
echo Boom!
goto :eof
) else (
echo %count% > boom.txt
)
)
goto tag

Code.bat
Code: [Select]@echo off
start boom
:tag
set /p var=Enter Code:
if .%var%==.8 (echo 0 > boom.txt)
goto tag



PS. If you need a copy of sleep, try Google for a standalone copy or download the Win2003 Resource Kit.Quote
You really need something other than a batch file for this. A HTML Application (HTA) would be a likely solution; the window object has a setinterval method that might be helpful.

The problem here is you need two threads (windows) which need some common point of communication. You ask for a dinky batch solution, so I put forth dinky:

Boom.bat
Code: [Select]@echo off
echo 0 > boom.txt
set count=0
:tag
sleep 1
for /f %%i in (boom.txt) do (
call set /a count=%%i+1
if %count%==6480 (
echo Boom!
goto :eof
) else (
echo %count% > boom.txt
)
)
goto tag

Code.bat
Code: [Select]@echo off
start boom
:tag
set /p var=Enter Code:
if .%var%==.8 (echo 0 > boom.txt)
goto tag



PS. If you need a copy of sleep, try Google for a standalone copy or download the Win2003 Resource Kit.

i tried a few things out but i don't really understand what the codes does. when i use the script (i open code.bat) i get two dos screens, one whit enter code and another that does nothing, you can't type in it. When i enter 8 nothing seems to happen. And when I enter a code nothing happens.... What i tried to get was:

counting from 108 till zero. If you enter the CORRECT code (the number example at the 70th minute, it recounts from 108 till zero, and so one. If you enter the WRONG code, it says immediately boom OR if you enter the code not at time (not within the 108 minutes) it says boom too.

so perhaps i do something wrong, because the things i want doens't seems to work, can you help me pleas...

greetz

blackberry Code: [Select]@echo off
start boom
:tag
set /p var=Enter Code:
if .%var%==.8 (echo 0 > boom.txt) else (echo 6479 > boom.txt)
goto tag

FYI: Most scripting languages can do date/time arithmetic; batch cannot. Instead of counting down, it's easier to count up to a predetermined number (60*108 with a 1 second delay between increments).

Hope this helps. 8-)There might be an easier way to do this but here is what I have. You have to use 2 batch files. The code to restart the countdown is 4, 8, 15, 16, 23, 42,

RUN this batch file to start the countdown

Code: [Select]@echo off
TITLE Lost Menu
start countdown.bat
:MENU
CLS
Echo Enter in code
set /p code=
echo %code% >%temp%\entercode
GOTO MENU
Countdown batch file

Code: [Select]@echo off
:start
SET thecode=0
IF EXIST %temp%\entercode del %temp%\entercode
SET D=8
SET T=0
SET H=1
GOTO COUNTDOWN

:BEGIN
IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I "4, 8, 15, 16, 23, 42,"') do set thecode=1
if "%thecode%"=="1" GOTO START
IF "%COUNT%"=="099" GOTO DIGITS
IF "%COUNT%"=="009" GOTO DIGITS
IF "%COUNT%"=="100" set COUNT=099
IF "%COUNT%"=="010" set COUNT=009
IF "%COUNT%"=="099" GOTO 1SKIP
IF "%COUNT%"=="009" GOTO 1SKIP

:DIGITS
IF "%COUNT%"=="099" SET H=0
IF "%COUNT%"=="099" SET T=9
IF "%COUNT%"=="099" SET D=9
IF "%COUNT%"=="009" SET T=0
IF "%COUNT%"=="009" SET D=9
IF %D%==0 goto TENS
if %D%==1 set D=0
if %D%==2 set D=1
if %D%==3 set D=2
if %D%==4 set D=3
if %D%==5 set D=4
if %D%==6 set D=5
if %D%==7 set D=6
if %D%==8 set D=7
if %D%==9 set D=8
goto COUNTDOWN

:TENS
if %D%==0 SET D=9
if %T%==1 set T=0
if %T%==2 set T=1
if %T%==3 set T=2
if %T%==4 set T=3
if %T%==5 set T=4
if %T%==6 set T=5
if %T%==7 set T=6
if %T%==8 set T=7
if %T%==9 set T=8
if %T%==0 set T=9
goto COUNTDOWN


:COUNTDOWN
SET COUNT=%H%%T%%D%
Title Minutes Remianing %count%
IF %COUNT%==000 GOTO BAD

:1SKIP
cls
echo Time Remaining %count%
ping -n 2 127.0.0.1 >NUL
GOTO BEGIN

:BAD
CLS
Echo You are too late Process's are set in motion
pause
EXITForgot change the Ping statement to 60 seconds

ping -n 60 127.0.0.1 >NUL

If you use sleep.exe it is a little more accurate at counting.
Quote
There might be an easier way to do this but here is what I have. You have to use 2 batch files. The code to restart the countdown is 4, 8, 15, 16, 23, 42,

Run this batch file to start the countdown

Code: [Select]@echo off
TITLE Lost Menu
start countdown.bat
:MENU
CLS
Echo Enter in code
set /p code=
echo %code% >%temp%\entercode
GOTO MENU
Countdown batch file

Code: [Select]@echo off
:start
SET thecode=0
IF EXIST %temp%\entercode del %temp%\entercode
SET D=8
SET T=0
SET H=1
GOTO COUNTDOWN

:BEGIN
IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I "4, 8, 15, 16, 23, 42,"') do set thecode=1
if "%thecode%"=="1" GOTO START
IF "%COUNT%"=="099" GOTO DIGITS
IF "%COUNT%"=="009" GOTO DIGITS
IF "%COUNT%"=="100" set COUNT=099
IF "%COUNT%"=="010" set COUNT=009
IF "%COUNT%"=="099" GOTO 1SKIP
IF "%COUNT%"=="009" GOTO 1SKIP

:DIGITS
IF "%COUNT%"=="099" SET H=0
IF "%COUNT%"=="099" SET T=9
IF "%COUNT%"=="099" SET D=9
IF "%COUNT%"=="009" SET T=0
IF "%COUNT%"=="009" SET D=9
IF %D%==0 goto TENS
if %D%==1 set D=0
if %D%==2 set D=1
if %D%==3 set D=2
if %D%==4 set D=3
if %D%==5 set D=4
if %D%==6 set D=5
if %D%==7 set D=6
if %D%==8 set D=7
if %D%==9 set D=8
goto COUNTDOWN

:TENS
if %D%==0 SET D=9
if %T%==1 set T=0
if %T%==2 set T=1
if %T%==3 set T=2
if %T%==4 set T=3
if %T%==5 set T=4
if %T%==6 set T=5
if %T%==7 set T=6
if %T%==8 set T=7
if %T%==9 set T=8
if %T%==0 set T=9
goto COUNTDOWN


:COUNTDOWN
SET COUNT=%H%%T%%D%
Title Minutes Remianing %count%
IF %COUNT%==000 GOTO BAD

:1SKIP
cls
echo Time Remaining %count%
ping -n 2 127.0.0.1 >NUL
GOTO BEGIN

:BAD
CLS
Echo You are too late Process's are set in motion
pause
EXIT

fantastic code, but... if you enter the code wrong, nothing happens, and it should happen something. But thanx for the code yet! another problem that i like to be solved, is if you just enter 4, 8, it recounts to, so is it possible that you have enter correctly the exactly combination, nothing else
To make it require the exact code change the findstr.

This will make it require the exact passcode
Code: [Select]IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I /C:"4, 8, 15, 16, 23, 42,"') do set thecode=1
Insert the line below after this lineif "%thecode%"=="1" GOTO START This if they enter the wrong code.

Code: [Select]IF EXIST %temp%\entercode GOTO Wrong
then add this to the bottom of the file

Code: [Select]:wrong
cls
Echo.
Echo You Entered in the worng cade, That was a bad mistake.
echo.
pause
Have funQuote
To make it require the exact code change the findstr.

This will make it require the exact passcode
Code: [Select]IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I /C:"4, 8, 15, 16, 23, 42,"') do set thecode=1
Insert the line below after this lineif "%thecode%"=="1" GOTO START This if they enter the wrong code.

Code: [Select]IF EXIST %temp%\entercode GOTO Wrong
then add this to the bottom of the file

Code: [Select]:wrong
cls
Echo.
Echo You Entered in the worng cade, That was a bad mistake.
echo.
pause
Have fun

bad code, it doesn't work! nothing happens if you enter the wrong code, beside it should be possible if you just enter 4, 8 that is shows the message too, because 4, 8 is just a part of the code and is wrong, does anybody knows an other solution
Aren't you being a bit unreasonable? Two solutions have been offered and all the feedback we've gotten is "it doesn't work" or "I don't understand the code" or "this is what I want". It doesn't help that the SPECIFICATIONS keep changing with each post.

You already know quite a bit. You know you need two threads, you have two different techniques for implementing a timer, and you have enough code to choke a horse. All you need to do is put it together. The best way to learn is by doing.

8-)

Please don't post back with one your more colorful "*censored* is your problem?" comments. We've seen it all before.

I only come here for the entertainment, I am never disappointed. Quote
Aren't you being a bit unreasonable? Two solutions have been offered and all the feedback we've gotten is "it doesn't work" or "I don't understand the code" or "this is what I want". It doesn't help that the specifications keep changing with each post.

You already know quite a bit. You know you need two threads, you have two different techniques for implementing a timer, and you have enough code to choke a horse. All you need to do is put it together. The best way to learn is by doing.

8-)

Please don't post back with one your more colorful "*censored* is your problem?" comments. We've seen it all before.


lol

first of all i only use the such sentences like *censored* is your problem for peoples who really iritate me, just posting here some crap or want to make VIRUSES, or who thinks they have the right to SCOLD to someone (mostly that last reason).
now second, when I read you message it looks like you think that I don't appreciate at all the help the people gave me. That is a totaly wrong vision, I really appreciate the help people gives me, but with my last post I was a bit disappointed that it didn't worked... So I asked (perhaps on a bit impolite way) if he -or anybode else- knew an other solution. and my thirth and last point on your text, you say
you have enough code to choke a horse..... i'm here for learning and yes i learned a lot yet, but you can't expect that if you post a totaly strange code for me, that I understand it within the minute... I am still busy to decipher it.. and if you think that it isn't so hard, whell you can take my work over as seen you can understand everything in two minutes. By monday I would like to have some calculatings for my house that i'm designing now (i'm an architect)


Discussion

No Comment Found