PRG_EXIST.kl

This Karel program valid if a specific program name already exists in the robot.

CODE    tag icon

PROGRAM PRG_EXIST

%NOPAUSE=ERROR+COMMAND+TPENABLE
%NOBUSYLAMP
%NOLOCKGROUP
%NOPAUSESHFT

CONST
flg_id = 1– Flag number that will be set when the program exist
str_reg_id =1– String Register number to compare

VAR
ary_name: ARRAY[200] OF STRING[64] new_tp_name: STRING[64] n_progs: INTEGER
i,status: INTEGER

BEGIN
–Reset Flag
FLG[flg_id] = FALSE

— Get String Register Value
GET_STR_REG(str_reg_id,new_tp_name,status)
— Get the list of all TP program
PROG_LIST(‘*’,7,0,1,ary_name,n_progs,status)

FOR i = 1 TO n_progs DO
— Set flag is the program already exist
IF (ary_name[i] = new_tp_name) THEN FLG[flg_id]=TRUE; ENDIF
ENDFOR

END PRG_EXIST