SRL Archive - OSR Help

Type Mismatch between 2 integers because of absolute value?


bink830

2010-05-22 02:46:09

Ok, so I'm trying to make a smither for my first script but I've come across an early snag in my PostProggie procedure. Excerpt Included Below \/.


var
TotalTime, TotalBars, TotalLoads, Profit, NegProfit:integer;

procedure PostProggie;
begin
ClearDebug;
TotalTime := 200; //test number in seconds
TotalBars := 28; //test numbers
TotalLoads := 1; //test numbers
Profit := -100; //this is the issue
NegProfit := (abs(Profit)); //[Error] (21125:27): Type mismatch in script.. Aren't they both integers?
WriteLn('Thank you for using My Goldsmither!');
WriteLn('The script ran for '+inttostr(TotalTime/60)+' minutes.');
WriteLn('You smelted '+inttostr(TotalBars)+' in '+inttostr(TotalLoads)+' loads.');
if (Profit > 0) then WriteLn('You made '+inttostr(Profit)+' gold. :)');
else WriteLn('You lost'+inttostr(NegProfit)+' gold. :(');
end;

I know I have that done in a weird way, but I've been looking and trying everything I could think of to make it work and I'm still getting nothing. If possible I'd like to be pointed in the right direction and not have the script corrected for me so I can learn better. If not, then I'll take whatever help I can get. Thanks.

~Bink

Wanted

2010-05-22 03:06:39

Round(Abs(

bink830

2010-05-22 03:11:38

:( I figured it out a different way. Sad I hadn't done either before. I was about to delete this post.


var
TotalTime, TotalBars, TotalLoads, Profit:integer;
NegProfit:extended;

procedure PostProggie;
begin
ClearDebug;
TotalTime := 200;
TotalBars := 28;
TotalLoads := 1;
Profit := -100;
NegProfit := abs(Profit);
WriteLn('Thank you for using My Goldsmither!');
WriteLn('The script ran for '+inttostr(TotalTime/60)+' minutes.');
WriteLn('You smelted '+inttostr(TotalBars)+' in '+inttostr(TotalLoads)+' loads.');
if (Profit > 0) then WriteLn('You made '+inttostr(Profit)+' gold. :)');
if (Profit < 0) then WriteLn('You lost '+floattostr(NegProfit)+' gold. :('); //here
end;

Taking the else out and making it another if statement fixed it. Want me to delete? Thanks though.

bullzeye95

2010-05-22 03:25:02

Use iAbs() for integers.

i luffs yeww

2010-05-22 22:09:41


if (Profit > 0) then WriteLn('You made '+inttostr(Profit)+' gold. :)');
if (Profit < 0) then WriteLn('You lost '+floattostr(NegProfit)+' gold. :('); //here

Can just be


if(Profit > 0)then
Writeln('You made ' + IntToStr(Profit) + ' gold. :)')
else
Writeln('You lost ' + FloatToStr(NegProfit) + ' gold. :(');

Sex

2010-05-22 23:24:13

From: i luffs yeww
Code:
[LEFT]if (Profit > 0) then WriteLn('You made '+inttostr(Profit)+' gold. :)');
if (Profit < 0) then WriteLn('You lost '+floattostr(NegProfit)+' gold. :('); //here

[/LEFT]


Can just be

Code:
[LEFT]if(Profit > 0)then
Writeln('You made ' + IntToStr(Profit) + ' gold. :)')
else
Writeln('You lost ' + FloatToStr(NegProfit) + ' gold. :(');
[/LEFT]

If the profit is 0 then it will say you lost 0 gold or something like that :p. With what he has, nothing would show.

bink830

2010-05-23 00:02:06

if (Profit > 0) then WriteLn('You made '+inttostr(Profit)+' gold. :)')
else if (Profit < 0) then WriteLn('You lost '+floattostr(NegProfit)+' gold. :(')
else WriteLn('You broke even, did you even make a bar?');

Figured out I wasn't supposed to put a semicolon after the if statement before the else. That was giving me the expected identifier error I was bewildered about.

Sex

2010-05-23 00:03:42

Nothing wrong with his code…how do you have it in your script?

bink830

2010-05-23 00:13:10

I edited it in above.

i luffs yeww

2010-05-23 00:13:26

Well why would that matter? ^^