Clipboard
Contains functions for interacting with the shared clipboard.
Functions
write(key, value)
Writes a value to the specified clipboard slot.
Parameters
- key — A string containing the key used to identify the slot in the clipboard.
- value — Data to write to the clipboard.
Example
Make a robot chase the player when the Boss's Hp is below 60 percent. Note: for this example to work you have to use the Clipboard.read() example as well.
-- This code is on the Boss
function onStart()
local health = 0
-- start minion behaviour
Channels.publish('minion', true)
-- write boss health percent in the clipboard
while true do
health = Health.percent()
Clipboard.write('boss-health', health)
Task.yield()
end
end
read(key)
Reads a value from the specified clipboard slot.
Parameters
- key — A string containing the key used to identify the slot in the clipboard.
Returns
The value stored in the clipboard, or nil if empty.
Example
Make a robot chase the player when the Boss's Hp is below 50 percent. Note: for this example to work you have to use the Clipboard.write() example as well.
function onStart()
while true do
bossHealth = Clipboard.read('boss-health')
if bossHealth < 50 then
Movement.moveToPlayer(AsyncMode.Continue)
else
Movement.stop()
end
Task.yield()
end
end
isEmpty(key)
Returns true of the specified clipboard slot is empty.
Parameters
- key — A string containing the key used to identify the slot in the clipboard.
Returns
A boolean (true/false).
Example
Check if a slot is being used with a key.
function onStart()
local data = 'data'
Clipboard.write('test-slot', data)
if Clipboard.isEmpty('test-slot') then
print('the slot is empty')
else
print('the slot is being used') -- this one will print
end
end