Skip to content

Commit 598c092

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 237c709 commit 598c092

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
@@ -164,6 +164,12 @@ static func get_general_categories() -> Array[BlockCategory]:
164164
b.statement = "str({int})"
165165
variable_list.append(b)
166166

167+
b = BLOCKS["parameter_block"].instantiate()
168+
b.block_type = Types.BlockType.INT
169+
b.block_format = "Get Int {var: INT} from {object: NODE}"
170+
b.statement = "{object}.VAR_DICT[{var}]"
171+
variable_list.append(b)
172+
167173
var variable_category: BlockCategory = BlockCategory.new("Variables", variable_list, Color("4f975d"))
168174

169175
# Objects & Types
@@ -205,6 +211,17 @@ static func get_general_categories() -> Array[BlockCategory]:
205211
b.statement = "bool({value})"
206212
type_list.append(b)
207213

214+
b = BLOCKS["parameter_block"].instantiate()
215+
b.block_type = Types.BlockType.VARIANT
216+
b.block_format = "Get property {key: STRING} from {object: NODE}"
217+
b.statement = "{object}.get({key})"
218+
type_list.append(b)
219+
220+
b = BLOCKS["statement_block"].instantiate()
221+
b.block_format = "Set property {key: STRING} in {object: NODE} to {value: VARIANT}"
222+
b.statement = "{object}.set({key}, {value})"
223+
type_list.append(b)
224+
208225
var type_category: BlockCategory = BlockCategory.new("Objects & Types", type_list, Color("c12f8e"))
209226

210227
# Math

0 commit comments

Comments
 (0)