User Tools

Site Tools


tasks:00_check_task_run_count
Title:Check Task Run Count
Sex: Female T Male T Trans T
Require:
Limits:
; Template: Count the number of times a task has been run
;
;---------------
; Configuration
;---------------
; Before copying the code in your task, perform a search and replace to customize the functions for your own task.
; * Replace TEMPLATE_EXAMPLE_TASK_PREFIX by something unique to your task.
;
;--------------------
; Reusable functions
;--------------------
; You should copy and paste this section at the beginning of your task
; Call these functions as needed in your task flow.
; See the Demo section for examples.
;
; /**
;  * Reads the number of time a task has been run.
;  * You should call this function just before you need to check the task run count.
;  * Returns: the run count in the $taskRunCount variable
;  * Warning: Calling this function will override TEMP1.
;  */
function:ReadRunCount
  loadtemp1:TEMPLATE_EXAMPLE_TASK_PREFIX_run_count
  assign:taskRunCount:(parseInt(TEMP1) || 0)
end:ReadRunCount
;
; /**
;  * Increments the number of time a task has been run.
;  * Always call this function at the end of your task.
;  * Warning: Calling this function will override TEMP1.
;  */
function:IncrementRunCount
  loadtemp1:TEMPLATE_EXAMPLE_TASK_PREFIX_run_count
  settemp1:((parseInt(TEMP1) || 0) + 1)
  savetemp1:TEMPLATE_EXAMPLE_TASK_PREFIX_run_count
end:IncrementRunCount
;
; /**
;  * Resets the number of time a task has been run.
;  * Warning: Calling this function will override TEMP1.
;  */
function:ResetRunCount
  settemp1:0
  savetemp1:TEMPLATE_EXAMPLE_TASK_PREFIX_run_count
end:ResetRunCount
;
;------
; Demo
;------
;
; A simple menu to play around with
;
show:This template task will show you how to count the number of times a task has been run before.
button:OK
;
; Call ReadRunCount before you need to check the run count
;
call:ReadRunCount
if:($taskRunCount == 0)
  show:You have never run this task before.
fi:
if:($taskRunCount == 1)
  show:This is the second time you are running this task.
fi:
if:($taskRunCount > 1)
  show:You have run this task $taskRunCount times before.
fi:
choice:Quit,Reset count
if:(LASTASK == 1)
  wait:1
  ;
  ; Call IncrementRunCount when the user completes the task
  ;
  call:IncrementRunCount
fi:
if:(LASTASK == 2)
  wait:1
  ;
  ; Only call ResetRunCount if you need to start from 0
  ;
  call:ResetRunCount
fi:
tasks/00_check_task_run_count.txt · Last modified: 2020/08/12 22:46 (external edit)