Results 1 to 6 of 6

Thread: How to get a function to be true after a procedure has executed?

  1. #1
    Join Date
    Mar 2013
    Location
    Shaolin
    Posts
    863
    Mentioned
    24 Post(s)
    Quoted
    519 Post(s)

    Default How to get a function to be true after a procedure has executed?

    This is a pretty simple thing but I can't get it to work, probably because I have it completely wrong

    Simba Code:
    function didTheStuff(): Boolean;
    begin
    end;

    procedure doTheprocedure();
    begin
      walkToBank;
      dosomethings;
      morethings;
      someotherstuff;
      plusonemorething;
        didThestuff() = True;
    end;

    This is mostly what it is, but when I try to writeLn() it for false and true it always comes out false. What do I have to put in the function to have a difference between true and false? Shouldn't it store whatever true or false value I assign to it? I don't want any failsafes or if (aconfirmation) then things in the function I just want it to state whether or not the script has determined it to be true or false after execution of dotheprocedure.

    Thanks

    ~Wu

    EDIT: I will also only be running doTheProcedure once for the entire running of the script so the value for True has to remain true for the entirety of the runtime after it has been changed from false at the start.
    You have permission to steal anything I've ever made...

  2. #2
    Join Date
    Sep 2014
    Location
    C:\Simba\
    Posts
    565
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    Simba Code:
    function yourFunc() : boolean;
    begin
      result := true;
    end;

    Or the smarter thing would be what @Borland; said.
    Last edited by Joopi; 01-17-2017 at 05:00 PM.
    Feel free to ask me any questions, I will do my best to answer them!

    Previously known as YouPee.

  3. #3
    Join Date
    Dec 2011
    Posts
    193
    Mentioned
    5 Post(s)
    Quoted
    51 Post(s)

    Default

    What's the reason for avoiding the use of a global Boolean?

    Simba Code:
    var
      StuffDone: Boolean;

    procedure doTheprocedure();
    begin
      walkToBank;
      dosomethings;
      morethings;
      someotherstuff;
      plusonemorething;
        StuffDone := True;
    end;

    This is mostly what it is, but when I try to writeLn() it for false and true it always comes out false.
    That's because you have used the "=" (comparative) sign instead of the ":=" (assignment) sign. So when you debug didTheStuff, seeing as nothing is inside the function, it returns the default value of False. If you were to use ":=", the script will not compile as you are trying to use it like regular varibale. The value of didTheStuff is the value of Result inside the function.

    Now, with pointers we can accomplish resulting didTheStuff as true despite it being an empty function, but that would only make any sense to do if you absolutely cannot use a global variable like above.

  4. #4
    Join Date
    Mar 2013
    Location
    Shaolin
    Posts
    863
    Mentioned
    24 Post(s)
    Quoted
    519 Post(s)

    Default

    Quote Originally Posted by Joopi View Post
    Simba Code:
    function yourFunc() : boolean;
    begin
      result := true;
    end;

    Or the smarter thing would be what @Borland; said.
    I had already tried this and it still returned false?

    Quote Originally Posted by Borland View Post
    What's the reason for avoiding the use of a global Boolean?

    Simba Code:
    var
      StuffDone: Boolean;

    procedure doTheprocedure();
    begin
      walkToBank;
      dosomethings;
      morethings;
      someotherstuff;
      plusonemorething;
        StuffDone := True;
    end;
    I was unaware that could be done thank you

    EDIT:
    Simba Code:
    didtheprocedure = true;
      if (didTheprocedure = false) then
        begin
          writeln('no deal');
        end;
      if (didtheprocedure = true) then
        begin
          writeln('deal');
        end;

    still returns no deal @Borland any ideas?
    You have permission to steal anything I've ever made...

  5. #5
    Join Date
    Dec 2011
    Posts
    193
    Mentioned
    5 Post(s)
    Quoted
    51 Post(s)

    Default

    Read the bottom parts of my other post, added some bits. Specifically read the bits about "=" and ":="

    I had already tried this and it still returned false?
    It should return true, probably same error as above. Paste the following into simba and run it.


    Simba Code:
    function BoolFunc: Boolean;
    begin
      Result := True;
    end;

    begin
      Writeln(BoolFunc);
    end.

    Edit:

    Also, you could tidy up that code (if you was doing it for full verbosity to debug your issue, then ignore me) like the following:
    Simba Code:
    if didTheprocedure then
      writeln('deal')
    else
      writeln('no deal');

    A Boolean only has two states, so if it's not the first, it has to be the second.

  6. #6
    Join Date
    Mar 2013
    Location
    Shaolin
    Posts
    863
    Mentioned
    24 Post(s)
    Quoted
    519 Post(s)

    Default

    Quote Originally Posted by Borland View Post
    Read the bottom parts of my other post, added some bits. Specifically read the bits about "=" and ":="



    It should return true, probably same error as above. Paste the following into simba and run it.


    Simba Code:
    function BoolFunc: Boolean;
    begin
      Result := True;
    end;

    begin
      Writeln(BoolFunc);
    end.

    Edit:

    Also, you could tidy up that code (if you was doing it for full verbosity to debug your issue, then ignore me) like the following:
    Simba Code:
    if didTheprocedure then
      writeln('deal')
    else
      writeln('no deal');

    A Boolean only has two states, so if it's not the first, it has to be the second.
    the := made all the difference thank you
    You have permission to steal anything I've ever made...

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
  •