LaptopExports and events

Exports and events

Every export and event the Laptop gives other resources, on the server and the client.

On this page

Server exports

exports.tr_laptop:<name>(...)

Export
registerApp(def) → ok, problem?See Adding apps
registerDevice(def) → ok, problem?See Adding devices
registerSite(def) → ok, problem?See Adding websites (1.2.0)
unregisterSite(domain) → removedTakes one of your websites down (1.2.0)
getOpen(src) → { serial, coords }?The laptop a player has open
getHolder(serial) → src?Who has a laptop open
close(src, reason?)Shuts a player's laptop. A reason (an error.* key or your own text) is shown to them
refresh(serial)Sends the player on that laptop every app's state again. Call it when what your app shows changed without its page asking
sendApp(serial, app, event, data)A message to your page on that laptop, if it's open and logged in
sendSite(serial, domain, event, data)A message to your website's page on that laptop, if it's open, logged in and the site is up in the browser (1.2.0)
notify(serial, { app?, title, body?, error? })A notification on that laptop's screen, if it's open and logged in
isInstalled(serial, app) → booleanInstalled and finished installing
runnable(serial, app) → ok, reason?Installed and its devices plugged in. Reasons: no_app, not_installed, installing, needs_device, not_placed
isPlugged(serial, device) → boolean
getData(serial) → anyWhat your resource keeps on that laptop
setData(serial, value) → savedKeeps it (nil clears it)
writeFile(serial, folder, name, text) → ok, problem?Puts a text file in one of the account's folders (desktop, documents, downloads, pictures, music, videos), or changes the one there by that name. From then on it's the user's. Problems: not_placed, bad_folder, file_name, name_taken, too_big, disk_full, too_many
readFile(serial, folder, name) → text?What a text file in one of those folders says (not in the Recycle Bin)
listFiles(serial, folder) → { name, size, at }[]?The text files in one of those folders (not those in folders inside it). size in bytes, at = os.time() it last changed
getPlaced(serial) → { coords, heading, ports }?A placed laptop
canReach(src, serial) → ok, reason?Whether a player is near enough to use it. Reasons: not_placed, too_far
shareTargets(src) → { serial, name, own? }[], rangeNearby sharing from something the player holds (a phone): the laptops within share.range metres open by other players, and those the player logged in to since they joined (own)
shareOffer(src, serial, fromName, files) → id?, problem?Sends text files ({ name, text }[]) to one of them. Whoever uses it is asked to save them into Downloads; on one of the player's own they're saved without asking. The answer comes as tr_laptop:shared. Problems: not_nearby, share_busy, file_name, too_big, invalid_args, and on an own laptop disk_full, too_many
shareCancel(id) → booleanCalls off one of your offers still waiting

The laptop exports (isInstalled, getData and so on) work on placed laptops only: a laptop in someone's inventory can't be used.

Client exports

None of these wait. Walking the player somewhere or playing an animation is up to you.

Export
getOpen() → serial?The laptop the player has open
isBusy() → booleanThe player is placing, using or plugging into a laptop, or another resource claimed them
claim() → booleanMarks the player busy at a laptop while you do something there. false if they're busy already. Call release() when done
release()
serialOf(entity) → serial?The placed laptop a prop belongs to (its base, lid, or a device next to it)
getEntity(serial) → entity?A placed laptop's base, when it's drawn near the player
getDeviceEntity(serial, device) → entity?A plugged-in device's prop
frontOf(entity, depth) → spot, heading, kneelWhere to stand or kneel to use a prop depth metres deep
addOption(option, device?)A third eye option on every placed laptop, or on a cabled device's box. option = { name, label, icon?, distance?, canInteract?(entity, serial), onSelect(entity, serial) }. The same name replaces it; removed when your resource stops
removeOption(name)
sendApp(app, event, data)A message to your page while the player has the laptop open
sendSite(domain, event, data)A message to your website's page while the player has it up in the browser (1.2.0)

Events

Server, local (AddEventHandler):

EventArguments
tr_laptop:readyThe Laptop started: register your apps, websites and devices
tr_laptop:openedsrc, serial
tr_laptop:closedsrc, serial
tr_laptop:installedsrc, serial, app
tr_laptop:uninstalledsrc, serial, app
tr_laptop:pluggedserial, device, src
tr_laptop:unpluggedserial, device, src
tr_laptop:erasedsrc, serial: the laptop was erased. What you keep with setData is gone already; clear anything else you keep for that serial
tr_laptop:sharedid, kind: how a shareOffer went: sent, declined, unanswered (not answered within share.wait seconds) or failed (the laptop closed or was full, or the player left or walked off)

Client, local: tr_laptop:opened(serial), tr_laptop:closed(serial).

Was this page helpful?

Still stuck? Open a ticket on Discord.Privacy