Results 1 to 4 of 4

Thread: References within procedure?

  1. #1
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default References within procedure?

    See comments within code - I'm trying to remove the strings:='bankbooth' and see if it's possible to put that within the parameter of the procedure itself?

    @KeepBotting;
    Simba Code:
    program new;
    {$I SRL/OSR.simba}
    type
      losevalueinfo = record
        tcts2: TCTS2Color;
        alpha, b: Int32;
      end;

    var
      strings: string;
      losevalue: losevalueinfo;
    procedure loadrecords();
    begin
      case lowercase(strings) of
        'bankbooth':        begin
                              losevalue.tcts2 := [1, 2, 3, 4];
                              losevalue.alpha := 1;
                              losevalue.b := 2;
                            end;
      end;
    end;

    procedure runbot1(strings:='bankbooth';);
    begin
      //strings:= 'bankbooth'; //this is the "reference" for loadrecords I'm trying to cut out this line and instead use it as a parameter
      loadrecords();
      writeln(losevalue.tcts2);
    end;

    procedure runbot();
    begin
      runbot1();
    end;

    begin
      runbot();          
    end.

    I can do procedure(strings: string = 'bankbooth') but this doesn't allow the reference to update when I loadrecords so the values return 0's.

  2. #2
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Yes, you can do this. For example:

    Simba Code:
    program new;

    procedure myProc(myParam: string = 'bankbooth');
    begin
      writeLn(myParam);
    end;

    begin
      myProc();
    end.

    This is what's known as a default parameter. It can easily be overridden, e.g. you can pass myProc('something else'); instead of the default.

    Edit: Re-reading, I see that you might actually be wanting to assign a new value to a global variable from within a function declaration. I do not think this is possible.

    Instead, you could re-structure your code. I edited this slightly so it would compile for me (don't have SRL on-hand atm):

    Simba Code:
    program new;

    type
      losevalueinfo = record
        tcts2: integer;
        alpha, b: integer;
      end;

    var
      strings: string; // unused now
      losevalue: losevalueinfo;

    procedure loadrecords(whichRecords: string); // accept a parameter instead of reading a global variable
    begin
      case lowercase(whichRecords) of
        'bankbooth':        begin
                              losevalue.tcts2 := 0;
                              losevalue.alpha := 1;
                              losevalue.b := 2;
                            end;
      end;
    end;

    procedure runbot1(usingWhat: string);
    begin
      loadrecords(usingWhat); // this is the main thing
      writeln(losevalue.tcts2);
    end;

    procedure runbot();
    begin
      runbot1('bankbooth'); // and utilize it
    end;

    begin
      runbot();
    end.
    Last edited by KeepBotting; 08-10-2018 at 02:50 AM.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  3. #3
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Yes, you can do this. For example:

    Simba Code:
    program new;

    procedure myProc(myParam: string = 'bankbooth');
    begin
      writeLn(myParam);
    end;

    begin
      myProc();
    end.

    This is what's known as a default parameter. It can easily be overridden, e.g. you can pass myProc('something else'); instead of the default.
    Yeah I know, but that's not the problem.

    So the problem is I'm trying to get the values of my records. These values will be changing occassionally so right now I have to do the following:

    Simba Code:
    procedure myproc();
    begin
      recordstring:='bankbooth';
      loadrecords(); //this has the bankbooth string
    writeln(myrecord.value1);
    end;

    This works, but I'm curious as to whether or not I can cut out the manual changing of the reference and include it within. I could do this... but that doesn't get rid of my still updating the reference.

    Simba Code:
    procedure myproc(updatestring: string ='bankbooth');
    begin
      recordstring:=updatestring; //I'm pretty sure this would work still don't see why not but this is the line I'm trying to cut out of the equation.
      loadrecords(); //this has the bankbooth string
    writeln(myrecord.value1);
    end;

  4. #4
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by BlitzKrieger View Post
    ...
    Simba Code:
    procedure myProc();
    begin
      loadRecords('bankbooth');
      writeln(myRecord.value);
    end;
    I am Ggzz..
    Hackintosher

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
  •