BetterAttributes | Control your instance attributes with ease

BetterAttributes

An OOP-Styled attribute controller for whatever your needs are

BetterAttributes is a ModuleScript designed to help developers use the current Attributes system in an easier way than before using simple OOP-styled way in a way it was not used before.

Example;

local BA = require(script.BetterAttributes)
local Atts = BA.Focus(script.Parent) -- Get the attributes from the parent of the script.

-- let's say the parent already has some attributes like 'Key1' (= "Val1") and 'Key2' (= "Val2")
print(Atts.Key1); --> "Val1"
Atts.Key1 = "NewVal1";
print(Atts.Key1); --> "NewVal1"
print(Atts.Key2); --> "Val2"

Atts.New("Key3","Huh"); -- Make sure the script will start listening to Key3 so it won't be nil later.
Atts.Key3 = Atts.Get(Atts.Key2); -- The .Get() part is optional, but will decrease the chance of a nil if such attribute exists but the script didn't listen to it.

API Docs, shown as an example (again);

local BetterAttributes = require(script.BetterAttributes);
local Attributes = BetterAttributes.Focus(script.Parent);

Attributes.Get("Attribute") --> instance:GetAttribute("Attribute") [Not being listened to]
Attributes.New("Attribute", 0) --> instance:SetAttribute("Attribute",0)
Attributes.Get("Attribute") --> 0 [Listened to]
Attributes.Attribute --> 0
Attributes.Attribute = 1 --> instance:SetAttribute("Attribute",1)

The Script:
You can get the modulescript directly from this link.
Alternatively, you can do local Attributes = require(7390744226).Focus(inst) to get the same result.

1 Like

I struggle to see how this is better than just using the two Get and Set methods.

For one, this module really doesn’t add any more “ease” to the process. All it does is shorten the method names, but in that process it adds a medium between the namecall and the actual procedure which is likely less efficient. Plus, it really only becomes a one character difference because this will autofill the rest.

Is this module really significant enough to be considered a community resource?

1 Like

Well, you’re not wrong, but considering that some new developers might use attributes (far more often than they should, may I mention), I thought that having an easier method of calling the attributes with Attributes.Attribute rather than repeatedly having instance:GetAttribute(“Attribute”) is better.

No, the module may not be that significant for experienced devs, but newer devs might use it (and probs even enjoy it).

I disagree. Attributes are already extremely easy to use…

I agree with both @twinqle and @foodman54. You can just add attributes to your script. It’s not hard to do. All this does is allow you to do that live.

2 Likes

i was gonna type something earlier but nah can you just delete this post