Skip to content

Conversation

wjt
Copy link
Member

@wjt wjt commented Oct 23, 2024

This was mainly a direct reimplementation of each BlockCode program, with a few tweaks. I had to make the Ball group global so that it shows up in the “[something] is in group [group ▼]” dropdown. I also added an extra Reset method on the "Bump!" label to hide it when the game resets, calling it directly with "call [method] on [node]".

The code that plays one of 5 sounds at random when the ball hits a pin
previously relied on being able to pass an int as the "sound name" parameter,
which would for some reason I didn't bother digging into would previously cause
a str() conversion to be inserted, but now does not.

func _on_body_entered(body: Node2D): if body.is_in_group('Ball'): PinSound = randi_range(1, 5) var __sound_node_1 = get_node(str(PinSound)) # ...

So instead I use a chain of conditionals that compiles to:

func _on_body_entered(something: Node2D): if ((something).is_in_group('Ball')): PinSound = randi_range(1, 5) if PinSound == 1: var __sound_node_1 = get_node('1') # ... elif PinSound == 2: # ...

This is a bit wordier than what was there before but it works.

It would be nice to have a way to define a local variable rather than a
property of the node, but it's not the end of the world.

https://phabricator.endlessm.com/T35697

@wjt wjt force-pushed the T35697-update-pachinko-to-0.7 branch from 6573d36 to 6f073d0 Compare October 23, 2024 12:20
@cassidyjames
Copy link
Member

I'm also 100% okay dropping the complexity of having five random sounds. If it greatly simplifies it (while still showing the concept of using random numbers) by e.g. reducing the number of sounds to two, that would be totally reasonable. We could also/instead use a random number in the pitch instead to do something similar without trying to be clever with the multiple sound files.

@wjt
Copy link
Member Author

wjt commented Oct 23, 2024

FWIW, I think it's fine how I have it here. The added complexity was not too great and in some ways it's more obvious what it's doing.

@wjt wjt marked this pull request as draft October 24, 2024 09:07
@wjt
Copy link
Member Author

wjt commented Oct 24, 2024

However the comparison block does not accept the variable block as either of its parameters. I guess this is because they are floats and the variable is an int. But this should work: passing the result of the randi_range() block directly works.

I tried this again today and the bug doesn't exist so I'll revise this PR…

@wjt wjt force-pushed the T35697-update-pachinko-to-0.7 branch 2 times, most recently from bf068bd to 6516e08 Compare October 24, 2024 09:15
@wjt wjt marked this pull request as ready for review October 24, 2024 09:15
@wjt wjt force-pushed the T35697-update-pachinko-to-0.7 branch from 6516e08 to dbab50f Compare October 24, 2024 12:49
@starnight
Copy link
Contributor

LGTM basically. The only thing is the conflicted project.godot. Feel free to merge it after fix the conflict.

This was mainly a direct reimplementation of each BlockCode program, with a few tweaks. I had to make the Ball group global so that it shows up in the “[something] is in group [group ▼]” dropdown. I also added an extra Reset method on the "Bump!" label to hide it when the game resets, calling it directly with "call [method] on [node]". The code that plays one of 5 sounds at random when the ball hits a pin previously relied on being able to pass an int as the "sound name" parameter, which would for some reason I didn't bother digging into would previously cause a str() conversion to be inserted, but now does not. ```gdscript func _on_body_entered(body: Node2D):	if body.is_in_group('Ball'):	PinSound = randi_range(1, 5)	var __sound_node_1 = get_node(str(PinSound))	# ... ``` So instead I use a chain of conditionals that compiles to: ```gdscript func _on_body_entered(something: Node2D):	if ((something).is_in_group('Ball')):	PinSound = randi_range(1, 5)	if PinSound == 1:	var __sound_node_1 = get_node('1')	# ...	elif PinSound == 2:	# ... ``` This is a bit wordier than what was there before but it works. It would be nice to have a way to define a local variable rather than a property of the node, but it's not the end of the world. https://phabricator.endlessm.com/T35697 JJ: M game-04/main.tscn JJ: M game-04/pin.tscn JJ: M project.godot
@wjt wjt force-pushed the T35697-update-pachinko-to-0.7 branch from dbab50f to dfb07cb Compare October 25, 2024 07:37
@wjt wjt merged commit fd88775 into godotcon Oct 25, 2024
@wjt wjt deleted the T35697-update-pachinko-to-0.7 branch October 25, 2024 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants