Skip to content

Commit 46c6dee

Browse files
committed
Add blocks to access properties of objects
A property is always returned as a variant, which must be cast to a concrete type by using a type casting block.
1 parent 56c44f5 commit 46c6dee

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

addons/block_code/ui/picker/categories/category_factory.gd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ static func get_general_categories() -> Array[BlockCategory]:
173173
b.statement = "str({int})"
174174
variable_list.append(b)
175175

176+
b = BLOCKS["parameter_block"].instantiate()
177+
b.block_type = Types.BlockType.INT
178+
b.block_format = "Get Int {var: INT} from {object: NODE}"
179+
b.statement = "{object}.VAR_DICT[{var}]"
180+
variable_list.append(b)
181+
176182
var variable_category: BlockCategory = BlockCategory.new("Variables", variable_list, Color("4f975d"))
177183

178184
# Objects & Types
@@ -214,6 +220,17 @@ static func get_general_categories() -> Array[BlockCategory]:
214220
b.statement = "bool({value})"
215221
type_list.append(b)
216222

223+
b = BLOCKS["parameter_block"].instantiate()
224+
b.block_type = Types.BlockType.VARIANT
225+
b.block_format = "Get property {key: STRING} from {object: NODE}"
226+
b.statement = "{object}.get({key})"
227+
type_list.append(b)
228+
229+
b = BLOCKS["statement_block"].instantiate()
230+
b.block_format = "Set property {key: STRING} in {object: NODE} to {value: VARIANT}"
231+
b.statement = "{object}.set({key}, {value})"
232+
type_list.append(b)
233+
217234
var type_category: BlockCategory = BlockCategory.new("Objects & Types", type_list, Color("c12f8e"))
218235

219236
# Math

0 commit comments

Comments
 (0)