Hi
I've built a system for handling gui-popups that the player can answer to. The popup when called sets an "popup id" so i can check for that popup being answered elsewhere in the code like so:
if (timeToEat())
callPopup(13, "What to eat?", "Cake", "Cookies!");
//elsewhere in code
if (popupAnswered(13,0)) // clicked first button in popup
eatCake();
if (popupAnswered(13,1)) // clicked second button in popup
eatCookiesDamnit();
So i just increase the id (in the example it's 13) when adding more popups. This isn't ideal of course but I don't want to add defines or enums to identify the popups. Adding new popups should be easy.
Another idea is to set a string value when calling a popup and check for that string to be exactly the same (the string will be the ID instead). Would that make sense? What else could I do?
See below for string identifier example:
if (timeToEat())
callPopup("popup_eat_question", "What to eat?", "Cake", "Cookies!");
//elsewhere in code
if (popupAnswered("popup_eat_question",0))
eatCake();
if (popupAnswered("popup_eat_question",1))
eatCookiesDamnit();
↧