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)
The function never gets executed, my source code http://pastebin.com/JPZSTA6a Line: 35-38 and 150
Thank you
The function is being called, but you are assigning to
enemies
andvelocity
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.You need to read about locals and globals in Python. As others point out you also have both
Score
andscore
here. Python is case-sensitive, those are different names.It's a scoping issue, the variables you're referring (enemies and velocity) to are created further down inside a while loop so they're not in scope in the function where you're trying to modify them. You need to read up on Execution model it should be able to clarify scoping rules.
You have
if score >= 100
when you probably meantif Score >= 100
. The function gets executed, it's just that the if statement always evaluates to false.Your code, paraphrased:
So, why isn't levels() being called? I suppose one of those many control flow items doesn't go the way you want. I can't say for example whether or not your enemies variable is empty but I can tell you that print is your friend.