Difference between revisions of "HPL3/Scripting/Scripting Guide/The Update method"
Line 21: | Line 21: | ||
===Example=== | ===Example=== | ||
+ | If we wanted to increase the brightness of a light based on the distance of the player from that light, we could use the <code>Update</code> method to always update the brightness value at any given time: | ||
− | |||
− | |||
− | |||
Revision as of 22:12, 12 August 2020
This article is actively undergoing a major edit. The user who added this notice will be listed in its edit history should you wish to contact them. |
Update
Update
is one of the most commonly used methods in HPL3. It’s called once per-frame in every script that uses it. Almost anything that needs to be changed or adjusted regularly happens here.
The Update method gets called on a fixed timeline and has the same time between calls. Immediately after Update is called, any necessary calculations are made, such as physics or dynamic value changes. Anything that affects rigid bodies, meaning a physics object, should be executed in this method.
Below is the default code in a map script file for Update
:
void Update(float afTimeStep)
{
}
Breakdown
afTimeStep
represents the time (in seconds) which takes the function to get called. It is called every frame, and the game can run up to 60 frames per seconds. Therefore, the value ofafTimeStep
will almost always be0.0167 seconds
(60 fps in seconds).
However, we can also use it to calculate different things that aren’t related to physics.
Example
If we wanted to increase the brightness of a light based on the distance of the player from that light, we could use the Update
method to always update the brightness value at any given time: