SRL Archive - SRL Suggestions

More constants in SRL.


Wizzup?

2009-07-19 22:17:30

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:

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?

mastaraymond

2009-07-19 22:19:11

Made_me_happy = True;

ShowerThoughts

2009-07-19 22:21:48

From: mastaraymond
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.

mastaraymond

2009-07-20 01:32:50

From: Hermen
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.

Markus

2009-07-20 01:52:05

You better post this Inside SRL so the people who need to read this actually will.

Method

2009-07-20 02:21:28

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.

Boreas

2009-07-20 04:27:43

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.

{*******************************************************************************
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…:duh:

EvilChicken!

2009-07-20 05:56:39

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

From: Method
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.

Nava2

2009-07-20 06:32:11

//****************************************************************************//
// * 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..

marpis

2009-07-20 08:27:30

From: Nava2
//****************************************************************************//
// * 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…

Method

2009-07-20 08:34:42

From: Nava2
//****************************************************************************//
// * 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).

Wizzup?

2009-07-20 12:47:00

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

Narcle

2009-07-21 15:28:08

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…