Esc to clear, Enter to open the best match, click an export to open it in its page
whip_phone

Phone API

Reach a player's phone from your resource with exports.whip_phone. New to the phone? Read Phone System first; to add an app, Phone apps.

If your resource runs without the phone, check GetResourceState('whip_phone') == 'started' before a call.

Server

Notify(source, n)SERVER#

A notification on the player's phone. It peeks up from the corner while the phone is put away, and a tap opens the app it names.

n fieldTypeDescription
title, textstringWhat it says
appstring?The app it's from: its icon, and what a tap opens. An unknown id shows a bell
kindstring?'chat' (the default), 'command' (it needs them), 'success', 'error', 'warning' or 'call'. Only 'call' gets through Do Not Disturb
argstable?Handed to that app's open when it's tapped
soundboolean?false: quiet. Otherwise it plays the SIM's notification sound, unless Do Not Disturb is on
Returns: true, or false when n isn't a table
exports.whip_phone:Notify(source, {
    app = 'mycars', title = 'My Cars', text = 'Your Sultan was towed', kind = 'warning',
})
It shows whether or not they carry a phone. Check GetItemCount(source, 'phone') first if a player without one shouldn't see it.
Push(source, app, event, data)SERVER#

Runs on[event](app, data) in that app on the player's phone, so your app updates without asking.

ParamTypeDescription
sourcenumberThe player
appstringThe app's id
eventstringThe name of one of its on handlers
dataanyWhat the handler gets
Returns: true
exports.whip_phone:Push(source, 'mycars', 'changed', { id = vehicleId })   -- runs on.changed
Open(source, mode) / Close(source)SERVER#

Takes the player's phone out, as F3 does, or puts it away. It opens only with a phone on them; without one they're told "You need a phone".

ParamTypeDescription
sourcenumberThe player
modestring?'phone' (folded, the default) or 'tablet'
Returns: true

Client

Open(mode) / Close() · IsOpen() / GetState()CLIENT#

Takes this player's phone out or puts it away, as the server's do, and says whether it's in use. IsOpen is true while the player is using it (it has the focus).

Returns: GetState: 'hidden', 'peek' (notifications showing), 'phone' or 'tablet'
if exports.whip_phone:GetState() == 'tablet' then return end   -- it covers the screen's middle
Notify(n) / Push(app, event, data)CLIENT#

The server's Notify and Push, for this player's phone, without the server.

Returns: nothing
RegisterModule(def) / UnregisterModule(id)CLIENT#

Adds your resource's app to the phone, or takes it away. It goes by itself when your resource stops; register it again when whip_phone restarts (Whip.registerWith does both). See Phone apps.

def fieldTypeDescription
idstringLowercase letters, digits, _ or -, up to 32 characters
scriptstringThe app's file in your resource, listed in its files {} (default 'html/module.js')
nsstring?What its requests start with (default your resource's name): app.request('list') asks <ns>:list
Returns: true, or false, why: a bad id, 'that id is a built-in module', or 'the phone app "mycars" belongs to other_res'. UnregisterModule takes only your own
RunApp(id, args) / IsHeld()CLIENT#

Opens the phone unfolded to a tablet, held to one app, and waits for its answer: no home screen, no folding, no other app, and every game control held off. The app answers with app.done(result); putting the phone away, or Back the app doesn't take, gives up. Afterwards the phone goes back to how it was. Call it from a thread. IsHeld says whether one is running.

ParamTypeDescription
idstringThe app
argstable?What its open(app, args) gets
Returns: the app's result table; { passed = false, why = 'cancelled' } when given up; or nil, why when it can't start: 'busy', 'dead', 'no app', 'not ready'
CreateThread(function()
    local result, why = exports.whip_phone:RunApp('mycars', { pick = true })
    if not result then return print('the phone could not open: ' .. why) end
    if result.why == 'cancelled' then return end                 -- put away
    print('they picked car ' .. tostring(result.id))             -- the app called app.done({ id = ... })
end)

Events#

EventSideArgsWhen
whip_phone:client:openedClientopen (boolean)The player took the phone up or let it go. Not for something in their hands: the phone plays Config.Emotes itself, and a second animation fights it
whip_phone:client:stateClient'hidden', 'peek', 'phone' or 'tablet'What the phone shows changed