background info:In a game I'm making I find myself using 2 functions: a home menu and a main-game while loop. To make things work at the moment I have the home menu call the main-game loop. Then when a round of play ends the while loop then calls the home menu function.

Now for the questions:Does this solution generate an endless series of function calls that just consume resources?Is there a better, more efficient way to leave the one function and go to the other?

While you probably won't have issues with this approach in a small program, it is certainly not the correct structure. It also sounds like a major memory leak (which takes work to accomplish in python).

A game (and many other types of program for that matter) should have a class that handles the main loop (singular). The different states (your menu and your play phase) of your program should be objects (class instances) within that control class (ideally held in a dictionary). The controlling class keeps track of which state currently has control and updates the current state during the main loop.

So I tried your suggestion Somelauw. and it certainly took care of the infinite looping. I had to make some changes due to an unexpected issue which of course caused another problem lol. So here's the slightly changed code:

So that is the important change along with the rest of the code.I made the change because leaving that call where it was didn't allow for a new enemy to generate, and putting it there I had hoped that with each new call of the game would set a new enemy. Instead I get an annoying "global 'enemy' not set" error when I use the "player_attack()" call.

The variable enemy is created in the function game and can only be used in that function, unless you pass it to another function or return it.A quick way to solve your problem, it to pass "enemy" as a parameter to the function player_attack.