SRL Archive - OSR Help

Function Help


Kaladin

2010-11-06 20:14:33

Okay so this is my first script and obviously im just finding my way around however this is one very minor problem thats annoying me.

Im using OpenBankFast(): which works fine, what I want to know is for log purposes how do I find out if it was sucessfull or not.

I tried a few different things guessing (As there is Boolean in the paramaters but I just don't know how to use it)

  Procedure Bank;
Var
banksucess: boolean
begin
OpenBankFast('veb')banksucess;
If banksucess = True then
WriteLn('Bank sucessfully opened')
else
writeLn('Banking failed')

DepositAll;
end

I assumed that would asssign a value of true to banksucess if it were sucessfull but my syntax is very wrong.

Any help would be much appreciated, sorry for asking so soon into the tutorials but it is bugging me.

Cstrike

2010-11-06 20:25:04

Make sure you have standards :) [which are the proper indentation after bold words]

Procedure Bank; // Should not be a space
Var // No space here
banksucess: boolean // You forgot the semicolon ";"
begin // first begin is always at the base
OpenBankFast('veb')banksucess; // When calling OpenBankFast('veb'), you dont need anything after it (no procedure name is needed)
If banksucess = True then // Bank success is not defined, but I assume thats what you wanted to define above? I'll cover that in my new paragraph
WriteLn('Bank sucessfully opened')
else
writeLn('Banking failed') // Forgot semicolon

DepositAll; // This will attempt to deposit all, even if you failed
end // forgot semicolon, should be at the beginning

So this is how I would make your code:

Procedure Bank;
Var
banksucess: boolean;
begin
banksuccess := OpenBankFast('veb'); // OpenBankFast is a function that returns true or false, so therefore we can set banksuccess to true or false, this can be shortened later
If banksucess = True then
begin
WriteLn('Bank sucessfully opened');
DepositAll; // This should be in here because it should only be called if we know the bank was opened
end else writeLn('Banking failed'); // We need no begin or end; if it's only ONE line of code, if its two then you need begin/end;
end;

Now you can further shorten it to this [USE THIS]:
Procedure Bank;
begin
if (OpenBankFast('veb')) then // if (function inside here is true) then ...
begin
WriteLn('Bank sucessfully opened');
DepositAll;
end else writeLn('Banking failed');
end;

EDIT: My standards spaces are not appearing for some reason
Hope that helps :)

TomTuff

2010-11-06 20:26:55

function Bank: Boolean;
begin
Result := OpenBankFast('veb');
if Result then
Writeln('Bank sucessfully opened')
else
Writeln('Banking failed');
DepositAll;
end;

Kaladin

2010-11-07 05:11:01

Thanks both of you :) Very helpful.

I thought that would be the correct way (I tried that first but I forgot the colon before the = (Used to VB) and then the paramaters at the bottom confused me)

thanks again.