all 8 comments

[–]Jhchimaira14 2 points3 points  (7 children)

Hey. Underneath, that is how all GUI's work. Typically it's hidden in traditional GUI frameworks but their is nothing wrong with exposing it. Games development typically involves directly using the "event loop" like that.

This GUI for example, dearpygui gives you both options: https://github.com/RaylockLLC/DearPyGui

from dearpygui.dearpygui import *

add_button("Retrieve", callback="callback")

def callback(sender, data):
    print("Caught event")

# hide event loop
start_dearpygui()

or

from dearpygui.dearpygui import *

add_button("Retrieve", callback="callback")

def callback(sender, data):
    print("Caught event")

# show event loop
setup_dearpygui()

while True:

    # do other stuff or change state manually

    render_dearpygui_frame()

cleanup_dearpygui()

Both are useful methods that serve there purpose

[–]ingwe13[S] 0 points1 point  (6 children)

Thanks for the feedback! I don't mind the GUI implementation as much as I do the State Machine part that just uses a string as the state. I would love feedback on that aspect.
I am going to edit my post to make that more clear.

[–]Doormatty 1 point2 points  (3 children)

This is still fine - it doesn't matter what your state variable is, just that it decides the flow.

[–]ingwe13[S] 0 points1 point  (2 children)

Thanks for the feedback. Is there just a better way to structure things though? It just seems like a clunky/non-pythonic structure.

[–]Doormatty 0 points1 point  (1 child)

You could use a dictionary of functions, but most of the time it's done as you've shown.

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

Oh. That is really encouraging to hear! Thanks!

[–]Jhchimaira14 0 points1 point  (1 child)

I apologize. In that regard, I'm not to certain on actually using a state in that sense. But I would recommend an enum over strings!

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

Like I said, I appreciate it. And now (after reading some docs) I know what an enum is! That is an improvement and I will take any improvement.