-
Notifications
You must be signed in to change notification settings - Fork 333
Expression 2 Core Timer
<< Go back to Expression 2: Features
Timers in E2 are used to schedule ahead another execution. Whenever anything tells the expression to update itself, all of its code runs at once.
How do you get it to only run certain pieces of your code? To do that, you'll want to check if the current execution was caused by a certain trigger or timer, using clk() functions. (Click, clock, whatever your preference.)
To that end, it is impossible to get an expression 2 to "sleep," "wait," or "pause" for code in-line. Everything must have a scheduled trigger.
At the very core of E2, it must be triggered by something in order to run after it initially spawns. This can be from either what was previously scheduled, or by external means, such as a wired input that was updated and changed.
By default, all inputs will trigger an E2 to run its entire code. To change this, you can use the @trigger directive to only allow certain inputs to trigger the expression, or use @trigger none to disable input triggering altogether.
Function | Returns | Description |
---|---|---|
~InVar | if(~InVar){doThings()}. Input update operator, returns 1 if the current execution was caused by the input named InVar. Shorthand of if(inputClk()&inputClkName()=="InVar")). | |
inputClk() | Returns 1 if the current execution was caused an input (Any of them) | |
inputClkName() | Returns the name of the input which caused the current execution, if any. | |
runOnTick(N) | - | Sets the expression to run every physics tick. 1 to enable, and 0 to disable. Persists between executions. |
tickClk() | Returns 1 if the current execution was caused by the tick clock. | |
first() | Returns 1 if this is the first time the E2 has executed (Just spawned in). Persists across duplication. | |
last() | Returns 1 if this is the last time the E2 will execute. Requires runOnLast() to have been enabled. | |
runOnLast(N) | - | Schedules an E2 to run its code when it is about to be removed, undone, or otherwise. 1 to enable, 0 to disable. |
More triggers can be found throughout the various extensions. Really, it's easier just to search for "runOn" and "clk" in the E2 helper.
Timers in E2 are interesting as, once they're called, they're analogous to a lua timer.Simple. In other words, you don't tell an E2 to run every 1500ms. What you're doing when you give it an interval(1500) instruction, you tell it to run again only once in 1500 milliseconds, and once only. If it finds the interval again in that next execution, it'll tell it to go again still after 1500ms, giving you an interval loop.
This is why it's important to keep track of where and how you're scheduling your timers.
Function | Returns | Description |
---|---|---|
interval(N) | - | Runs the E2 again in N milliseconds. Rounds up to the nearest game tick. (EG. 66 tick will round in 15ms increments) Same as using timer("interval",N) |
timer(S,N) | - | Schedules a timer with the name S to run the E2 after N milliseconds. |
stoptimer(S) | - | When called before a timer is executed, stops and cancels the timer. Note timer priorities below. |
stopAllTimers() | - | Cancels all active timers. (including interval, if called before executing) |
clk() | Returns 1 if the current execution was caused by the interval timer. Same as using clk("interval") | |
clk(S) | Returns 1 if the current execution was caused by the timer named S. | |
clkName() | Returns the name of the timer that executed the E2. | |
getTimers() | Returns a list of all currently scheduled, active timers. |
If you have a case where two or more timers are set to execute on the same tick, they'll run in alphabetical order. However, interval has a higher priority than a named timer.
For example:
if(first()){timer("testa",100),timer("testb",100),interval(100)}else{ if(clk("testa")){stoptimer("testb"),print("Clked on test2. Stopped test1.")} if(clk("testb")){stoptimer("testa"),print("Clked on test1. Stopped test2.")} if(clk("interval")){print("Clked interval.")} }With this code, three timers execute in 100ms. "testa," "testb," and "interval." When it runs,
Clked interval.
is the first to print. Then, the timer named "testa" executes, stopping "testb" from executing. Switching "testb" with a character further behind sequence than "testa," such as the character 1
, will cause what was previously "testb" to execute first instead.
These functions don't really have anything to do with the timers system in E2, but they do return values related to time.
Function | Returns | Description |
---|---|---|
curTime() | Returns the current game world time since the map loaded. This scales with things such as game lag and host_timescale. | |
realTime() | Returns the real world time since the server has started. Only updates whenever the server processes a frame. | |
sysTime() | Returns a highly accurate system time since the server started, ideal for benchmarking. Unlike realtime, this will recall whatever the real value is, the moment it is called. | |
date([N]) |
Returns a table describing the current date. The keys of this table can be previewed further below. When given a number, it will return the values of the table for the number of seconds passed since 6:00PM, 31st Dec 1969. |
|
dateUTC([N]) | Same as date() but adjusted to the UTC standard, instead of being based in the server's timezone. | |
time(S) | Precursor to date(). Returns the same values as the strings of the table keys returned by that function, but used differently. Not really deprecated per-se. | |
time() | Returns the number of seconds passed since 6:00PM, 31st Dec 1969 using the server's timezone. | |
time(T) | Accepts a table containing date keys described below. Returns the number of seconds passed since 6:00PM, 31st Dec 1969 at the specified date in the table. Requires year, month, and day. |
String key | Description |
---|---|
year | The current year, A.D. |
month | The current month of the year |
day | The current day of the month |
hour | The current hour of the day |
wday | The current day of the week, numeric, starting from 1 on Sunday. |
isdst | Boolean. Returns 1 when Daylight Savings Time is in effect in this timezone. |
min | The number of minutes on the hour |
sec | The number of seconds on the minute |
yday | The number of days passed in the year |
Please do not alter the e2 docs ...
pages manually.
They are autogenerated from the E2Helper. In the future, this will hopefully be its own dedicated website or tool.
Basic Features: core, debug, number, selfaware,
string, timer
🌎 World: angle, color, find, ranger, sound,
🔣 Math: bitwise, complex, matrix, quaternion, vector, vector2/4
📦 Entities: bone, constraint, egp, entity, hologram, npc
👨 Players: chat, console, player, weapon
📊 Data storage: array, files, globalvars, serialization, table
💬 Communication: datasignal, http, signal, wirelink,
❓ Informational: gametick, serverinfo, steamidconv, unitconv
Disabled by default: constraintcore, effects, propcore, remoteupload, wiring
Wire-Extras (repo): camera, ftrace, holoanim, light, stcontrol, tracesystem
Expression 2 ⚙️
- Syntax 🔣
- Directives 🎛️
- Editor 🖥️
- Ops 📊
- Learning & Getting Help 📚
- Triggers ⏲️
- Events 🎬
- Find Functions 🔍
- Physics 🚀
- EGP Basics 📈
- Lambdas λ
- Tips & Tricks 📘
Click To Expand
- 🟥 SPU
- 🟥 Address Bus
- 🟥 Extended Bus
- 🟥 Plug/Socket
- 🟥 Port
- 🟥 Transfer Bus
- 🟩 GPU
- 🟥 Dynamic Memory
- 🟥 Flash EEPROM
- 🟥 ROM
- 🟧 Beacon Sensor
- 🟧 Locator
- 🟧 Target Finder
- 🟧 Waypoint
- 🟥 XYZ Beacon
- 🟩 CPU
- 🟩 Expression 2
- 🟩 Gates
- 🟥 PID
- 🟧 CD Disk
- 🟥 CD Ray
- 🟧 DHDD
- 🟥 Keycard
- 🟥 RAM-card
- 🟧 Satellite Dish
- 🟧 Store
- 🟧 Transferer
- 🟥 Wired Wirer
- 🟧 Adv Entity Marker
- 🟧 Damage Detector
- 🟧 Entity Marker
- 🟧 GPS
- 🟧 Gyroscope
- 🟥 HighSpeed Ranger
- 🟧 Laser Pointer Receiver
- 🟥 Microphone
- 🟧 Ranger
- 🟧 Speedometer
- 🟧 Water Sensor
- 🟧 7 Segment Display
- 🟥 Adv. Hud Indicator
- 🟧 Console Screen
- 🟧 Control Panel
- 🟧 Digital Screen
- 🟧 EGP v3
- 🟧 Fix RenderTargets
- 🟥 GPULib Switcher
- 🟧 Hud Indicator
- 🟧 Indicator
- 🟧 Lamp
- 🟧 Light
- 🟧 Oscilloscope
- 🟧 Pixel
- 🟧 Screen
- 🟧 Sound Emitter
- 🟧 Text Screen
- 🟩 Cam Controller
- 🟧 Colorer
- 🟧 FX Emitter
- 🟧 HighSpeed Holoemitter
- 🟧 HoloEmitter
- 🟧 HoloGrid
- 🟥 Interactable Holography Emitter
- 🟥 Materializer
- 🟥 Painter
- 🟧 Adv. Input
- 🟧 Button
- 🟧 Constant Value
- 🟥 Door Controller
- 🟧 Dual Input
- 🟧 Dynamic Button
- 🟧 Eye Pod
- 🟧 Graphics Tablet
- 🟧 Keyboard
- 🟥 Lever
- 🟧 Numpad
- 🟧 Numpad Input
- 🟧 Numpad Output
- 🟧 Plug
- 🟧 Pod Controller
- 🟧 Radio
- 🟧 Relay
- 🟧 Text Receiver
- 🟧 Two-way Radio
- 🟧 Vehicle Controller
- 🟥 Door
- 🟥 Adv. Dupe. Teleporter
- 🟥 Buoyancy
- 🟧 Clutch
- 🟧 Detonator
- 🟧 Explosives
- 🟧 Explosives (Simple)
- 🟥 Forcer
- 🟩 Freezer
- 🟧 Gimbal (Facer)
- 🟧 Grabber
- 🟧 Hoverball
- 🟧 Hoverdrive Controller
- 🟥 Hydraulic
- 🟧 Igniter
- 🟧 Nailer
- 🟩 Prop Spawner
- 🟥 Servo
- 🟥 Simple Servo
- 🟧 Thruster
- 🟥 Touchplate
- 🟥 Trail
- 🟩 Turret
- 🟩 User
- 🟥 Vector Thruster
- 🟥 Vehicle Exit Point
- 🟧 Weight (Adjustable)
- 🟧 Weld/Constraint Latch
- 🟥 Wheel
- 🟥 Wire Magnet
- 🟥 Wired Npc Controller
- 🟧 Debugger
- 🟥 GUI Wiring
- 🟥 Multi Wire
- 🟧 Namer
- 🟥 Simulate Data
- 🟩 Wiring
- 🟥 Beam Reader
- 🟥 Implanter
- 🟥 Reader
- 🟥 Target Filter
- 🟥 User Reader
Gates 🚥
Click To Expand
TBD