Skip to content

Add 4 random number generation blocks#194

Merged
manuq merged 1 commit intoendlessm:mainfrom
jfcharron:random
Aug 15, 2024
Merged

Add 4 random number generation blocks#194
manuq merged 1 commit intoendlessm:mainfrom
jfcharron:random

Conversation

@jfcharron
Copy link
Copy Markdown
Contributor

Add 4 random number generation blocks.
One for each of these godot's functions:

  1. randi
  2. randi_range(from,to)
  3. randf
  4. randf_range(from,to)

Copy link
Copy Markdown
Contributor

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +441 to +442
b.statement = "(randi_range({from}, {to}))"
b.defaults = {"from": -1, "to": 1}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the 2 "random integer" blocks can be one, if the defaults are from: 0, to: 2^32-1. Then the code (statement) can be:

randi() if {from} == 0 and {to} == 2^32-1 else randi_range({from}, {to})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge the two blocks, because they are pretty similar. Also I will do the same for randi.

I feel the if statement is unnecessary because after some thought, I believe that the randi method is not useful in our case. I don't see a case where you would want such a high number of random values. So I will just the let the users enter the range they desire.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge the two blocks, because they are pretty similar. Also I will do the same for randi.

I feel the if statement is unnecessary because after some thought, I believe that the randi method is not useful in our case. I don't see a case where you would want such a high number of random values. So I will just the let the users enter the range they desire.

Yes, very well thought @jfcharron. Programming with blocks should be easy and providing multiple blocks that do the same can be confusing to the end users.

Comment on lines +421 to +422
b.statement = "(randf_range({from}, {to}))"
b.defaults = {"from": -1.0, "to": 1.0}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the 2 "random floating point" blocks can be one, if the defaults are from: 0.0, to: 1.0. Then the code (statement) can be:

randf() if {from} == 0.0 and {to} == 1.1 else randf_range({from}, {to})

@jfcharron
Copy link
Copy Markdown
Contributor Author

The Allow edits by maintainers checkbox is checked so I suppose you should be able to merge.

@manuq manuq merged commit 8c1abb4 into endlessm:main Aug 15, 2024
@manuq
Copy link
Copy Markdown
Contributor

manuq commented Aug 15, 2024

@jfcharron merged! I tested placing a sprite in a random vertical position and it worked like a charm:
Captura desde 2024-08-15 09-07-18

I have converted the blocks to the new definition format, which uses resources. In case you want to contribute new blocks, this is now the way to do it. It is nicer because the definitions can be edited in the editor directly:
Captura desde 2024-08-15 09-25-07

Thanks!

@manuq manuq mentioned this pull request Aug 15, 2024
@jfcharron jfcharron deleted the random branch August 19, 2024 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants