Note: We use horizontal separator lines to indicate different parts of the post, if you want to skip a part, go to the next separator line.
The fastest answer to the question “What is SLib?”
SLib is a versatile library whose functions are used in any project, SLib improves code quality several times, increases its readability, prevents errors, and thus makes your project better and faster than before! The following code is just one of the things that SLib does:
With SLib: Just 1 Line, Just 1 Parameter For Work As Well, Automated Error-Handling, With Very Simple Syntax!
Any code is even shorter than the text you’re writing about!
# This one line of code creates a backup of the player's data file with an optional
# suffix next to it, it has the ability to check all types of errors and manage them,
# prevent syntax errors, repeating lines and code length.
SLib.backup_file("user://main_data.json", TYPE_DICT)
It’s so long that by the time you get to the end, you’ll have forgotten what this code is for…
# These 11 lines of code do the same thing as one line above, with the difference that
# the file suffix and path must be specified in several places each time.
# and creates variables that are no longer usable!
var target_file = "user://main_data.json"
var file_access := FileAccess.open(target_file, FileAccess.READ)
var json_string := file_access.get_line()
file_access.close()
var json := JSON.new()
json.parse(json_string)
var data = json.data
var backup_json_string := JSON.stringify(data)
var backup_file_access := FileAccess.open(target_file.get_basename() + "-Backup." +target_file.get_extension(), FileAccess.WRITE)
backup_file_access.store_var(backup_json_string)
backup_file_access.close()
Thank you for your contribution.
One way to make it even better is if you could incorporate Godot-styled documentation. That way, the method documentation can be opened and explained straight from within the editor.
Thanks for your work! I am looking for something like your library but at the moment I’d use maybe 2 functions, since it’s very project specific you know? I have the same issue with similar libraries for Godot that are hosted on Github. Will you accept contributions?
But this variable is already accessable by the autoload? I believe this will produce a warning/error for shadowing the autoload and recommend removing this step 3 from the install instructions.
The SendError function is being used backwards in the SLib.gd, the first argument is defined as the error message, and the second argument is the location. So the doc comments reports errors will say
“Can’t load from -->file_location<–, file not exists!” From “BackupFile”
But the actual error reads:
“BackupFile” From “Can’t load from -->file_location<–, file not exists!”
I find myself using these two functions often, if you want to include them:
## finds the first child of a given class, does not find class_name declarations
func find_child_of_class(node: Node, typename: StringName, descendants: bool = false) -> Node:
for child in node.get_children():
if child.is_class(typename):
return child
elif descendants:
var found: Node = find_child_of_class(child, typename, descendants)
if found:
return found
return null
## time based smooth interpolation, [b]not framedependant[/b] like [code]a = lerp(a, b, delta)[/code]
## Set [i]decay[/i] to 1-25 for a good range of values
func exp_decay(a, b, decay: float, delta: float):
return b + (a - b) * exp(-decay * delta)
Thank you very much! All fixed and added the two functions you mentioned, I have publish a pre-release version for try, if there are any problems with it I will be happy to state it here!
The pre-release is available here:
The major changes of these changes have been made according to the participation in this topic.
Thank you all and I hope you find this helpful!
I still welcome new suggestions but I recommend creating a fork.
1.0.3 Beta (2):
A heads up, seems like you’ve committed the .godot directory to your github. It’s highly recommended to remove and ignore that directory. I can see your personal editor changes in the repository and some of your computer’s filepaths.
SLib is a plugin that makes your code much more readable, cleaner, and more stable after installation. This library offers long processes with just one line of code by putting frequently used code into ready-to-use functions. Join the SLib community and take your code to the next level:
Three months after our last release , we’re thrilled to announce the launch of version 1.1.0 beta 1 today! With an astounding 600 changes and the longest changelog in our history, SLib is on the cusp of a stable release, and we can’t wait for you to explore the significant enhancements in structure and documentation.
SLib is designed to empower developers with a suite of complementary functions, all wrapped in user-friendly formats:
Experience unparalleled code readability that transforms debugging and development into an enjoyable journey.
Say goodbye to lengthy code; with just a single line, you can automate entire processes.
Accelerate your development speed by cutting through code complexity, allowing you to concentrate on what truly matters—your project logic.
Seamlessly connect related tasks, even those that lack syntactical similarities, to streamline your workflow.
Enjoy lightning-fast, efficient file interactions, bolstered by an intelligent automated error management system.
Personalize your debugging experience to suit your needs.
Break free from the constraints of default functions.
Watch as keywords are automatically recognized and converted into library functions, letting you code without the traditional coding hassle!
And there’s so much more to discover.
This beta version boasts major updates and, as of now, is free from known issues. It’s your opportunity for a final review to ensure everything functions smoothly while we refine the documentation and macros, And it’s a great time to adapt your project to minor library changes before the official release!
Curious to see SLib in action? Check out our project’s public webpage:
For projects that you already have SLib installed on, Merging Method for Update is the fastest way to update, review here to make sure you’re using the best possible method!
For the best experience for new developer with SLib, we highly recommend a quick start!
After some time of not expanding the library, SLib is now back with the stabilization of extensive and fundamental changes. Prepare to update your plugin in your projects, otherwise missing out on these new features will slow down your progress!
What’s New?
Since the previous stable version (1.0.7), SLib has changed so much that this update is marked as a direct leap and a major update. But what has happened in this time? Let’s take a look together!
Extensive improvements, Let's do it better than ever!
New Functions, Better Access
New SLib functions like set_file_location and localize_path break the limitations! From now on, defining file paths at runtime and returning to relative paths is possible.
Completely Reliable
We have added numerous checks to prevent any possible errors and made several fixes to ensure error-free operation. Now everything will be under control! We have also implemented a new format for errors and warnings that makes understanding errors easier!
New Naming Conventions
Minor changes have been made to the names of some functions and parameters to ensure that everything is in its place and completely clear. This will not break previous versions in most cases, but to be sure, you can go to the ChangeLogs in the project repository!
Faster and Simpler
As the philosophy of creating SLib is to reduce complexity as much as possible while maintaining an appropriate level of customization and flexibility, we have now added features to improve the performance of functions. This includes automatic conversion of file paths where necessary and a few extra optional parameters. Additionally, improving the quality of the library code now increases speed and makes following the code path easier!
An intelligent file management system, SLib introduces you to AFMS!
In the previous update, we added many features to the file saving and loading functions, which increased the number of functions and the complexity of each one. Now, after reviewing several alternative solutions, we have arrived at a suitable method to return to the simplicity of the past! From now on, support for various file types, along with automatic type detection and type distinction, has been added! You can also now optimize performance by setting the file type. Now, 12 functions are usable in only 3 functions, without any conflicts!
Clear and precise documentation
One of SLib’s strengths is its comprehensive documentation. Now, with the internal documentation updated and reformatted, everything is in place! Press F1, search for SLibDocs, and see a detailed explanation of everything!
Animations; as easy as typing!
Thanks to @Locher for recommendation about appear and disappear functions for previous versions, we have now replaced them with a flexible animation system with easy access. From now on, you can run various animations on objects with just one line of code, without the need for special code blocks!
We have incorporated suitable capabilities to improve this feature by adding new animations to the existing ones. You can also be a contributor to this library by submitting new animations and your ideas!
Are macros no longer a thing?!
Due to inconsistencies and issues related to incorporating macros into the library, we are obliged to announce that from this version onward, we will no longer support macros or the so-called “automation system” . This measure was taken to facilitate better and smoother library development and usage. It is also important to note (for those game developers who have studied the complete version 1.0.7 guide) that we will no longer support Advanced Load, Fast Load & Simple Load. We have integrated all of these and similar functionalities into a clear Load method, which is now no longer confusing (as valuable feedback from some users indicated).
Join us in the latest update!
We’re moving fast! Head over to the library’s GitHub repository for access to everything: forks, projects, contributors, documentation, ongoing development, and most importantly, SLib library v1.1.0! It’s waiting for you in the repository!