Skip to content

Add 4 random number generation blocks #194

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

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions addons/block_code/blocks/math/randf_range.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://u35glf576fue"]

[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_03jps"]

[resource]
script = ExtResource("1_03jps")
name = &"randf_range"
description = "Generate a random floating point number between [i]from[/i] and [i]to[/i] inclusively"
category = "Math"
type = 3
variant_type = 3
display_template = "Random floating point number between {from: FLOAT} and {to: FLOAT}"
code_template = "randf_range({from}, {to})"
defaults = {
"from": -1.0,
"to": 1.0
}
signal_name = ""
scope = ""
19 changes: 19 additions & 0 deletions addons/block_code/blocks/math/randi_range.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://b3b1dyarh2hmo"]

[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_hk574"]

[resource]
script = ExtResource("1_hk574")
name = &"randi_range"
description = "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 a negative or positive number"
category = "Math"
type = 3
variant_type = 2
display_template = "Random integer number between {from: INT} and {to: INT}"
code_template = "randi_range({from}, {to})"
defaults = {
"from": 0,
"to": 100
}
signal_name = ""
scope = ""
2 changes: 1 addition & 1 deletion addons/block_code/ui/picker/categories/category_factory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static func get_general_blocks() -> Array[Block]:
block_list.append(b)

# Math
for block_name in [&"add", &"subtract", &"multiply", &"divide", &"pow"]:
for block_name in [&"add", &"subtract", &"multiply", &"divide", &"pow", &"randf_range", &"randi_range"]:
b = Util.instantiate_block(block_name)
block_list.append(b)

Expand Down