0 Replies - 243 Views - Last Post: 28 July 2013 - 08:15 PM Rate Topic: -----

#1 PGspy18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-July 13

Batch (DOS) Code not reading from file properly.

Posted 28 July 2013 - 08:15 PM

For fun, i am working on a ATC Simulator. It is not homework, school doesn't start for a week or two...
Anyways, you play as the pilot, and the program balances takeoff/landing clearance, and tracking stages of flight.
When i get to the part to request takeoff clearance, the program does not read from the files telling it how to update the status, and signal the pilot program that it is clear of the runway. The main program is launched from a launcher that starts it with arguments. so the program starts copies of itself with different arguments to launch the pilot program. it might be a little hard to understand, but here is the code for the main program:
REM @echo off
color 0F
cd Bin\
if %1 NEQ show exit
goto %2
:start
REM mode con cols=20 lines=5
cls
title ATC KPGA
if not exist Data\ goto new
goto old
:new
cls
mkdir Data\
mkdir Data\s
mkdir Data\c
mkdir Data\r
echo 10>Data\r\n.pga
:old
cd Data\
cls
set c=y
set /p n=<n.pga
start ..\prog.bat show status
cls
goto ATC
:status
title Status
:statr
cls
dir s\ /b
timeout /t 5 /nobreak >nul
if not exist q.pga goto statr
exit
:ATC
verify>nul
cls
echo Press C for command
choice /c ca /d a /t 1 /n
if %errorlevel% EQU 2 goto Check
if %errorlevel% EQU 1 goto Command
:Check
set /p c=<c.pga
if exist m.pga goto ATC_M
if exist q.pga goto ATC_Q
if %c% EQU y goto ATC_R
goto ATC
:Command
start ..\prog.bat show ask
goto ATC
:ATC_M
set /p t=<m.pga
set /p t0=<p.pga
del m.pga /q
del p.pga /q
goto M_%t%
:ATC_Q
cls
echo Program Exiting!
timeout /t 6 /nobreak >nul
del q.pga /q
exit
:ATC_R
set /p t=<r\n.pga
if %t% EQU 10 goto ATC
set /a t -= 10
set t0=1
set /a t1=%t0% + 1
set /p t2=<r\1.pga
set /p t3=<c\%t1%\n.pga
del r\1.pga
if %t% EQU 1 (
echo 10>r\n.pga
goto ATC_R2
)
if %t3% EQU 13 (
set /p t4=<c\%t2%\d.pga
set /p t5=<c\%t2%\s.pga
set t6=Departing
set t7="%t2%%t4%%t5%"
set t8="%t2%%t4%%t6%"
rename s\%t7% s\%t8%
echo 14>c\%t2%\n.pga
echo a0>i.pga
echo %t2%>f.pga
goto ATC_R2
)
if %t3% EQU 15 (
set /p t4=<c\%t2%\d.pga
set /p t5=<c\%t2%\s.pga
set t6=Arriving
set t7="%t2%%t4%%t5%"
set t8="%t2%%t4%%t6%"
rename s\%t7% s\%t8%
echo 16>c\%t2%\n.pga
echo a1>i.pga
echo %t2%>f.pga
goto ATC_R2
)
goto ATC_R2
:ATC_R1
set /a t1 += 1
set /a t0 += 1
if %t0% EQU %t% goto ATC_R2
rename r\%t1% r\%t0%
goto ATC_R1
:ATC_R2
cls
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
set t6=
set t7=
set t8=
set c=n
goto ATC
:ask
title Command
cls
echo What can I help you with?
echo.
echo [1] New Flight
echo [2] Delete Flight
echo [3] Quit the program
echo [4] Plane Status
echo [5] Nothing
choice /c 12345
if %errorlevel% EQU 5 exit
if %errorlevel% EQU 4 goto ask_p
if %errorlevel% EQU 3 goto ask_q
if %errorlevel% EQU 2 goto ask_d
if %errorlevel% EQU 1 goto ask_n
:ask_q
cls
echo QUIT>q.pga
exit
:ask_d
cls
set /p t=Flight Callsign: PGA
set t=PGA%t%
if not exist c\%t%\ (
cls
echo Flight not exist!
pause
goto ask_else
)
cls
echo Are you sure you want to delete flight %t%?
choice
if %errorlevel% EQU 2 goto ask_nvm1
set /p t0=<c\%t%\d.pga
set /p t1=<c\%t%\s.pga
set t2="%t%%t0%%t1%"
del s\%t2% /q
rmdir c\%t% /s /q
set t=
set t0=
set t1=
set t2=
cls
echo Flight Deleted!
pause
goto ask_else
:ask_n
cls
set /p t=Flight Callsign: PGA
set t=PGA%t%
if exist c\%t%\ (
cls
echo Flight already exist!
pause
goto ask_else
)
set /p t0=Flight Details: 
set t0= - %t0% - 
set /p t1=Board Time: 
set t1=Scheduled to board at %t1%
set t2="%t%%t0%%t1%"
mkdir c\%t%
echo KPGA ATC by Patrick Gelvin>s\%t2%
echo %t0%>c\%t%\d.pga
echo %t1%>c\%t%\s.pga
echo 10>c\%t%\n.pga
set t=
set t1=
set t2=
set t0=
cls
echo Flight Created!
pause
goto ask_else
:ask_p
cls
set /p t=Flight Callsign: PGA
set t=PGA%t%
cls
start ..\prog.bat show pilot %t%
goto ask_else
:ask_nvm1
set t=
goto ask_else
:ask_nvm2
set t=
set t0=
goto ask_else
:ask_else
cls
echo Is there anything else I can help you with?
echo.
echo [1] New Flight
echo [2] Delete Flight
echo [3] Quit the program
echo [4] Plane Status
echo [5] Nothing
choice /c 12345
if %errorlevel% EQU 5 exit
if %errorlevel% EQU 4 goto ask_p
if %errorlevel% EQU 3 goto ask_q
if %errorlevel% EQU 2 goto ask_d
if %errorlevel% EQU 1 goto ask_n
:M_p0
cls
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Boarding
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
rename s\%t3% %t4%
echo 11>c\%t0%\n.pga
echo %t5%>c\%t0%\s.pga
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
goto ATC
:M_p1
cls
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Push Back
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
rename s\%t3% %t4%
echo 12>c\%t0%\n.pga
echo %t5%>c\%t0%\s.pga
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
goto ATC
:M_p2
cls
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Taxi to Runway
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
rename s\%t3% %t4%
echo 13>c\%t0%\n.pga
echo %t5%>c\%t0%\s.pga
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
goto ATC
:M_p3
cls
if %c% EQU y (
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Departing
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
pause
cls
echo %t1%
echo %t2%
echo %t3%
echo %t4%
pause
cls
rename s\%t3% %t4%
echo 14>c\%t0%\n.pga
echo %t0%>f.pga
echo a0>i.pga
echo %t5%>c\%t0%\s.pga
pause
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
set c=n
goto ATC
)
if %c% EQU n (
echo %t0%>p.pga
echo a2>i.pga
set /p t1=<r\n.pga
set /a t1 -= 9
echo %t0%>r\%t1%.pga
set /a t1 += 10
echo %t1%>r\n.pga
set t=
set t0=
set t1=
goto ATC
)
cls
echo ERROR CLEAR
pause
exit
:M_p4
cls
if %c% EQU y (
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Arriving
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
rename s\%t3% %t4%
echo 16>c\%t0%\n.pga
echo %t0%>f.pga
echo a1>i.pga
echo %t5%>c\%t0%\s.pga
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
set c=n
goto ATC
)
if %c% EQU n (
echo a2>i.pga
echo %t0%>p.pga
set /p t1=<r\n.pga
set /a t1 -= 9
echo %t0%>r\%t1%.pga
set /a t1 += 10
echo %t1%>r\n.pga
set t=
set t0=
set t1=
goto ATC
)
cls
echo ERROR CLEAR
pause
exit
:M_p5
cls
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Deboarding
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
rename s\%t3% %t4%
echo 18>c\%t0%\n.pga
echo %t5%>c\%t0%\s.pga
echo %t5%>c\%t0%\s.pga
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
goto ATC
:M_p6
cls
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Flight Ended
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
rename s\%t3% %t4%
echo 19>c\%t0%\n.pga
echo %t5%>c\%t0%\s.pga
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
goto ATC
:M_p7
cls
set c=y
set t=
goto ATC
:M_p8
cls
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=On Route
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
pause
cls
echo %t1%
echo %t2%
echo %t3%
echo %t4%
pause
cls
rename s\%t3% %t4%
echo 15>c\%t0%\n.pga
echo %t5%>c\%t0%\s.pga
pause
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
set c=y
goto ATC
:M_p9
cls
set /p t1=<c\%t0%\d.pga
set /p t2=<c\%t0%\s.pga
set t5=Taxi to Gate
set t3="%t0%%t1%%t2%"
set t4="%t0%%t1%%t5%"
rename s\%t3% %t4%
echo 17>c\%t0%\n.pga
echo %t5%>c\%t0%\s.pga
set t=
set t0=
set t1=
set t2=
set t3=
set t4=
set t5=
goto ATC
:pilot
set c=%3
set /p t=<c\%c%\d.pga
set t=%c%%t%
set /p n=<c\%c%\n.pga
if exist c\%c%\a.pga goto p15w
goto p%n%
:pc
cls
set /p n=<c\%c%\n.pga
if exist q.pga exit
goto p%n%
:p10
title %t%Scheduled
cls
echo Press [R] to request boarding
echo Press [E] to exit
choice /c REA /d A /t 1 /n
if %errorlevel% EQU 3 goto pc
if %errorlevel% EQU 2 exit
cls
echo %c%>p.pga
echo p0>m.pga
goto p10
:p11
title %t%Boarding
cls
echo Press [P] to request pushback
echo Press [E] to exit
choice /c PEA /d A /t 1 /n
if %errorlevel% EQU 3 goto pc
if %errorlevel% EQU 2 exit
cls
echo %c%>p.pga
echo p1>m.pga
goto p11
:p12
title %t%Push Back
cls
echo Press [T] to request Taxi to runway
echo Press [E] to exit
choice /c TEA /d A /t 1 /n
if %errorlevel% EQU 3 goto pc
if %errorlevel% EQU 2 exit
cls
echo %c%>p.pga
echo p2>m.pga
goto p12w
:p12w
cls
echo Which Runway?
echo.
echo [1] Runway 1
echo [2] Runway 20
choice /c 12 /n
if %errorlevel% EQU 2 goto p12_2
if %errorlevel% EQU 1 goto p12_1
:p12_1
set r=01
goto p12_3
:p12_2
set r=20
goto p12_3
:p12_3
cls
echo Gelvin Private Ground, %c%, Request taxi for takeoff, runway %r%
timeout /t 3 /nobreak >nul
echo %c%, Gelvin Private Ground, Taxi to Runway %r%, Contact tower when ready on 128.75
timeout /t 3 /nobreak >nul
echo Gelvin Private Ground, %c%, Taxi to Runway %r%, Tower on 128.75
timeout /t 10 /nobreak >nul
cls
echo Taxiing to runway, Please wait
timeout /t 30 /nobreak >nul
goto p13
:p13
title %t%Taxi to Runway
cls
echo Press [T] to request Takeoff Clearance
echo Press [E] to exit
choice /c TEA /d A /t 1 /n
if %errorlevel% EQU 3 goto pc
if %errorlevel% EQU 2 exit
cls
echo %c%>p.pga
echo p3>m.pga
goto p13w
:p13w
cls
echo Gelvin Private Tower, %c%, Ready to go, runway %r%
:p13w_
timeout /t 2 /nobreak >nul
if not exist i.pga goto p13w_
set /p q0=<f.pga
if %q0% NEQ %c% (
timeout /t 3 /nobreak >nul
goto p13w_
)
set /p q0=<i.pga
if %q0% NEQ a0 (
if %q0% EQU a2 (
del f.pga /q
del i.pga /q
echo %c%, Gelvin Private Tower, Hold short runway %r%
timeout /t 2 /nobreak >nul
echo Gelvin Private Tower, %c%, Hold short runway %r%
timeout /t 1 /nobreak >nul
goto p13w_
)
pause
timeout /t 3 /nobreak >nul
goto p13w_
)
del f.pga /q
del i.pga /q
echo %c%, Gelvin Private Tower, Cleared for takeoff, runway %r%
timeout /t 2 /nobreak >nul
echo Gelvin Private Tower, %c%, Cleared for takeoff
timeout /t 2 /nobreak >nul
title %t%Departing
cls
echo Takeoff Roll!
timeout /t 25 /nobreak >nul
cls
echo %c%>f.pga
echo p8>m.pga
goto p14
:p14
title %t%Departing
cls
echo Takeoff Roll!
timeout /t 1 /nobreak >nul
goto pc
:p15
if exist c\%c%\a.pga goto p15w
title %t%On Route
cls
echo Aircraft is On Route
timeout /t 600 /nobreak >nul
echo KPGA by Patrick Gelvin>c\%c%\a.pga
goto pc
:p15w
title %t%Arrived at Destination
cls
echo Aircraft has arrived at destination
echo Press [R] to make return trip
echo Press [E] to exit
choice /c RE /n
if %errorlevel% EQU 2 exit
REM Program is unfinished...



Right now it is set up to have the echo on, and pause before clearing the screen at the areas that don't work.
Help would be appreciated!
The program, launcher, and a txt file describing what every file used does is attached in a zip file.

Attached File  KPGA.zip (3.44K)
Number of downloads: 20

Is This A Good Question/Topic? 0
  • +

Page 1 of 1