SRL Archive - Help and Support

XP/hour going negative


Narcle

2007-11-22 12:49:00

For some reason my XP/hour isn't calculating right. I keeps going negative or is way to low. I think some how when I'm adding time to each person its going negative somehow but I can't figure it out.

I have it MarkTime(RoundTimer) every time I do the player setup process, so that shouldn't cause the problem… *sigh* I marked the lines with {T} and {C}
  if (HowManyPlayers > 1) then
begin
Players[currentplayer].Integers[11] := Players[currentplayer].Integers[11] + XPn;
Players[currentplayer].Integers[12] := Players[currentplayer].Integers[12] + killed;
Players[currentplayer].Integers[13] := Players[currentplayer].Integers[13] + CurAU;
Players[currentplayer].Integers[15] := Players[currentplayer].Integers[15] + foodate;
{T} Players[currentplayer].Integers[31] := Players[currentplayer].Integers[31] + TimeFromMark(RoundTimer);
{C} if (Players[currentplayer].Integers[11]>0) and (Players[currentplayer].Integers[31]>0) then
Players[currentplayer].Integers[32] := ((Players[currentplayer].Integers[11]*3600000)/Players[currentplayer].Integers[31]) else Players[currentplayer].Integers[32] := 0;
ClearDebug;
Writeln('|_Multi-Player__Fast Fighter v'+Version+' by Narcle___|');
Writeln('| Ran: ' + inttostr(H) + 'h:' + inttostr(M) + 'm:' + inttostr(S)+'s Current Time: '+TheTime+' Start Time: '+StartTime+' |');
WriteLn('| Totals: XP Gained; '+ inttostr(Txp)+', Kills; '+ inttostr(TKilled)+', Food ate; '+inttostr(TFoodate)+', Ammo used; '+inttostr(TArrowAmount)+' |');
writeln(' _____________________________________________________________________________________');
Writeln('| # | Nick | Active | A S D R | XP gained | Kills | XP/hour | Food ate | Ammo Used |');
For I := 0 to HowManyPlayers - 1 do
begin
if Players[i].Active=True then Active := 'True' else Active := 'False';
Writeln('| '+IntToStr(I)+' | '+Players[i].Nick+' | '+Active+' | '+IntToStr(Players[i].level[1])+' '+IntToStr(Players[i].level[2])+' '+
+IntToStr(Players[i].level[3])+' '+IntToStr(Players[i].level[4])+' | XP: '+IntToStr(Players[i].Integers[11])+' | K: '+
+IntToStr(Players[i].Integers[12])+' | XP/h: '+IntToStr(Players[i].Integers[32])+' | Ate: '+IntToStr(Players[i].Integers[15])+
+' | AU: '+IntToStr(Players[i].Integers[13])+' |');
end;
end;

Report:
|_Multi-Player__Fast Fighter v2.1 by Narcle___|
| Ran: 8h:0m:59s Current Time: 12:32:01 PM Start Time: 04:31:57 AM |
| Totals: XP Gained; 17320, Kills; 1432, Food ate; 0, Ammo used; 0 |
_____________________________________________________________________________________
| # | Nick | Active | A S D R | XP gained | Kills | XP/hour | Food ate | Ammo Used |
| 0 | enc | True | 12 12 12 1 | XP: 3300 | K: 272 | XP/h: -178 | Ate: 0 | AU: 0 |
| 1 | sgi | True | 21 21 21 1 | XP: 3832 | K: 316 | XP/h: 158 | Ate: 0 | AU: 0 |
| 2 | vei | True | 19 20 19 1 | XP: 3832 | K: 318 | XP/h: 156 | Ate: 0 | AU: 0 |
| 3 | etb | True | 16 16 16 1 | XP: 2864 | K: 236 | XP/h: 341 | Ate: 0 | AU: 0
| 4 | cal | True | 21 21 0 0 | XP: 3492 | K: 290 | XP/h: -60 | Ate: 0 | AU: 0 |

Santa_Clause

2007-11-22 18:15:04

What's wrong with it?

It says it ran for 8 hours and 59 seconds…

Sebo

2007-11-22 21:44:58

Santa, look down at XP/Hr on the players

Narcle

2007-11-22 22:35:28

From: Sebo
Santa, look down at XP/Hr on the players


Yeah the XP/hour.

