jmoenig / Snap

a visual programming language inspired by Scratch
http://snap.berkeley.edu
GNU Affero General Public License v3.0
1.49k stars 743 forks source link

custom repeat until runs forever. #1730

Closed DarinM1967 closed 7 years ago

DarinM1967 commented 7 years ago

Hardware: Raspberry Pi 3 OS: Raspbian 1.2 (Feb 2017 update) Chromium Browser: Version 56.0.2924.84 Built on Ubuntu 14.04, running on Raspbian 8.0

I created the following custom block:

repeat_until

then tested it like this:

repeat_until_test

And it runs forever! Any ideas why? Thank you in advance! Take care now.

Darin Murphy

jguille2 commented 7 years ago

Hi @DarinM1967 ,

Which is general regiser 1 initial value?

Of course, if it is greater than 10, it runs forever. But also, if it is not an integer.

Maybe you have to change it to: until general register 1 > 9

Joan

towerofnix commented 7 years ago

Yep. Think of it this way – you're passing the result of "<(general register 1) = [10]>" into "begin..until". That value is false, since "general register 1" is not equal to 10. So, inside of "begin..until", the value of the "test" variable is always false, since that's what you gave it!

Instead, you'll need to use an unevaluated input:

Input type screenshot

For an example of what it does, what do you think the result of this is?

"my block" definition

"my block" usage

Here's what it shows:

The result

See, "my block" got the block "1 + 5 = 7 - 2". You're then able to evaluate this block using the "call" control block. Here's an example:

"make a sound until" definition

"make a sound until" usage

From here I think you can figure out how to use an unevaulated input with your custom block to make it work!

DarinM1967 commented 7 years ago

Thank you Liam, using unevaluated and call fixed it! Now I have a functioning forth-like begin-until! Thank you also Joan for your help too! Take care now,

Darin Murphy

On Apr 18, 2017 7:18 AM, "Liam" notifications@github.com wrote:

Yep. Think of it this way – you're passing the result of "<(general register 1) = [10]>" into "begin..until". That value is false, since "general register 1" is not equal to 10. So, inside of "begin..until", the value of the "test" variable is always false, since that's what you gave it!

Instead, you'll need to use an unevaluated input:

[image: Input type screenshot] https://cloud.githubusercontent.com/assets/9948030/25128008/859865f2-240e-11e7-833f-acb067764107.png

For an example of what it does, what do you think the result of this is?

[image: "my block" definition] https://cloud.githubusercontent.com/assets/9948030/25128076/c6342b3c-240e-11e7-8800-dacb51fe507b.png

[image: "my block" usage] https://cloud.githubusercontent.com/assets/9948030/25128101/d511a198-240e-11e7-8ff8-98a0d554509b.png

Here's what it shows:

[image: The result] https://cloud.githubusercontent.com/assets/9948030/25128129/e9aa7fda-240e-11e7-93c9-71b1d952a376.png

See, "my block" got the block "1 + 5 = 7 - 2". You're then able to evaluate this block using the "call" control block. Here's an example:

[image: "make a sound until" definition] https://cloud.githubusercontent.com/assets/9948030/25128219/509cd3f0-240f-11e7-910b-e5f75f0245f4.png

[image: "make a sound until" usage] https://cloud.githubusercontent.com/assets/9948030/25128228/599202b4-240f-11e7-8eb4-5d6f3c463a8d.png

From here I think you can figure out how to use an unevaulated input with your custom block to make it work!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/issues/1730#issuecomment-294790346, or mute the thread https://github.com/notifications/unsubscribe-auth/AFwZikNbq9Kj0polk-Vkf5Lze5ywihzqks5rxJvygaJpZM4M_wtG .

DarinM1967 commented 7 years ago

Thanks Joan. Register_1 is always set to 0 prior to running the code. Liam was able to help me fix the issue. Take care now,

Darin Murphy

On Apr 18, 2017 12:40 AM, "Joan Guillén i Pelegay" notifications@github.com wrote:

Hi @DarinM1967 https://github.com/DarinM1967 ,

Which is general regiser 1 initial value?

Of course, if it is greater than 10, it runs forever. But also, if it is not an integer.

Maybe you have to change it to: until general register 1 > 9

Joan

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/issues/1730#issuecomment-294675638, or mute the thread https://github.com/notifications/unsubscribe-auth/AFwZin9Zo_sR5iSqJM_NuDisspeyWqEtks5rxD6qgaJpZM4M_wtG .