SRL Archive - Help

[Error] Type mismatch


rj

2012-12-28 16:24:49

On my script I want to make a progress report that is supposed to look something like this:

********************************
RJJ95 Potion Drinker Version 2.2
Status:Drinking Potions
Potions Drank:500 |500 left to drink| [50%]
*****************************
So far I almost have it down but I keep getting a mismatch

[Error] C:\Users\*\Desktop\simba\Password\Scripts\Herblore\PotDrinker.simba(133:52): Type mismatch at line 132
Compiling failed.

The code im using works all except for the percent part,
Writeln('********************************')
Writeln('RJJ95 Potion Drinker Version 2.2')
Writeln('Status:' + status + '');
Writeln('Potions Drank:' + IntToStr(PotsDrank) + ' |'
+ IntToStr(StrToInt(HowManyDrink)-PotsDrank) + ' Left to drink| ['
+ IntToStr(PotsDrank)/(StrToInt(HowManyDrink)) + '%]');
Writeln('********************************')

How do i properly divine How many potions I have drank (integer) and how many the goal is (string)

note: This part works
' |'
+ IntToStr(StrToInt(HowManyDrink)-PotsDrank) + ' Left to drink|'

But the dividing part does not
['
+ IntToStr(PotsDrank)/(StrToInt(HowManyDrink)) + '%]');

masterBB

2012-12-28 16:30:04

IntToStr(PotsDrank)/(StrToInt(HowManyDrink))

replace it with

IntToStr(PotsDrank / StrToInt(HowManyDrink))

I also suggest casting str to int in a variable or use StrToIntDef, if you use str to int def it will pass a default value if the number couldn't be read. If it is 0 for example this will generate a divide by zero error. Setting the default value to 1 will help you.

rj

2012-12-28 16:30:53

From: masterBB
IntToStr(PotsDrank)/(StrToInt(HowManyDrink))

replace it with

IntToStr(PotsDrank / StrToInt(HowManyDrink)))

I also suggest casting str to int in a variable or use StrToIntDef, if you use str to int def it will pass a default value if the number couldn't be read. If it is 0 for example this will generate a divide by zero error. Setting the default value to 1 will help you.


I just have the script add pots drank by 1 when it asks for user input thanks anyways

rj

2012-12-28 16:39:52

wwwww aiit

My progress report looks like:
********************************
RJJ95 Potion Drinker Version 2.2
Status:Closing bank
Potions Drank:100 |5502 Left to drink| [0%]
********************************
Shouldn't it be at atleast 1% now?

Btw it's multiplied it by to show percent but it does nothing
Writeln('Potions Drank:' + IntToStr(PotsDrank) + ' |'
+ IntToStr(StrToInt(HowManyDrink)-PotsDrank) + ' Left to drink| ['
+ IntToStr(PotsDrank / StrToInt(HowManyDrink)*100) + '%]');

masterBB

2012-12-28 16:49:30

An Integer is a number in
So to get a more exact answer we need extendeds. To force simba to use it we will multiply by 1.0.

IntToStr(PotsDrank * 1.0 / StrToInt(HowManyDrink)*100)

Now you will have a huuuuuuuuuge number so let's round it( and maybe an error cause IntToStr on an extended):

IntToStr(Round(PotsDrank * 1.0 / StrToInt(HowManyDrink)*100))

rj

2012-12-28 17:08:35

From: masterBB
An Integer is a number in
So to get a more exact answer we need extendeds. To force simba to use it we will multiply by 1.0.

IntToStr(PotsDrank * 1.0 / StrToInt(HowManyDrink)*100)

Now you will have a huuuuuuuuuge number so let's round it( and maybe an error cause IntToStr on an extended):

IntToStr(Round(PotsDrank * 1.0 / StrToInt(HowManyDrink)*100))


ahh thanks I knew i always had a problem with rounding in simba