0

In the project I'm working on in Pygame, there are a lot of variables that need to be decremented to 0 over time (momentum of an object, charge level of a battery, etc.). Instead of creating a seperate USEREVENT+X for each variable, I figured it would be useful to create a decrementvariable() function which takes a variable and a time in milliseconds, and brings the variable to zero over that time. Multiple variables may be reducing to zero at any given time.

However, the only way I know to create USEREVENTS is to hard code them, which brings me to my question:

Is there a way to dynamically create USEREVENTS so that my goal can be met? Or would I have to go about this in some other way?

martineau
  • 119,623
  • 25
  • 170
  • 301
Metalgearmaycry
  • 271
  • 1
  • 2
  • 7
  • Seems like you could do it with single `USEREVENT` which caused a check to be made of some private container of "active" variables that needed to be decremented. Variables could be added and removed from the this container as needed. – martineau Jul 14 '17 at 13:00
  • `USEREVENT` is just a variable name; you can type `pygame.event.post(pygame.event.Event(USEREVENT + x))` (as long as x in an integer between zero and eight. – pppery Jul 14 '17 at 13:09
  • Can you show us a simple example that demonstrates what you want to achieve (or what you have tried yet)? It sounds to me like you want several objects with their own unique timers. In this case I'd use the time that `clock.tick` returns, pass it to the objects that need it and decrement their timer attributes. – skrx Jul 14 '17 at 14:10

0 Answers0