Snippets

This section includes three useful code snippets for your LightScripts: meters, state handlers, and effects handlers.

The Meter

As a continuation from the previous section, the Meter class is designed to help track meaningful changes in unstable metered data. Think of it as a brake pedal for your code - providing stability even in complex zones. Each meter holds a customizable array of values collected during each run of your update function. When all values in that array are the same (i.e., the data is "stable"), the meter updates its value and triggers a linked callback function to activate an effect.

MethodDescription
Meter(size, callback)

The constructor accepts both a size and a callback.

size - the number of times an identical value should be present in order for the meter value to be considered 'stable' enough to be processed. Higher values result in more accuracy, lower values result in less latency.

callback - a function to be called when the meter value is stable and has changed.

Meter.setValue(value)You should call setValue(value) every frame, or any time new raw data for this meter is available.

The process of collecting screen data should generally follow this structure:

  1. The engine.vision.meter value updates based on new data from the screen.
  2. Inside the update function, Meter.setValue(engine.vision.meter) is called to record the new value.
  3. The Meter checks its internal array to see if all values are identical. If so, it updates its own state and runs its assigned callback function.
  4. The callback function then evaluates specific conditions using the Meter's variables and executes its code if those conditions are met.

IMPORTANT NOTE:

Do not skip using callbacks. Since the update function runs continuously, it must remain as efficient as possible. Its primary role should be to update Meter values. Avoid chaining conditionals within update to check meters and trigger effects, as this leads to unnecessary checks on every cycle. Instead, define your effects in separate functions and pass them into your Meter as callbacks.

Meter Variables

When stable, the Meter will provide a few values to its callback function:

VariablesDescription
Meter.valueThe current value of the meter.
Meter.increasedA boolean that indicates whether or not our value has increased this update
Meter.decreasedA boolean that indicates whether or not our value has decreased this update
Meter.diffThe absolute value of the change the meter has experienced this update.

Meter Example

Here is a basic single-meter setup, including the Meter class code:

All
Head
Body
Script
Meter
Copy

The State Handler

The state handler is an effect stack that specifically handles effects that have precedence over all others. If you want one big dominant animation to run until it is done with no interruption, insert it into the state handler.

MethodDescription
StateHandler()The constructor requires no arguments.
StateHandler.push(new State())You can push a new state onto the state stack using push, and processing will begin immediately.
StateHandler.pop()Pops the current state off the state stack, and begins processing the previous state on the state stack.

Any object pushed into the state handler must implement Process(). The Process function determines the lifespan of an effect in the handler.

State Handler Example

The following shows a basic state handler, plus the Process function that should run inside your effect functions:

State Handler
Effect Process()
Copy

The Effect Handler

Effect handlers are excellent for storing and rendering smaller, lighter effects all together. Each effect in the handler will be evaluated on each update call, and they are removed when they reach the end of their lifespan.

The effects handler is just an array to store effects. That is all.

Effect Handler
Copy

EFFECT VS. STATE WARNING

The state manager is specifically for priority effects, which means we have to give it priority during execution. In your update function, process the effect handler THEN the state handler. This will draw the state effect on top of the effect handler's items.

Like this:

Do This
Copy

USB Data Capture Guide

Saving USB data is a straightforward process, but the drivers used by these programs are known to conflict with certain systems, sometimes disabling USB ports until the software is removed. The common fix is to disable 'Secure Boot' in your BIOS/UEFI settings. Before proceeding, it's strongly recommended to have a system restore available on a flash drive or a way to remotely access your computer that doesn’t rely on user input at boot time. This is important in case disabling Secure Boot doesn’t resolve the issue and you’re unable to access the system to uninstall the program. In such cases, a Windows refresh may be necessary to remove all installed programs while keeping your personal files. You are doing this at your own risk. If you don’t feel comfortable trying, request your device here. Do not use a laptop system for this process.

Once installed, the process is simple and will capture all data passing through your USB devices. Do not type any sensitive information while capturing if you plan to share the data, as keystrokes are included in the recording. Two third-party programs that can be used are Usblyzer(free trial) and Wireshark (free). Both work, but if you choose Wireshark, make sure USBPcap is selected.

Check out our next page, Callbacks, for more detail on constructing meter callbacks and effect functions.

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard