SuperAttribute - Easier Attributes with Private and ReadOnly attributes

Set and Get attributes easier! SuperAttribute allows you to create Private and ReadOnly attributes too!

This is my first announced Open Source Project that I have done. If you see anything wrong with this post please let me know! :+1:

Why Should You Use SuperAttribute?

SuperAttribute is really easy to use and is lightweight. SuperAttribute will save alot of time when dealing with attributes in your projects because you don’t have to deal with :SetAttribute and :GetAttribute.

You also get some extra features with SuperAttribute that the Roblox Engine currently does NOT support, like being able to use the arithmetic operators (+=, -=, *=, …) when using attributes. You also get access to Global, Private and ReadOnly attributes with SuperAttribute. :muscle:

SuperAttribute is focused on making your life easier by providing a simple API that will speed up your work with attributes!

🧰 Installation

You can install SuperAttribute via:
Wally Marketplace

The source can be found at
Github

đź“• Documentation

All the documentation needed is provided in this post!

đź“ť Usage

This Library is VERY easy to use.

To create an AttributeClass, you simply use the .new method SuperAttribute.new(Instance). The first argument is the Instance you want to bind the attributes with.

The SuperAttribute.new() returns 3 values:

  • Global (Where you’ll set and get GLOBAL (regular) attributes, they will show up as normal attributes in the attributes tab)
  • Private (Where you’ll set and get PRIVATE attributes, saved in the AttributeClass, they will NOT show up in the attributes tab)
  • ReadOnly (Where you’ll set and get READONLY attributes, the attribute is only readonly in the properties window and when other scripts try to change the value. It will show up in the attributes tab, but won’t be editable from outside of the script)

All of the SuperAttributes can be accessed with the Global variable, but not the other way around.

An example of this

local Global, Private, ReadOnly = SuperAttribute.new(MyPickaxe)

-- Global Example

Global.MineSpeed = 10

print(Global.MineSpeed) -- 10
print(ReadOnly.MineSpeed) -- nil
print(Private.MineSpeed) -- nil

-- ReadOnly Example

ReadOnly.ItemName = "Diamond Pickaxe"

print(Global.ItemName) -- "Diamond Pickaxe"
print(ReadOnly.ItemName) -- "Diamond Pickaxe"
print(Private.ItemName) -- nil

-- Private Example

Private.Debounce = false

print(Global.Debounce) -- false
print(ReadOnly.Debounce) -- nil
print(Private.Debounce) -- false

đź“‹ Use Case Example

-- Get SuperAttribute
local SuperAttribute = require(PARENT.SuperAttribute)

-- Create a new Attribute Class
local Global, Private, ReadOnly = SuperAttribute.new(MyCar)

-- Now just create your attributes!

Global.MaxSpeed = 100 -- Regular Attribute, does show up in the attributes tab.
Private.HasDriver = false -- Private Attribute, does not show up in the attributes tab with the Properties Tab
ReadOnly.Throttle = true -- ReadOnly Attribute (SuperAttribute Exclusive), does show up in the attributes tab but can't be changed from the window, must be changed within the script.

print(Global.MaxSpeed) -- 100
print(Global.HasDriver) -- false

print(Global.Throttle) -- true
Attributes.Throttle = false
print(Global.Throttle) -- false

Global.MaxSpeed += 30
print(Global.MaxSpeed) -- 130

TIP: You can also access a normal attribute that is not created via SuperAttribute. You can do so by indexing Global with the attribute name.

Think of it as a normal variable, you can use the normal Lua operators and such.

SuperAttribute also supports arithmetic operators, which the Roblox Engine does not support when it comes to dealing with attributes

đź“‹ Arithmetic Operators Example

-- This is the normal way to increment an attribute

Part:SetAttribute("Clicks", Part:GetAttribute("Clicks") + 1) -- 60 characters

-- This is the SuperAttribute way of doing the same thing

Global.Clicks += 1 -- 18  characters

-- This leaves us with an astonishing 70% code reduction!

Now this might seem like magic at first, but it really isn’t. It’s just a way to manage object attributes easier, with some extra features included.

Feedback is appreciated!

Would you use this in a game?
  • Yes
  • No
  • Maybe
  • Sometimes

0 voters

8 Likes

Cool library, by the way the link to Wally does not work

Thank you!

Hmm, that’s weird. It works for me. Maybe it takes a while for the site to setup or something.

You could go to Wally and search for it there.

The link in the github is working, but when I click on the link, it shows me that the page has not been found, but there is your library on the Wally page

Oh! You meant the one in Github, thank you for telling me. It should be fixed now.

this seems like a cool trick however I don’t know where I’d use this, was desiring something like parent:FindFirstChildWithAttribute upon viewing thread,

will probably make something like that to code enemy’s ais (by simply doing something like attributestable[parent][tag][1] internally so I don’t have to iterate thru a table or do weird string magic and make my function super bloaty with collectionservice to code multiple enemy’s ais as best as i can think of.)

1 Like

Pretty neat resource. I don’t really think people will use this in games for most cases. I can see this being used in resources though. I probably won’t be using this anytime soon, but respect the effort. Good job!

1 Like