Results 1 to 13 of 13

Thread: More constants in SRL.

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

    Default More constants in SRL.

    I believe that constants can make a huge difference in code readability, and also allow source code of a program itself to change, without affecting it's end users' code.
    Take for example the latest GameTab() update in SRL. SRL now uses constants for each tab number, defined in SRL.

    This is a great addition, and I believe every function in SRL should have it's own constants. (Only if it has arguments that are usually defined with numbers, or strings.)
    It can GREATLY improve readability and backwards compatiblity.

    I think this job would be tough one to do for a single developer, so I was hoping this could be done as a team of several members and/or developers?

    Before we start off, we will need some general formula for creating constant names.
    EG:

    DropPattern(which: integer)
    would have these constants:
    pascal Code:
    drop_patt_up_down = 1;
    drop_patt_snake = 2;

    First four characters of each function name + underscore and 4 characters of the next `Camelcase' part. And finally a underscore + short description of a constant?
    Last edited by Wizzup?; 07-20-2009 at 05:54 AM.



    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)

  2. #2
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Made_me_happy = True;
    Last edited by mastaraymond; 07-20-2009 at 05:31 AM.
    Verrekte Koekwous

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

    Default

    Quote Originally Posted by mastaraymond View Post
    Made_me_cum = True;
    Get mature, yours isn't even a centimeter...

    Yeah, good idea, or continuing on a good idea!
    I never changed anything in the SRL include, so maybe I will do this.
    ~Hermen

  4. #4
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Hermen View Post
    Get mature, yours isn't even a centimeter...

    Yeah, good idea, or continuing on a good idea!
    I never changed anything in the SRL include, so maybe I will do this.
    What you on about?

    Yes, constants should be the future. They are a far better than passing strings to indicate something.
    Verrekte Koekwous

  5. #5
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    You better post this Inside SRL so the people who need to read this actually will.
    I made a new script, check it out!.

  6. #6
    Join Date
    Mar 2007
    Posts
    3,042
    Mentioned
    1 Post(s)
    Quoted
    14 Post(s)

    Default

    Skill level integers should be constants as well, though I don't think they need to follow this naming schema. Something like skill_attack would work fine.
    :-)

  7. #7
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    In other cases, where the update-able numbers/strings only effect one function, should they be local or global? For example, for InvBox to calculate the clickable areas correctly, you need the X1, Y1, X2, Y2 of the first slot in the first row, and the X1, Y1 of the second slot in the second row. Rather than having 6 variables Inv_Box_X1, Inv_Box_Y1....etc, I clumped them all together into a couple of TBoxes. I'm thinking keep local for this case, as I don't see why a scripter would need to use those values, plus if they really wanted them they could generate them by using InvBox itself.

    SCAR Code:
    {*******************************************************************************
    Function InvBox(i :Integer): TBox;
    By: Boreas. Coords by Ogre July 15th 2009.
    Description: Returns TBox of surrounding Inventory SlotBox
    1-2-3-4
    5-6-7-8
    etc.
    *******************************************************************************}


    function InvBox(i :Integer): TBox;
    var Slot1, Slot6: TBox;
    begin
      if not InRange(I, 1, 28) then
      begin
        srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
        exit;
      end;
      Slot1 := IntToBox(563,213,594,244);     //update these
      Slot6 := IntToBox(605,249,31415,92653); //except pi :p
      Result.x1 :=Slot1.X1+((((i+(4-1))mod 4))*(Slot6.X1-Slot1.X1)); //4 for number
      Result.y1 :=Slot1.Y1+((((i-1)/4))*(Slot6.Y1-Slot1.Y1));        //of columns
      Result.x2 := Result.x1+(Slot1.X2-Slot1.X1);
      Result.y2 := Result.y1+(Slot1.Y2-Slot1.Y1);
    end;

    //when i click i dont just click within the black outline
    procedure MMouseItem(i: Integer);
    var
      TB: TBox;
    begin
      GameTab(tab_inv);
      TB:=InvBox(I);
      MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2,3);
    end;

    That was in the OpenDev SVN the other day, but now somebody has replaced it with the old one...

  8. #8
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Sounds good to me, if we take what Method said in consideration:

    Quote Originally Posted by Method View Post
    Skill level integers should be constants as well, though I don't think they need to follow this naming schema. Something like skill_attack would work fine.
    And also, Boreas; someone forgot to checkout before committing again. Gah, people need to learn how to do that.
    Just readd it.

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

    Default

    SCAR Code:
    //****************************************************************************//
    // * GameTab 2 Related Functions.
    //****************************************************************************//

    { const Skill Constants;
      Description: Constants representing player skills. }

    const
      skill_Attack = 1;
      skill_Strength = 2;
      skill_Defence = 3;
      skill_Range = 4;
      skill_Prayer = 5;
      skill_Magic = 6;
      skill_Runecrafting = 7;
      skill_Hitpoints = 8;
      skill_Agility = 9;
      skill_Herblore = 10;
      skill_Thieving = 11;
      skill_Crafting = 12;
      skill_Fletching = 13;
      skill_Slayer = 14;
      skill_Mining = 15;
      skill_Smithing = 16;
      skill_Fishing = 17;
      skill_Cooking = 18;
      skill_Firemaking = 19;
      skill_Woodcutting = 20;
      skill_Farming = 21;
      skill_Construction = 22;
      skill_Hunting = 23;
      skill_Summoning = 24;

    I'll just leave this here..
    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

  10. #10
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    SCAR Code:
    //****************************************************************************//
    // * GameTab 2 Related Functions.
    //****************************************************************************//

    { const Skill Constants;
      Description: Constants representing player skills. }

    const
      skill_Attack = 1;
      skill_Strength = 2;
      skill_Defence = 3;
      skill_Range = 4;
      skill_Prayer = 5;
      skill_Magic = 6;
      skill_Runecrafting = 7;
      skill_Hitpoints = 8;
      skill_Agility = 9;
      skill_Herblore = 10;
      skill_Thieving = 11;
      skill_Crafting = 12;
      skill_Fletching = 13;
      skill_Slayer = 14;
      skill_Mining = 15;
      skill_Smithing = 16;
      skill_Fishing = 17;
      skill_Cooking = 18;
      skill_Firemaking = 19;
      skill_Woodcutting = 20;
      skill_Farming = 21;
      skill_Construction = 22;
      skill_Hunting = 23;
      skill_Summoning = 24;

    I'll just leave this here..
    mwah i was alrdy using these in my fighter!

    i don't think all the functions need constants, for example DropPattern.
    things that might change in rs like gametabs and skills require a constant, because if jagex makes a new skill between attack and strength, you wouldn't need to update all scripts like GetSkillLevel(2)->GetSkillLevel(3), you can just use GetSkillLevel(skill_Strength). I know, in this case you can use GetSkillLevel('strength') but anyways...

  11. #11
    Join Date
    Mar 2007
    Posts
    3,042
    Mentioned
    1 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    SCAR Code:
    //****************************************************************************//
    // * GameTab 2 Related Functions.
    //****************************************************************************//

    { const Skill Constants;
      Description: Constants representing player skills. }

    const
      skill_Attack = 1;
      skill_Strength = 2;
      skill_Defence = 3;
      skill_Range = 4;
      skill_Prayer = 5;
      skill_Magic = 6;
      skill_Runecrafting = 7;
      skill_Hitpoints = 8;
      skill_Agility = 9;
      skill_Herblore = 10;
      skill_Thieving = 11;
      skill_Crafting = 12;
      skill_Fletching = 13;
      skill_Slayer = 14;
      skill_Mining = 15;
      skill_Smithing = 16;
      skill_Fishing = 17;
      skill_Cooking = 18;
      skill_Firemaking = 19;
      skill_Woodcutting = 20;
      skill_Farming = 21;
      skill_Construction = 22;
      skill_Hunting = 23;
      skill_Summoning = 24;

    I'll just leave this here..
    Was this ever announced? I don't remember reading about it and I certainly haven't seen these constants until now (though I don't really browse through the include anyways).
    :-)

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

    Default

    I am not only talking about Skills.scar or GameTab.scar; I was talking about SRL as a whole, rather.



    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)

  13. #13
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    I see how this was brought up, specially with the major changes in GameTab so that we can do:
    Tab_Inventory := 5;
    GameTab(Tab_Inventory);

    Instead of having EVERYONE change their scripts...
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

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
  •