Skip to content
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

[BUG] combining ask with at random does not work (level 3) #1938

Closed
juliabolt opened this issue Feb 10, 2022 · 7 comments · Fixed by #5362
Closed

[BUG] combining ask with at random does not work (level 3) #1938

juliabolt opened this issue Feb 10, 2022 · 7 comments · Fixed by #5362
Assignees
Labels
bug Something isn't working language Issues related to the Hedy language

Comments

@juliabolt
Copy link
Collaborator

Describe the bug
When using at random in combination with ask, the name of the list and at random is printed without being replaced by one of the elements of the list.

Paste the Hedy code & level

questions is color, food, song, movie
answer is ask What is your favourite questions at random ?
print answer? me too!

In level 3

Expected behavior
The question asked becomes: What is your favourite color? (Or one of the other options in the list. )

@ThomasKluiters
Copy link
Contributor

Hmm, I think this is gonna be a bit tough! A simpler program such as:

questions is color, food, song, movie
topic is questions at random
answer is ask What is your favourite topic ?
print answer? me too!

Is currently also not supported, as the text after ask is treated as plain text

@juliabolt
Copy link
Collaborator Author

Now that you mentioned this, I see that any variable does not work with ask! For example:

x is how are you?
y is ask x

This should work from level 2 on, but doesn't.

Is it too difficult to treat the text behind ask the same way as text behind print?

@juliabolt
Copy link
Collaborator Author

From level 4 on, we need to use quotation marks for strings we want to print with ask and print. So these example programs work from level 4 on, maybe it is okay that it does not work in level 3 yet. @Felienne What do you think?

In level 4, the first example would become:

questions is color, food, song, movie
answer is ask 'What is your favourite ' questions at random'?'
print answer'? me too!'

This works fine, so the problem that we cannot use variables (let alone use at random) in combination with ask is only in level 3. It just seemed a little weird it could be used with other commands but not with ask, that's why I made this issue, but since it is solved in level 4, maybe we can leave it like this.

@Felienne
Copy link
Member

Felienne commented Feb 15, 2022

Thanks for diving into this you both!!

I think in general ask and print are sort of similar things so I think kids might assume that they work the same. So if it works for print it should work for ask too?

On the other hand, the ask syntax is more complex with the variable, so maybe we should not allow it to grow even more complex before it is really needed? I am torn but I lean towards consistency between print and ask. That will probably simplify the grammar/code too.

@huangjac1
Copy link

Hi, new to open source and looking to contribute! I've been able to build and run Hedy. I'm working with a partner from my class to do an assignment that pertains to contributing to open-source. Any chance this issue is still unassigned and we can work on it?

@Felienne
Copy link
Member

Yes it is still open! As you can read there was some discussion on the best path here, but I think that it would be nice to have consistency between ask and print, meaning

questions is color, food, song, movie
answer is ask What is your favourite questions at random ?
print answer? me too!

should indeed work.

Let us know if you need any help! Since this is an issue pertaining to the Hedy language it can be a bit complex (many connected parts) but we are here to help.

@Felienne Felienne added the bug Something isn't working label Dec 2, 2022
@Felienne Felienne added the language Issues related to the Hedy language label Sep 23, 2023
@boryanagoncharenko
Copy link
Collaborator

I am afraid the ask and print commands are already very different and making them symmetrical would require a big change in the content of the levels. Please note that the differences between the commands start already at level 2 which is illustrated in the snippet below:

name is ask What is your name?
print Hello name

The print command accepts variables, while ask does not. I can easily make ask accept variables and list access but then we need to teach kids that they cannot use the variable name in the ask question (name of the right-hand-side of the ask becomes a variable now). It is very common to use a name for the variable of an ask statement which appears as a literal word inside the ask question. We could do some magic to solve specific case, but I am afraid the complexity will outweigh the benefits.

We could ignore the difference in level 2 and just add list access in level 3. But wouldn't that be confusing? ask will not support variables but will support list access. @Felienne how would you like me to proceed?

@Felienne Felienne moved this to ToBeDiscussed in Hedy organization board Mar 21, 2024
@mergify mergify bot closed this as completed in #5362 Apr 16, 2024
mergify bot pushed a commit that referenced this issue Apr 16, 2024
…5362)

Fixes #1938
The `ask` command now accepts the same input as the `print` command. In levels 2-3 it supports variables and list access. If the variable is defined after the command or the list is just used by name (without `at random` or `at` index), the argument is interpreted as a literal string.

**How to test**
Automated tests are added to cover all changes. However, to get a sense of how the change looks in Hedy, execute the following snippets in the respective level.
Level 2
```
name is Hedy
answer is ask are you name?
# the ask command should yield `are you Hedy?`
```
```
answer is ask are you name?
name is Hedy
# the ask command should yield `are you name?` because the variable name is defined afterwards
```
```
name is what is your name?
# the name on the rhs should be a literal string and not a reference to the variable
```

Level 3
```
animals is cat, dog, hamster
answer is ask Do you have a animals at random?
print Do you have a animals at random
# both commands should interpret animals at random
```
```
animals is cat, dog, hamster
answer is ask Do you like animals?
print Do you like animals?
# both commands should not interpret animals, so it should be 'Do you like animals?'
```
```
animals is cat, dog, hamster
answer is ask Do you like animals at rand?
print Do you like animals at rand?
# both commands should not interpret animals, so it should be 'Do you like animals at rand?'
```
```
c is red, green, blue
color c
# should yield a runtime error that the supplied value is not a color
```
```
red is 1, 2, 3
color red
# should not yield an error and should correctly show a red turtle
```
@Felienne Felienne moved this from ToBeDiscussed to Done in Hedy organization board Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working language Issues related to the Hedy language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants