#๐ optimizing pygame code
19 messages ยท Page 1 of 1 (latest)
@cobalt scarab
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Im trying to optimize my menu function since it has to calculate the UI each time its called. im making the recalculate function so it can just store and use the post-calculated variables. i want to call recalculate each time i click a button. i also want to move my hover button logic to my menu function
and im not sure how to without using global variables or something
this is what it looks like for reference. My cursor is above the "next" button which changes color themes
I'm not sure but I think it's not possible to optimize it further (I haven't checked your code yet) since you have to refresh the UI to check for input anyway
Ah wait there is some refactoring possible
You're calling menu() twice in the main() loop
That feels redundant
Using global variables also feels unnecessary as you can pass the params directly
recalculate() is completely redundant
You can embed the logic in menu() directly
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
This should be better
Not too different from your original just slightly refactored
I used AI to generate parts for the code and it works well form my testing
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.