Hey there developers!
Here’s a new and a very useful module I created named Better Stack. This is a module created in Lua for Roblox Studio. It expands the limits of a regular Lua stack which has more than 20 functions to use. New Functions are added frequently. It is completely Open Source!
If you don’t know what a Stack is -
A stack is a Last-In-First-Out (LIFO) data structure. It is very commonly used in computer programming. A stack can easily be imagined as a stack of dinner plates. You start with one, and then you put another on top. In order to get to the very first plate, you must remove the plate(s) on top of it. So you remove the last plate first . The act of putting a plate on top of the stack is called pushing while removing a plate from the top is called popping .
About
This is a module based on the data structure known as Stack. It has tons of functions you can use, whether it be connecting to stacks, pushing elements to a stack, popping elements from a stack or arithmetic operations. This module has it all!
Why Is There A Need To Use This Model?
Inside Roblox Studio the data structure Stack is not a thing. What I mean by this is there isn’t an inbuilt stack for you to use. In order to use a Stack you had to code it yourself. To make everyone’s task easier. I went out of my way to create this useful module! It has more than 20 functions! (New functions are added frequently) for you to use! Its not just a normal Stack. It has so many useful functions which will be listed down in the post in the Documentation section hence the name Better Stack
Important Links
Get the Module here
Github Repository
Instructions
To run the functions you must get the module here which has also been listen above in Important Links.
When you get the model. A script named Instructions has pop up in explorer. You must read it for the module to work.
-
Step 1 - Place the module script named “BetterStack” that is present inside the “Instructions” script, inside the Replicated Storage.
-
Step 2 - To start using the module. You’ll have to require it. Type the following code inside any script you want the Stack to be present in.
local BetterStack = game:GetService("ReplicatedStorage").BetterStack
That’s all! Enjoy using the module! The setup is complete. Now you can view the Documentation down below.
Documentation
All functions and code examples are listed below. Almost all these functions can be printed using print()
. They can also be stored in variables!
Make sure to have this in your script!
local BS = require(game:GetService("ReplicatedStorage").BetterStack)
Declare a Stack | .new
local myStack = BS.new()
Push an element | :push()
myStack:push(10) --my stack is now 10 (Top element is 10)
myStack:push("Hello") --my stack is now 10, "Hello" (Top element is "Hello")
Pop an element | :pop()
myStack:pop() --my stack is now back to 10
(Print Function can also be used. The value can also be stored in other variables)
Push multiple elements to a stack | :pushMany()
myStack:pushMany(3,4,5,6,7,7,8,8) --adds all these elements to the stack at once
Top element of the Stack | :top()
myStack:top() --stores the top value in the stack
Bottom element of the Stack | :bottom()
myStack:bottom() --stores the bottom value in the stack
Delete a stack | :bomb()
myStack:bomb() --makes the stack empty
Size of the Stack | :size()
myStack:size() --size of the stack aka number of elements in the stack
Remove N number of elements from the top of the stack | :cut()
myStack:cut(2) --remove top 2 elements from the stack
Connect multiple stacks to a stack | :pile()
myStack:pile(stack2, stack3)
Print the stack at once | :print()
myStack:print() --prints the stack
Check if a value is present in a stack | :find()
myStack:find("Epic") --returns true if "Epic" is present in the stack, else returns false
Get minimum value in the stack | :min()
myStack:min() --gets minimum element from the stack (only possible with numbers)
Get maximum value in the stack | :max()
myStack:max() --gets maximum element from the stack (only possible with numbers)
Get average of all elements in the stack | :average()
myStack:average() --returns average of all elements in the stack (only possible with numbers)
Get middle element in stack | :mid()
myStack:mid() --returns middle element of the stack
Check if the stack is empty | :isEmpty()
myStack:isEmpty() --returns boolean value
Set a description about the stack | :desc()
local description = myStack:desc("This is a better stack!") --sets description of the stack provided in the argument
Check the most frequent values in the stack | :based()
myStack:based() --returns the most frequent values
Returns “String Based” if most of the values are Strings
Returns “Number Baed” if most of the values are Numbers
Returns “Boolean Based” if most of the values are Booleans
Returns “Multi Based” if multiple types of values are equally present in the stack.
Check frequency of an Element | :freq()
myStack:freq(4) --returns the frequency of the element "4"
Check if stack has a String value in it | :hasString()
myStack:hasString() --returns boolean value
Check if stack has a Number value in it | :hasNumber()
myStack:hasNumber() --returns boolean value
Check if stack has a boolean value in it | :hasBool()
myStack:hasBool() --returns boolean value
That is all for the documentation
Thank you for reading my post!
Hope the module helps you in your development!
If you would like to ask queries or give feedback be sure to reply down below!
- 1
- 2
- 3
- 4
- 5
0 voters
Thanks!