6
submitted 11 hours ago* (last edited 11 hours ago) by MousePotatoDoesStuff@piefed.social to c/godot@programming.dev

Option 1:

func set_default_value(section:String,key:String,value:Variant)->Variant:  
	if !self.has_section_key(section,key):  
		self.set_value(section,key,value)  
	return self.get_value(section,key)  

Option 2:

func set_default_value(section:String,key:String,value:Variant)->Variant:  
	value=self.get_value(section,key,value)  
	self.set_value(section,key,value)  
	return value  
you are viewing a single comment's thread
view the rest of the comments
[-] one_old_coder@piefed.social 3 points 9 hours ago

Not specific to Godot but I prefer the second one. The if breaks the flow of reading IMHO. You could add a comment to explain the whole thing though.

No judgement but why is it not called set_value instead of set_default_value? And why is it returning a value? I'm a noob at Godot.

Thanks for the feedback!

It's based on Python's set_default dictionary method - it sets a value and The base class already has a set_value.

this post was submitted on 27 Oct 2026
6 points (100.0% liked)

Godot

7998 readers
44 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 3 years ago
MODERATORS