Results 1 to 4 of 4

Thread: Function Help

  1. #1
    Join Date
    Jul 2006
    Posts
    80
    Mentioned
    1 Post(s)
    Quoted
    27 Post(s)

    Default Function Help

    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)

    Code:
      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.

  2. #2
    Join Date
    May 2007
    Location
    Everywhere
    Posts
    1,428
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

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

    Simba Code:
    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:
    Simba 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]:
    Simba Code:
    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

  3. #3
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

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

  4. #4
    Join Date
    Jul 2006
    Posts
    80
    Mentioned
    1 Post(s)
    Quoted
    27 Post(s)

    Default

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •