Results 1 to 17 of 17

Thread: SRL Shortening

  1. #1
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default SRL Shortening

    I am not sure if anything I am doing makes a difference, but whatever.

    FindCoins
    SCAR Code:
    V: array [0..1] of TVariantArray;//i changed that 1 from a 2 since i couldnt find where a a [2] would be used.


    function CheckArea(area: string): Boolean;
    doesnt need the writeln at the end. Its checking to see if one is open, writing it is pointless.


    AreaInfo
    SCAR Code:
    procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
      colnumber, rownumber: Integer);
    var a: array [0..4] of tintegerarray;
        e: integer;
    begin
      a[0] := [560,212,36,42,4,7];
      a[1] := [63,97,55,39,21,4];
      a[2] := [35,91,44,44,10,5];
      a[3] := [310,75,32,49,4,7];
      a[4] := [24,75,32,49,4,7];
      case LowerCase(area) of
        'inv', 'inventory': e := 0;
        'shop':             e := 1;
        'bank':             e := 2;
        'trade':            e := 3;
        'your trade':       e := 4;
      else writeln('AreaInfo');
      end;
      startx := a[e][0];
      starty := a[e][1];
      rowsize := a[e][2];
      colsize := a[e][3];
      colnumber := a[e][4];
      rownumber := a[e][5];
    end;
    That is shortened quite bit.

    EDIT: but this is better
    SCAR Code:
    procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
      colnumber, rownumber: Integer);
    var a: array [0..4] of tintegerarray;
        s: TStringArray;
        e, i: integer;
        Opt : TIntegerArray;
    begin
      a[0] := [560,212,36,42,4,7];
      a[1] := [63,97,55,39,21,4];
      a[2] := [35,91,44,44,10,5];
      a[3] := [310,75,32,49,4,7];
      a[4] := [24,75,32,49,4,7];
      Opt := [startx, starty, rowsize, colsize, colnumber, rownumber];
      s := ['inv', 'inventory', 'shop', 'bank', 'trade', 'your trade'];
      for I := 2 to High(S) Do
        case LowerCase(area) of
          s[I] : e := i - 1;
        end;
      writeln(e);
      for I := 0 To High(Opt) Do
        Opt[I] := a[e][I];
    end;

    Small things, but yah.

    I also wonder if all the headings and whatnot are good for being in the code. I can see them being nicely documented somewhere, but having them all inside the code itself just makes the files larger and annoying to navigate through. I would say doing something similar to the php manual, with all nice examples and stuff inside, but that would probably be a large undertaking. Lacking that, I think just making sure there is documentation online of all of the functions would be enough to have and just delete everything out of the code itself.

    So far ive only gone through amount.scar, but there will probably be other shortenings that can be done. I dont know what the devs do exactly, but going back through SRL functions, even if its not broken, to see what can be improved upon could prove useful if not already done.

    Anyways, I was just perusing SRL and saw a few things i might be able to improve upon.
    Last edited by Dan Cardin; 10-10-2009 at 01:04 PM.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  2. #2
    Join Date
    Jul 2008
    Location
    England
    Posts
    763
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I've got one here too, i made it only one line:

    SCAR Code:
    function InvEmpty: Boolean;
    begin
      Result := InvCount = 0;
    end;
    Last edited by Quickmarch; 06-20-2009 at 01:36 AM.
    lol

  3. #3
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    If I recall correctly,
    Wizzup wants to keep the original Pascal.
    And not the [0..25] stuff, so goes for a := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

  4. #4
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    My contribution (not sure if it works)

    SCAR Code:
    Function TradeScreen: Variant;
    Begin
      Result := (GetColor(90, 61) = 2070783)
      If Result = 0 Then Result := 2;
    End;

    Edit, on your first proc .


    SCAR Code:
    procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
      colnumber, rownumber: Integer);
    var a: array [0..4] of tintegerarray;
        s: TStringArray;
        e, i: integer;
    begin
      a[0] := [560,212,36,42,4,7];
      a[1] := [63,97,55,39,21,4];
      a[2] := [35,91,44,44,10,5];
      a[3] := [310,75,32,49,4,7];
      a[4] := [24,75,32,49,4,7];
      s := ['inv', 'inventory', 'shop', 'bank', 'trade', 'your trade'];
      For I := 0 to High(S) Do
        case LowerCase(area) of
          s[I] : e := StrToint(S[I]);
        else writeln('AreaInfo');
      end;  
      startx := a[e][0];
      starty := a[e][1];
      rowsize := a[e][2];
      colsize := a[e][3];
      colnumber := a[e][4];
      rownumber := a[e][5];
    end;

    You should also store rownumber and those categorical variables to an Integer Array then use a loop to call them

    Edit, just did that:

    SCAR Code:
    procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
      colnumber, rownumber: Integer);
    var a: array [0..4] of tintegerarray;
        s: TStringArray;
        e, i: integer;
        Opt : TIntegerArray;
    begin
      a[0] := [560,212,36,42,4,7];
      a[1] := [63,97,55,39,21,4];
      a[2] := [35,91,44,44,10,5];
      a[3] := [310,75,32,49,4,7];
      a[4] := [24,75,32,49,4,7];
      Opt := [startx, starty, rowsize, colsize, colnumber, rownumber];
      s := ['inv', 'inventory', 'shop', 'bank', 'trade', 'your trade'];
      For I := 0 to High(S) Do
        case LowerCase(area) of
          s[I] : e := StrToint(S[I]);
        else writeln('AreaInfo');
      end;
      For I := 0 To High(Opt) Do
        Opt[I] := a[e][I];
    end;
    Last edited by Naum; 06-20-2009 at 04:18 AM.

  5. #5
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    People remember, shortened doesn't means better++ it just makes readable-- .
    ~Hermen

  6. #6
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    NaumanAkhlaQ - Your version calls inv and inventory different numbers by the way. and idk what that opt deal is supposed to do.

    Hermen - shortened = better if it works better. And to me, shortened, even if more complicated things are happening, is less complicated since i can see everything. For example i could make a function like this
    SCAR Code:
    function meow(m,q: integer): integer;
    var a,b,e,c,d, l: integer;
    begin
      a := 5;
      b := 15
      c := m;
      d := q;
      e := q+m;
      l := a + b + c+ d+ e*2;
      result := l;
    end;
    but that could easily be turned into one line. And still be better.

    n1ke! - i have no idea what you mean.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  7. #7
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Dan Cardin View Post
    NaumanAkhlaQ - Your version calls inv and inventory different numbers by the way. and idk what that opt deal is supposed to do.

    Hermen - shortened = better if it works better. And to me, shortened, even if more complicated things are happening, is less complicated since i can see everything. For example i could make a function like this
    SCAR Code:
    function meow(m,q: integer): integer;
    var a,b,e,c,d, l: integer;
    begin
      a := 5;
      b := 15
      c := m;
      d := q;
      e := q+m;
      l := a + b + c+ d+ e*2;
      result := l;
    end;
    but that could easily be turned into one line. And still be better.

    n1ke! - i have no idea what you mean.
    First Question, your correct sorry . Also the 'opt' deal is to set the number looping through the array so 'inv' would be 0 and 'inventory' would be 1 (which is wrong atm) andso on (if I can fix it )

  8. #8
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    My contribution (not sure if it works)

    SCAR Code:
    Function TradeScreen: Variant;
    Begin
      Result := (GetColor(90, 61) = 2070783)
      If Result = 0 Then Result := 2;
    End;

    Edit, on your first proc .
    No that wouldn't work. And why a variant?

    SCAR Code:
    Description: Returns 1 or 2 for the respective tradescreens, 0 if neither is open.

    Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.

  9. #9
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by Dan Cardin View Post
    n1ke! - i have no idea what you mean.
    I think he means that Wizzup doesn't want to count the 0 in arrays.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  10. #10
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    No that wouldn't work. And why a variant?

    SCAR Code:
    Description: Returns 1 or 2 for the respective tradescreens, 0 if neither is open.

    Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.
    Uhh would'nt that return the GetColor of 0?

  11. #11
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.
    I disagree. If you needed to change a value, then just change it, they're all in the same line. If you need to add more areas, then you just change the array size and add another line, where in your way, you need to add another case section and it would get bigger and more annoying.

    For the most part, shortening it in the way that i did, is better imo.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  12. #12
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Dan Cardin View Post
    I disagree. If you needed to change a value, then just change it, they're all in the same line. If you need to add more areas, then you just change the array size and add another line, where in your way, you need to add another case section and it would get bigger and more annoying.

    For the most part, shortening it in the way that i did, is better imo.
    I agree, it does need to be commented though.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  13. #13
    Join Date
    Dec 2006
    Posts
    908
    Mentioned
    1 Post(s)
    Quoted
    17 Post(s)

    Default

    get rid of 0 in arrays pl0x....hate it because it ??? me.

  14. #14
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Quote Originally Posted by Deathscytex View Post
    get rid of 0 in arrays pl0x....hate it because it ??? me.
    Really? Most of the languages I know use 0 indexed arrays.

  15. #15
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by senrath View Post
    Really? Most of the languages I know use 0 indexed arrays.
    I think all but really a few don't.
    ~Hermen

  16. #16
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    I agree, it does need to be commented though.
    Like i said. As long as there was good documentation in a separate help file, or online (or both), then it's not needed inside the code itself as it just makes the files bigger, longer, and more confusing. At first it would be fine to just transport everything to being separate, but I think it would be much better to have a PHP like manual that is much more extensive eventually (like what Freddy started doing with SCAR).
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  17. #17
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    No that wouldn't work. And why a variant?

    SCAR Code:
    Description: Returns 1 or 2 for the respective tradescreens, 0 if neither is open.

    Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.
    I agree with Zeph.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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