Skip to content

Add randi, randf, randf_range and randi_range blocks #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions addons/block_code/ui/picker/categories/category_factory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,46 @@ static func get_general_blocks() -> Array[Block]:
b.category = "Math"
block_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_name = "randf"
b.variant_type = TYPE_FLOAT
b.block_format = "Random number between 0.0 and 1.0"
b.statement = "randf()"
b.defaults = {}
b.category = "Math"
b.tooltip_text = "Generate a random floating point number between 0.0 and 1.0 inclusively ([0.0, 1.0])"
block_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_name = "randf_range"
b.variant_type = TYPE_FLOAT
b.block_format = "Random number between {from: FLOAT} and {to: FLOAT}"
b.statement = "(randf_range({from}, {to}))"
b.defaults = {"from": -1.0, "to": 1.0}
b.category = "Math"
b.tooltip_text = "Generate a random floating point number between [i]from[/i] and [i]to[/i] inclusively"
block_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_name = "randi"
b.variant_type = TYPE_INT
b.block_format = "Random number between 0 and 4294967295"
b.statement = "randi()"
b.defaults = {}
b.category = "Math"
b.tooltip_text = "Generate a random unsigned 32-bits integer number between 0 and 2^32-1 inclusively ([0, 2^32-1])"
block_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_name = "randi_range"
b.variant_type = TYPE_INT
b.block_format = "Random number between {from: INT} and {to: INT}"
b.statement = "(randi_range({from}, {to}))"
b.defaults = {"from": -1, "to": 1}
b.category = "Math"
b.tooltip_text = "Generate a random signed 32-bits integer number between [i]from[/i] and [i]to[/i] inclusively. [i]from[/i] and [i]to[/i] can be negative or positive number"
block_list.append(b)

#endregion
#region Logic

Expand Down