函数没有被调用 [英] Function Not getting called

查看:82
本文介绍了函数没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有检查分数的功能,如果分数达到给定的分数,我会(我还没有完成)提高等级,我的功能:

I have function which checks the score and will(I haven't finished) increases level if the score hits the given score, my function:

def levels(Score):
 if score >= 100:
   enemies = 6
   velocity = 2

我在游戏循环中调用它:

and I'm calling it in the game loop:

levels(score)

函数永远不会被执行,我的源代码 http://pastebin.com/JPZSTA6a线路:35-38和150

The function never gets executed, my source code http://pastebin.com/JPZSTA6a Line: 35-38 and 150

谢谢

推荐答案

函数正在被调用,但是你在函数中分配了enemiesvelocity,所以它们是函数的局部变量,然后在函数返回时被丢弃.所以你的函数被调用了,但没有持久的效果.

The function is being called, but you are assigning to enemies and velocity in the function, so they are local to the function, and are then discarded when the function returns. So your function is called, but has no lasting effect.

您需要阅读 Python 中的局部变量和全局变量.正如其他人指出的那样,您在这里也有 Scorescore .Python 区分大小写,它们是不同的名称.

You need to read about locals and globals in Python. As others point out you also have both Score and score here. Python is case-sensitive, those are different names.

这篇关于函数没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