SRL Archive - SRL Archives

function PlayOrBreak


AwesomeSRL

2009-10-17 17:55:00

Hey guys, I was thinking of an idea of making a True/False function that could be called whether or not to take a break. It requires a break-time to be provided and if the play-time exceeds to break-time then it will return False to take a break.

[PHP]
Description: This can be used to to define whether to take a break or not by returning a True or False Statement.

Checks for if Play is True or False. If the "TimeTillBreak" is less then "TimePlayed" then it will return that you are at or have exceeded the time that is limited till a break; thus making PlayOrBreak = False.

PlayOrBreak = False MEANS that it is time to take a break

PlayOrBreak = True MEANS that it has not yet reached the time to break

TimePlayed: Will find how long you have been playing for in minutes

TimeTillBreak: Used by the script to define how long till break-time is reached. It must be defined in minutes.
[/PHP]



MY ORIGINAL SRL Code:

function PlayOrBreak: Boolean;
var
TimePlayed, TimeTillBreak: Integer;
begin
Result := True;
TimePlayed := Round(GetTimeRunning / 60000.0);
If
(TimeTillBreak <= TimePlayed) Then
Result := False;
TimeTillBreak := (TimeTillBreak + TimePlayed);
If
(TimeTillBreak >= TimePlayed) Then
Result := True;
end;


Awkwardsaw's Shortened Version:

function PlayOrBreak(TimeTillBreak: integer): Boolean;
var
TimePlayed: Integer;
begin
TimePlayed := Round(GetTimeRunning / 60000.0);
result := TimePlayed >= TimeTillBreak;
end;

Awkwardsaw

2009-10-17 18:42:14

function PlayOrBreak(TimeTillBreak: integer): Boolean;
var
TimePlayed: Integer;
begin
TimePlayed := Round(GetTimeRunning / 60000.0);
result := TimePlayed >= TimeTillBreak;
end;

shortened :p

nice job though :)

AwesomeSRL

2009-10-17 18:55:04

From: Awkwardsaw
function PlayOrBreak(TimeTillBreak: integer): Boolean;
var
TimePlayed: Integer;
begin
TimePlayed := Round(GetTimeRunning / 60000.0);
result := TimePlayed >= TimeTillBreak;
end;

shortened :p

nice job though :)


Thanks for the review.

I learned quite a lot from that shortening though that you provided, even though it is a minor change, it made me see a couple different things that I could have done to make it smaller.

Like the:
result := TimePlayed >= TimeTillBreak;

I didn't know that it would return a true/false simply if you just provide the equation and if the equation worked it would return true.

Thanks man. =]

Awkwardsaw

2009-10-17 19:15:44

From: AwesomeSRL
Thanks for the review.

I learned quite a lot from that shortening though that you provided, even though it is a minor change, it made me see a couple different things that I could have done to make it smaller.

Like the:
result := TimePlayed >= TimeTillBreak;

I didn't know that it would return a true/false simply if you just provide the equation and if the equation worked it would return true.

Thanks man. =]


sure :p

sorry that i cant really explain why it works like that, its just a little technique lol