Replies: 2 comments
-
As lines of code run sequentially, the output of both code listings is the same. So you don't have to worry about potential issues or bugs with the first version of the code, it's a typical way to limit a value. When calling the |
Beta Was this translation helpful? Give feedback.
-
You're right about that. I was thinking about race conditions such, but since games are mostly ran on a single thread, there's no way for other code to execute until the function call fully resolves. |
Beta Was this translation helpful? Give feedback.
-
Something I noticed is is that on the Lesson 13 demo on adding health, the health is set to a level beyond 100 (125), and then it's set back to 100. In practice, I'm not too sure how error prone this is, but shouldn't health never be set to above 100 (assuming max is 100)? For example, there might be a frame where health is beyond max and it might result in bugs if there are other calculations on the same frame.
So in that case, instead of the original code...
maybe something like this would be a better.
It would be better to use an
else
, else is explained in the later part of this lesson so if we used it, this demo would have to come after it.I think people would question why we need to define a
new_health
variable, and why couldn't we just do it like the original way. Maybe that could be explained as well as an aside; that when updating health, its actual value should never be set above max.Beta Was this translation helpful? Give feedback.
All reactions