Thing to note, the first loop through all the players it works fine. But after the second loop they go negative or become really low numbers. *sigh*

Miitchyy

2007-11-23 06:51:25

It's because when your timing the first number 3600000 it goes over 2147mil and becomes -2147m because that's how Integer's work.

Thus a negative result xP

Abs((Players[CurrentPlayer].Integers[32]*3600000)/Players[CurrentPlayer].Integers[11]);
^Not sure about the indexes



Also that method will be inacurate since if it's a large number it will go through the loop many times and give totally off result, Try
Players[CurrentPlayer].Integers[32] / (Players[CurrentPlayer].Integers[11] / 3600000)

Narcle

2007-11-23 07:42:03

Ah, didn't know scar couldn't handle larger numbers like that, I'll try the other way and tell you the result.
thx kevin

Miitchyy

2007-11-23 07:51:25

^_^;

So it works now?

Narcle

2007-11-23 07:54:22

No testing right now, won't know for an hour or so (running 6 guys) since it doesn't mess up until second loop through.

Miitchyy

2007-11-23 08:23:27

Ah ok,
Well I'll check back again tomorrow,
I gotta go to bed xP

Good luck with the XP\H

Narcle

2007-11-23 08:25:24

[Runtime Error] : divide by Zero in line 407 in script C:\Documents and Settings\All Users\Documents\My SCAR stuff\Narcles Scripts\Narcles Fast Fighter v2.1 (m).scar

ffs

edit, maybe its trying to divide by to little of a number? idk… (sigh)

ZephyrsFury

2007-11-23 08:30:29

As long as you have this:

if (Players[currentplayer].Integers[11]>0) then
stuff here

It should work. The reason you are getting the error is because you can't divide a number by zero.

Narcle

2007-11-23 08:40:25

From: ZephyrsFury
As long as you have this:

if (Players[currentplayer].Integers[11]>0) then
stuff here

It should work. The reason you are getting the error is because you can't divide a number by zero.


if (Players[currentplayer].Integers[11]>0) and (Players[currentplayer].Integers[31]>0) then
Players[currentplayer].Integers[32] := ((Players[currentplayer].Integers[11]*3600000)/Players[currentplayer].Integers[31]) else Players[currentplayer].Integers[32] := 0;

Already did…

ZephyrsFury

2007-11-23 08:46:16

It shouldn't be getting the error then. Is line 407 that line that Kevin told you to put in?

Narcle

2007-11-23 08:53:50

Yep, trying another equation atm:

    if (Players[currentplayer].Integers[11]>0) and (Players[currentplayer].Integers[31]>0) then
Players[currentplayer].Integers[32] := ((Players[currentplayer].Integers[11]*3600)/(Players[currentplayer].Integers[31]/1000)) else Players[currentplayer].Integers[32] := 0;

So far no errors, and calculating correctly first time through, waiting for round 2 of loop.

Edit:
This equation worked, guess you need the numbers small enough and not in decimal form to work good. *jots note down*

R0b0t1

2007-11-23 12:51:23

Instead of doing all of that abs stuff, just set the value as an "Int64". (If you want to know how large it is, go into calculator and do 2^64)

Narcle

2007-11-23 13:12:23

From: R0b0t1
Instead of doing all of that abs stuff, just set the value as an "Int64". (If you want to know how large it is, go into calculator and do 2^64)


How you set it to "Int64"? Would be handy to have numbers go that high for all the calculations. :D

R0b0t1

2007-11-23 13:33:40


var
ReallyBigNumber: Int64;

Narcle

2007-11-23 13:37:05

From: R0b0t1

var
ReallyBigNumber: Int64;


zomg, fuck "integer" lol

R0b0t1

2007-11-23 15:53:57

Int64 uses two regular integer spaces, so don't use it often… (Well, unless you are using a 64bit architecture. Then I think "integer" and "Int64" are the same, or something like that.)


Why-the-hell would you want to use it often, anyway?

Narcle

2007-11-23 16:01:47

From: R0b0t1
Int64 uses two regular integer spaces, so don't use it often… (Well, unless you are using a 64bit architecture. Then I think "integer" and "Int64" are the same, or something like that.)


Why-the-hell would you want to use it often, anyway?


Who said I would use it often? It'll be for when I need to have large numbers saved.

R0b0t1

2007-11-23 16:25:59

I bet you're gonna crash the universe with those large numbers :p