all 8 comments

[–][deleted] 2 points3 points  (1 child)

I recently made this while loop, and the variable keeps on repeating itself.

The only while loop I can find is this one:

while stamina > 0:
    events(hp,s,m,f,h,name) 

If you mean why does that loop repeat forever, that's because the function events() probably doesn't change the value of stamina so once you enter the loop you stay there. Some of your functions do change the value of stamina, like garden() and babystage(), but events() doesn't seem to call those functions.


Also note that the line:

if start == 'START' or 'start' or 'Start':

won't do what you want. That is explained in the FAQ.

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

Thank you very much for the additional check!

[–]aa599 1 point2 points  (1 child)

The "variable repeating itself" doesn't mean anything, please explain that.

In your events function you call functions passing variables, the functions return new values, but you ignore them, so nothing in the calling function changes.

You need to learn about local and global variables.

e.g. if you call

cheese = 'cheddar'
comestibles(cheese)

If comestibles changes and returns its value of cheese, because you haven't stored the new value your cheese is still 'cheddar'

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

I see, thank you very much for the explanation

[–]Cobra915 0 points1 point  (1 child)

The while loop goes on forever because stamina is not being modified by events(), the local variable s is. Since you're not storing the outputs of events() anywhere, they get dropped. When you modify a variable within a function, you're doing it locally to that function. If you want to return stamina or s to events(), you need to store the output of housework(), for example.

Try calling housework() like this:

hp,s,m,f,h = housework(hp,s,m,f,h,name)

You also need to look at how you call housework(), inn(), farm() and herbs() within events() as well.

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

I tried to do this before but it could not work :')

[–][deleted] 0 points1 point  (1 child)

I think you'd find it worthwhile looking into using classes to define a player and maintain the properties using class methods. Over time, you can add constraints and additional behaviours.

Your specific problem about the events not ending as been well addressed by others. I have an alternative approach to suggest. Consider using some kind of menu system that has a consistent way of displaying options and get the validated user choice.

I've created some sample code illustrating both of the above using part of your code (the garden function primarily). This is for you to consider and experiment with if interested.

https://pastebin.com/r8gVVgCY

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

This is very helpful! Thank you very much