Difference between revisions of "HPL3/Scripting/Scripting Guide/The Update method"

From Frictional Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
{{shortPageTitle}}
 
{{shortPageTitle}}
  
== Update ==
+
==Update==
Update is one of the most commonly used methods in the engine. It’s called once per-frame on every script that uses it. Almost anything that needs to be changed or adjusted regularly happens here.  
+
<code>Update</code> 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.
 
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.
 
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 <code>Update</code>:
  
 
However, we can also use it to calculate different things that aren’t related to physics.  
 
However, we can also use it to calculate different things that aren’t related to physics.  
 +
 +
===Example===
  
 
For example, if we wanted to increase a value based on the distance from a certain entity, we could use the Update method to always update the value at any given time.  
 
For example, if we wanted to increase a value based on the distance from a certain entity, we could use the Update method to always update the value at any given time.  

Revision as of 21:57, 12 August 2020


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:

However, we can also use it to calculate different things that aren’t related to physics.

Example

For example, if we wanted to increase a value based on the distance from a certain entity, we could use the Update method to always update the value at any given time.

Let’s look at a quick example of what we can achieve with an update function.