Author Topic: Pascal: Doing something every 15 seconds, best way to do this ...  (Read 150 times)

0 Members and 1 Guest are viewing this topic.

Offline graysontTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • graysont has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
This is for pascal.

I have a fisher on a boat. Every 15 seconds I get to "scan the horizons" and see whether any other boats are in the vicinity. If there are, I want to go home.

Preferably, in 1 script I would scan the horizons, set a variable with a timestamp, then do my fisher functions ... and at several places in loops I would check that timestamp, and if it has been over 15 seconds, I'd perform the scan the horizons again, set the timestamp again, then continue with the script.

I saw "function Timer: Cardinal", but there's no examples and I'm not sure the syntax of setting the variable and comparing whether 15 seconds have passed.

Alternatively, I could run a 2nd script something like this ...

begin
 startscan:       
 scanhorizons;     
 wait(15000);
 goto startscan;
end.

The problem with this is if the 2nd script decides it needs to go home ... and it is going to cast recall, it would somehow have to pause or stop the other script (and I'm not sure if that can be done or how to do that).

So in summary ... I want to set a timestamp variable that I can check whether 15 seconds have passed since it was set, or ...

I need to know how to have one script pause another script.

Any ideas would be appreciated, thanks!

Offline graysontTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • graysont has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Pascal: Doing something every 15 seconds, best way to do this ...
« Reply #1 on: August 23, 2017, 03:58:53 PM »
0
Figured out the timing ... pasting it below if anyone else is interested in something similar.

Code: [Select]
program scanhorizons;

const seconds15 = (1/(24 * 60 * 60)) * 15; // 15 seconds

var time15 : TDateTime;
label startscan;

procedure scanhorizons;
begin
  UOSay('; scan the horizons');     
end;

begin
 time15 := Time;
 startscan:                       
 if (Time > time15) then
 begin                   
    time15 := Time + seconds15;   
    scanhorizons;
 end; 
 goto startscan;
end.

Though if anyone can tell me about how one script can control another script would appreciate it, thanks!

Tags: