Index

:!: Available in version 2.5 and later.

PingPong

PingPong (<-t <-length)

Description

PingPong returns a value that increments and decrements between zero and the length. It follows the triangle wave formula where the bottom is set to zero and the peak is set to length.

PingPong requires the value t to be a self-incrementing value.

This is similar to SignalGenerator for a triangular wave form, but more performant.

Examples

# An example of a unit + a beam. 
# The brightness of the unit and beam fluctuates while paused.
# The interval of t is 60+60 frames = 4 seconds.
 
:once
# Running the code in :PostUpdate allows it to work while paused when inside a unit script.
RegisterForMSG("MSG_PostUpdate" "PostUpdate") 
 
# To Differentiate against other units of the same type, the pulse time is set out of sync:
self getunittype 0 getunitsbytype ->unitList
<-unitList self getlistindex 33 mul getgametickcount add 120 mod ->t 
   # tickcount instead of updatecount since this will run while paused.
 
# Creating a beam between the unit and another unit
"red" 2 3 createbeam ->otherBeam
<-otherBeam <-otherUID "sphere" 1 getobjposition setbeamstart
<-otherBeam self "core" 1 getobjposition setbeamend
 
:PostUpdate
<-t 1 add dup ->t 60 pingpong ->pingpong
self "core" <-pingpong 10 div 0 0 v3 setobjcolor
<-otherBeam <-pingpong 60 div setbeambrightness

Index