Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Quick Tips

A topic by lavaduder created Aug 30, 2021 Views: 447 Replies: 7
Viewing posts 1 to 5
(+6)

Hey so I've been using godot since 2.2; (or 2.6 I forget?) I can give you some really neat speed tips for the engine.
'export' key word for 'var' can help a lot if your re-using code. It allows for modulation between scripts.

export var i = 0 #This variable can be changed in the editor
export(String) var s = "Four" #This variable can only be a string, it's never a float, bool, or int.
export(int) var num = 4 # Like String before it, this can only be an integer
export(bool) var torf = false
export(float) var f = 0.5
export(Vector2) var vec2 #Yep every known variable can be used in the export.
#Now for some unorthodox methods
export(String,FILE,"*.json") var dialog = "" #This allows you to open files, And the .json bit is a filter, you can have unlimited filters.
export(NodePath) var nodey #You can grab another node.
enum COOLTOOLBARS {ASK,ASKJEEVES,ASKPROFESSIONAL,ASKNORTON}
export(COOLTOOLBARS) var toolbar #Yep you can even use enums for the export key word, pretty neat huh?  
HostSubmitted

This is cool!

Deleted 2 years ago
Submitted

Adding a few more quick tips:

  • Download the export templates early and test your exports early. Especially the download can take some time as it contains the binaries for all target platforms. So don't wait with this part until the jam ends. You can download them in the menu "Editor" > "Manage Export Templates"
  • Look into signals. They are great for inter-node communication.
  • Use built-in constants for clearer naming. For example the 3D vector class has some helpers like Vector3.LEFT

Dude signals are practically a requirement for collision. Just highlighting them is not giving them justice.

signal fire_ready
func _ready():
    NODEA.connect("fire_ready",self,"print",["Come in."])
    emit_signal("fire_ready")
#Honestly I could have used the built in signal "ready", but this was to show how to create them as well.
(2 edits) (+1)

Previous export tip supercharged: here's export for referencing a node in the node tree:

export(NodePath) onready var player = get_node(player) as KinematicBody2D
  • Create a variable and assign it
  • Follows static typing - you get nice class-specific hints in the script editor instead of useless garbage
  • No need to remember how your node tree is laid out
  • You can rename or move that node elsewhere on the tree and it'll still be connected
  • All of that in one single line

The only downside to this is that it doesn't play nice if your script is a tool script. Other than that, it's super useful if you're a diehard OOP follower or rely on singular nodes to do your bidding instead of making one giant script for readability.

And here's a load and preload alternative with the use of export:

export(PackedScene) var bullet_entity

No need to refactor your code if that file moves! If you use Godot's file system to move files, other scenes should update automatically with the new file path.

Hmm I did not know about PackedScenes being compatible, Thank you.

(1 edit)

From what little knowledge I have of Godot here's a few things that are nice to know:
- Signals are very handy
- Singletons are tucked away in the project settings, under 'Autoload' (along with input, windows size etc.)
- Documentation is pretty good

Some nice resources:
- Godot Shaders will likely save you some time
- Godot Asset Library is evergrowing,
- Collection of Open Source Games made in godot, some are made in older versions. I know it helped me a fair bit to see how people structure their projects.

Life is keeping real busy right now so I likely won't be joining. Have fun with jamming everyone.

Signals are a requirement. Even in games where you don't think you need them. Anything that deals with buttons, collision, multiplayer, ETC. Needs to have some form of a signal. I dare anyone in this jam to make a game without them.