Is it bad to constantly set a variable to a static value for duration of a keypress in event tick?
Event Tick()
if BKeyPressed = True
then setMaxSpeed = 5000
or should I always set the values in the keypress/released where button press only fire once?
(note: KeyPress Events only fire once)
ifBKeyPressed then setMaxSpeed = 5000
ifBKeyReleased then setMaxSpeed = 50
Obviously the latter seems more efficient, but does it matter? Is it okay to set a variable to the same value over and over in the event tick for the duration of a keypress?
The latter would put a lot less pressure on the system, depending on how fast your keypress event fires. Is there a reason you would need to set the variable to a specific value while the key is pressed? I can understand if the variable changes in the programming and you need to reset it again.
I’ve made it a rule to never set a variable in the event tick unless it’s value is consistently changing (dynamic). If I set a variable to a static value that barely changes, it should only be once during an event that happens once.
Correct. I also feel better about having a setup where i know that i changed my variables. I often have a lot of notify calls that change stuff for me (depends on the game and situation).
For example notifying that a character is stunned. Why setting something that stops him from moving on tick, if i could just have the notification change all the values i need once, and revert them
once he’s not stunned anymore. That’s just a small example.