-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Question: Is Lua supported in Godot? (#23)
Answer: Kind of — it’s possible, but it requires C++ and some extra maneuvering.
Since Godot runs everywhere, why not just use GDScript here?
🤖 GPT
Yes — it is possible to run GDScript at runtime to modify or extend a game, but it depends on how you structure your game and the capabilities of the Godot engine. Let me break it down clearly:
1. GDScript and Runtime Loading
Godot allows you to load and execute scripts dynamically at runtime. You can:
- Use
load()orpreload()to load scripts. - Use
GD.load()(Godot 4) to load.gdfiles dynamically. - Instantiate scripts and attach them to nodes during runtime.
Example:
var script = load("res://mods/my_mod.gd") # Load script at runtime
var node = Node.new()
node.set_script(script) # Attach the script to a node
add_child(node)This lets you add new functionality without rebuilding the game.
2. Modding Games with GDScript
Many games allow mods by exposing certain hooks or APIs:
- You can design your game to read scripts from a
mods/folder. - Mods can extend existing classes using
extends. - You can call functions from these scripts safely if you design a sandboxed API.
Example structure:
res://mods/
mod1.gd
mod2.gd
Runtime loader code:
for file in Directory.new().list_dir_begin("res://mods"):
if file.ends_with(".gd"):
var mod_script = load("res://mods/" + file)
var mod_node = Node.new()
mod_node.set_script(mod_script)
add_child(mod_node)3. Security Considerations
Running arbitrary GDScript from mods can be dangerous:
- Mods can access all parts of your game, potentially modifying the save system or game data.
- Consider sandboxing, such as providing only certain APIs for mod scripts.
- In Godot 4, you can use
GDScriptFunctionStateandGDScriptCallableto better control script execution.
4. Hot-Reloading
You can also reload scripts while the game is running for development or mod support:
var script = load("res://mods/my_mod.gd")
node.set_script(script) # Update the behavior dynamicallyThis allows live testing of mods or GDScript changes.
✅ Summary
- Yes, GDScript can run at runtime.
- Use
load()to dynamically attach scripts to nodes. - Design your game to support mods safely.
- Hot-reloading and sandboxing can enhance flexibility and safety.
If you want, I can write a full example modding system in Godot that lets players drop GDScript files into a folder and automatically load them at runtime. This is exactly how some moddable Godot games work.
Do you want me to do that?