第 7 步:我们现在可以在舞台上看到我们的播放器,但是我们需要从add_player()返回精灵,以便在我们的main()函数中使用精灵。

return 语句将变量从函数传递回调用函数的位置。

  • 单击逻辑。去并将Return Statement拖到add_player()的最后一行。
  • 将从my_var返回的变量更改为player 。确保这个 return 语句是缩进的!

To navigate the page using the TAB key, first press ESC to exit the code editor.

def set_stage(): """ Sets up the stage for the game """ stage.set_background("soccerfield") stage.disable_floor() def add_player(): """ Adds a player to the stage for the user to control """ player = codesters.Sprite("player1") player.go_to(0, -155) def main(): """ Sets up the program and calls other functions """ set_stage() player = add_player() main()
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)