SRL Archive - RS3 Help

Progress Report - Error: Invalid floating point operation


Renzanity

2015-05-11 01:37:14

Hi everyone,

I decided I'd update my previous scripts and then I came across this problem. The script compiles, but when it's time to initiate the pRep() procedure, it terminates the script and shows Error: Invalid floating point operation on the debug.

This code works with my other script (Lumby Jug Filler), but for some reason it won't on my Vial Filler.
vialCount is counted using DTM, vialOfWaterPrice and vialPrice are manually typed on the playerForm.

procedure pRep();
var
gpPerHour, tgpMade: integer;
begin
tgpMade := ((vialCount * vialOfWaterPrice) - (vialCount * vialPrice));
{gpPerHour := round((tgpMade * 60) / (ScriptTimer.getTime() / 60000));} //This line's the one that's getting the error.
//When I use getTimeRunning() for it, it works fine,
clearDebug; //But when I use ScriptTimer.getTime(), that's when
writeLn('v4.0'); //I start to get the error
writeLn('/=======================================\');
writeLn('|======Renzanity Lumby Vial Filler======|');
writeLn('|=======================================|');
writeLn(PadR('| Time Ran: ' + msToTime(ScriptTimer.getTime(), TIME_SHORT), 40) + '|');
writeLn(PadR('| No. of breaks taken: ' + intToStr(BreaksTaken), 40) + '|');
writeLn(PadR('| Vials filled: ' + intToStr(vialCount) + ' pcs', 40) + '|');
writeLn(PadR('| Batches done: ' + intToStr(vialBatch) + ' batches', 40) + '|');
writeLn(PadR('| Estimated Total Profit: ' + intToStr(tgpMade) + ' gp', 40) + '|');
writeLn(PadR('| Estimated profit/hr: ' + intToStr(gpPerHour) + ' gp', 40) + '|');
writeLn('\=======================================/');

Thanks in advance for helping me if you're able to.:)

Have a good one!

slacky

2015-05-11 02:46:38

By the looks of things, the best bet is that `ScriptTimer` is a constant.
Solution: Store `ScriptTimer` as a variable.

PS: This is a guess, it would as usual be MUCH simpler if you actually shared ALL the relevant code, not just where the exception happens.

tls

2015-05-11 02:48:28

Debug the value of the denominator to make sure its not returning zero. For rate calculations you should use an extended anyways. Its more accurate/proper.

slacky

2015-05-11 02:52:38

From: tls
Debug the value of the denominator to make sure its not returning zero. For rate calculations you should use an extended anyways. Its more accurate/proper.

This is probably not the case here. When the denominator is Zero lape will normally raise a Division by zero exception.

Renzanity

2015-05-11 02:56:46

From: slacky
By the looks of things, the best bet is that `ScriptTimer` is a constant.
Solution: Store `ScriptTimer` as a variable.

PS: This is a guess, it would as usual be MUCH simpler if you actually shared ALL the relevant code, not just where the exception happens.


I've already stored 'ScriptTimer' on my global variables before, because I call it on my setup after my login procedure and before the mainloop.

var
vialCount, vialBatch, vialPrice, vialOfWaterPrice, scriptPaintBMP, breaksTaken,
breakT, breakL, vialOfWaterDTM: integer;
BreakTimer, ReloadTimer, {ScriptTimer}: TTimeMarker;
paint: boolean;
path: array [0..1] of TPointArray;

{*Other code goes here*}

//Setup
begin
{*setup code*}
logIn();
{ScriptTimer.start();}
repeat
mainloop
until (false);
end.

Edit: I'll post the entire code here since it will be publicly released anyway.:p
[SPOILER=Vial Filler Script]
WILL BE RELEASED TO THE PUBLIC SOON[/SPOILER]
EDIT: Forgot to revert the floatToStr back to intToStr. Was testing out a lot of crap for it to work.:p

Renzanity

2015-05-11 03:28:53

Okay, I think I fixed it now.

I just removed the 'pRep()' off of the first part of the mainloop and it now works well.

tls was right about the vialCount returning zero because it wasn't detecting any DTM at the start of the script.

Thanks everyone, for helping.:)

Have a good one.