You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scratch选择题测验按钮交互功能实现求助

Hey Gabe, let's fix that button functionality for your Scratch quiz—super common spot to get stuck, but it's straightforward once you know the right blocks to use! Here's a step-by-step breakdown tailored to your setup:

1. Add the Click Trigger to Each Button

Every button in your quiz is a separate Sprite in Scratch, so you need to attach a click event to each one individually:

  • Select the button Sprite you want to set up
  • Go to the Events category of blocks
  • Drag the 当这个角色被点击 block onto the Sprite's code area—this tells Scratch to run the following code whenever the user clicks that button.
2. Add Answer Validation Logic

Next, you'll add code inside the trigger to handle correct/incorrect answers. Here are two common setups:

For a Correct Answer Button

当这个角色被点击
将[分数 v]增加1  // Optional: if you're tracking scores
说"答对啦!"2秒
切换造型到[按钮按下 v]  // Optional: visual feedback for click
等待0.2秒
切换造型到[按钮正常 v]
广播[下一题 v]  // Optional: if you want to move to the next question automatically

For an Incorrect Answer Button

当这个角色被点击
说"不对哦,再想想!"2秒
切换造型到[按钮按下 v]  // Optional: visual feedback for click
等待0.2秒
切换造型到[按钮正常 v]
3. Optional: Set Up a Score Variable

If you want to track how many answers the user gets right:

  • Go to the Variables category and click "Make a Variable"
  • Name it 分数 (or "Score") and set it to "For all sprites"
  • Add the 将[分数 v]增加1 block to your correct answer code, and drag the variable onto the stage to display it for the user.
4. Troubleshooting Quick Checks
  • Make sure you haven't accidentally attached multiple button codes to the same Sprite—each button needs its own independent code
  • If your buttons aren't responding, double-check that the Sprite's "Visible" checkbox is ticked in the Sprite panel
  • For better user experience, add a pressed-state sprite (slightly darker or shifted) so users can see they actually clicked the button

内容的提问来源于stack exchange,提问作者Gabe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:05:03