Skip to content

Commit 8c1abb4

Browse files
authored
Merge pull request #194 from jfcharron/random
Add 4 random number generation blocks
2 parents b482f38 + 937bf21 commit 8c1abb4

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://u35glf576fue"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_03jps"]
4+
5+
[resource]
6+
script = ExtResource("1_03jps")
7+
name = &"randf_range"
8+
description = "Generate a random floating point number between [i]from[/i] and [i]to[/i] inclusively"
9+
category = "Math"
10+
type = 3
11+
variant_type = 3
12+
display_template = "Random floating point number between {from: FLOAT} and {to: FLOAT}"
13+
code_template = "randf_range({from}, {to})"
14+
defaults = {
15+
"from": -1.0,
16+
"to": 1.0
17+
}
18+
signal_name = ""
19+
scope = ""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://b3b1dyarh2hmo"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_hk574"]
4+
5+
[resource]
6+
script = ExtResource("1_hk574")
7+
name = &"randi_range"
8+
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"
9+
category = "Math"
10+
type = 3
11+
variant_type = 2
12+
display_template = "Random integer number between {from: INT} and {to: INT}"
13+
code_template = "randi_range({from}, {to})"
14+
defaults = {
15+
"from": 0,
16+
"to": 100
17+
}
18+
signal_name = ""
19+
scope = ""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static func get_general_blocks() -> Array[Block]:
198198
block_list.append(b)
199199

200200
# Math
201-
for block_name in [&"add", &"subtract", &"multiply", &"divide", &"pow"]:
201+
for block_name in [&"add", &"subtract", &"multiply", &"divide", &"pow", &"randf_range", &"randi_range"]:
202202
b = Util.instantiate_block(block_name)
203203
block_list.append(b)
204204

0 commit comments

Comments
 (0)