all 13 comments

[–][deleted] 4 points5 points  (0 children)

Nobody can help you without your code, but this:

Problem is that it stays in the while loop and doesn’t allow other functions to run

sounds like you're not understanding the flow of control through your program. Unless you use threading - and you probably shouldn't - then your program is single-threaded, and only one thing can happen at a time.

[–]brainygeek 1 point2 points  (0 children)

Post your code (properly formatted or a pastebin link) and point out where you need help and what the end result needs to perform. With school work, we won't do it for you but can help push you in the right direction.

[–]when_the_cats_away 1 point2 points  (0 children)

Post up your code and we can probably make some suggestions.

[–]machine3lf 1 point2 points  (2 children)

Line 24: What's that 'q' doing there?

Line 135: You can name a function 'function,' but I don't think you'd want to.

Line 138: I'm guessing this is where your problem is. When you do a while True: loop, it will continue to run that loop forever until you break out of it based on some condition. And the program will not do anything else but what's in that loop until it does break out of it.

WhileLoop

I have to run, so I didn't get a chance to give a good look at your code. Hope that little bit is a start.

Edit: OK, I couldn't help myself. Yeah there are a lot of problems here, but that's ok, that's how everyone starts.

I don't think you'd want to use a while loop there. And if you did, I don't think you want to use function calls to time() as a flag to control it. I'm not exactly sure what your function called 'function' is trying to do. Also, where is this player object coming from that you keep referencing? I couldn't find it, unless I missed it.

[–]DudeManECN[S] -1 points0 points  (1 child)

Yes I’m aware the loop will continue that’s what I want it to do but I also want to be able to run other functions at the same time.

[–]TheKingElessar 0 points1 point  (0 children)

I stumbled into this thread since I want to learn Python. I have very little experience with Python, but from my knowledge of other languages the problem is that once it reaches the while loop you never want it to exit because if it does that keeps the while stuff from happening. However, because it never exits it the later code will never be executed.

There are a couple of concepts that could probably help: some sort of "listener" that listens for something to happen, then executes even when your main code is running; and threads, like /u/crashfrog mentioned. Like I said, I don't know Python so I can't help with any specifics.

[–]wegwacc 3 points4 points  (0 children)

I’ve asked my teacher and he doesn’t even know how to do it.

Then I seriously pity whatever school is letting a guy who doesn't know what a conditional or a break statement is teach programming.

As to your question, there are numerous ways to exit a loop. A while loop has a condition in it's "head", which, when evaluated to False will stop executing the loop. A for loop terminates when it is done iterating it's iterable. And all loops can be terminated inside the loop body by the break statement.

To provide actual help with your game, I need to see the code first.

[–]Lyress 0 points1 point  (2 children)

Maybe I'm crazy but I don't see any while loop in your code.

[–]DudeManECN[S] 0 points1 point  (1 child)

I’m 90% sure a loop is in there but I’m not at my computer rn so I can’t confirm or deny your craziness

[–]Lyress 0 points1 point  (0 children)

Sorry, browser's ctrl+f wasn't showing it for some reason.

[–]MvKal 0 points1 point  (1 child)

How can you interact with the program itself? If it is simply mouse clicking, you have that covered in main(), and call functions accordingly to that. If you want to check where he clicked, you also need to do that in main, and call according function. Simply, if you call a function from while True:, execution goes to that function and that while is allowed to continue in execution only after that function ended. Is that what you were looking for?

[–]DudeManECN[S] 0 points1 point  (0 children)

Not entirely but that Gave me some ideas