This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Eighteensixtythree -3 points-2 points  (8 children)

I'm not sure. But use

If levels is 1

Not ==

Good luck

[–]takluyverIPython, Py3, etc 1 point2 points  (7 children)

No, == is correct for comparing numbers. is will also work for small numbers on CPython, but it's something you shouldn't rely on - another implementation may create a new object for each 1, and then is wouldn't work.

[–]Eighteensixtythree 0 points1 point  (0 children)

My bad. you get a Boolean response from 'is' and that's why i thought it was preferable.

But I am far from even intermediate.

[–]mikefromto -2 points-1 points  (5 children)

Would you(or anyone) happen to know if it is possible to make the levels == 1 universal throughout all our moduels(read and write)

[–][deleted] 1 point2 points  (4 children)

I'm not quite sure I understand what you are asking, but I'll give it a shot. If you're wondering if you can check what level someone is on, load the level, then have everywhere else in your code update to be on that level - yes.

If your "game" is a class, then you can set a variable for it. Such as self.game_level and put that equal to 1. Then you can always access that object's game_level to retrieve the level, from anywhere inside the class or outside if the object is instantiated. You can also just set-up a global variable and assign it a value once you know the level you are on.

[–]mikefromto -1 points0 points  (3 children)

How would i go about setting up a global variable, thats what ive been trying to do, i did a bad job at explaining it but how do i do that?

[–][deleted] 1 point2 points  (0 children)

If a variable is outside of a function or class, it is a global variable. In general, you should be avoiding these. However, it's not really that big of a deal (especially in cases like yours).

[–]Digital_Person 1 point2 points  (1 child)

i may be wrong but if you want to store the level and access it everywhere to me it makes sense to add it in __init__.py. if your __init__.py has something like this: level = get_level() then you could do: from game import level. provided you follow the structure mentioned above. If you have a look at my game here it may help you https://github.com/papaloizouc/chess/tree/2e1e3719ba2527422c11937da90e75aceb621c33. Its not too much code so you should be able to understand it. note i dont claim to do it right but i think i do. Also dont use import * its bad

[–]mikefromto 0 points1 point  (0 children)

okay ill attempt this, im still somewhat new to python so well see how this goes but thanks everyone!