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")
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!