“Godot Setget” Kode Jawaban

Godot Setget

#Both setter and getter:
var my_var setget my_var_set, my_var_get

func my_var_set(new_value):
    my_var = new_value

func my_var_get():
    return my_var # Getter must return a value.
    
    
#Only a setter
var my_var = 5 setget myvar_set


#Only a getter
var my_var = 5 setget ,myvar_get

Docs:
https://docs.godotengine.org/en/3.0/getting_started/scripting/gdscript/gdscript_basics.html?highlight=setget#setters-getters
Crazy Caracal

Setget Godot

var my_var setget my_var_set, my_var_get

func my_var_set(new_value):
    my_var = new_value

func my_var_get():
    return my_var # Getter must return a value.

#Only a setter
var my_var = 5 setget myvar_set

#Only a getter
var my_var = 5 setget ,myvar_get
Crazy Caracal

Jawaban yang mirip dengan “Godot Setget”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya