Work with Oneof fields in GDScript
masterA oneof group allows only one field to be set at a time. Setting a new field in the group automatically clears the others.
For each oneof group, Godobuf generates:
set_<field_name>(value)andget_<field_name>()for each member.has_<field_name>(): Returnstrueif that specific field is set.get_<oneof_name>_case(): Returns the tag number of the currently set field, or0if none are set.<OneOfName>Caseenum: Used formatchstatements. It contains<ONEOF_NAME>_NOT_SET = 0and<FIELD_NAME> = <tag_number>for each field.
var a = MyProto.A.new()
a.set_f1("my string")
# Check if a field is set
if a.has_f1():
print("F1 is set")
# Use match with the generated Case enum
match a.get_my_oneof_case():
a.MyOneofCase.F_1:
print("Text is set: ", a.get_f1())
a.MyOneofCase.F_2:
print("Number is set: ", a.get_f2())
a.MyOneofCase.MY_ONEOF_NOT_SET:
print("No payload field set")