This site requires JavaScript, please enable it in your browser!
Greenfoot back
sthompson
sthompson wrote ...

2025/1/6

Greenfoot.ask() window doesn't close on web

sthompson sthompson

2025/1/6

#
I'm uploading a project to greenfoot.org that uses Greenfoot.ask() to get an input from the player. It works fine in the greenfoot application, but now that I've uploaded it, the window prompting the player never closes. Is there any workaround for this? You can see it in action here (use the arrow keys to walk to the tree monster, and then follow the prompts): https://www.greenfoot.org/scenarios/34529
danpost danpost

2025/1/7

#
sthompson wrote...
I'm uploading a project to greenfoot.org that uses Greenfoot.ask() to get an input from the player. It works fine in the greenfoot application, but now that I've uploaded it, the window prompting the player never closes. Is there any workaround for this? You can see it in action here (use the arrow keys to walk to the tree monster, and then follow the prompts): https://www.greenfoot.org/scenarios/34529
Looks to me like it is working fine. I think your code is making it repeatedly perform the "ask" action. For assistance, either show your codes here or re-upload the scenario having the "Publish source" box checked this time.
sthompson sthompson

17 hours ago

#
Hmm, the code only performs "ask" once as far as I can tell. I reuploaded the code with "publish source" checked: https://www.greenfoot.org/scenarios/34529 Here's a video of it in the browser vs. locally so you can see the difference: https://youtu.be/E62BC6Rj6ps
danpost danpost

9 hours ago

#
sthompson wrote...
Hmm, the code only performs "ask" once as far as I can tell. I reuploaded the code with "publish source" checked: << Links Omitted >>
I noticed two things in your Textbox class. The first is in the act method where you check for input. The check however does not limit the input to a specific response. The programming there is considered "loose", where any correct input at the wrong time would trigger the wrong action to proceed with. The other thing was how you are comparing strings. Always make sure that the "noun" of the expression is not null. That is:
// instead of (for example)
if (answer.equals("30"))

// use
if ("30".equals(answer))
Absolutely no problems with the literal as the "noun" of the expression. If both have the possibility of being null, you would have to check one for null and then use it to compare (after finding out it is NOT null).
You need to login to post a reply.