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

Director: cards of your own

Put cards of your own in the Director's palette, and builders drag them into scenarios like whip_core's own. whip_core gets the card as data and calls your code through @whip_core/lib/satellite.lua, so an error reaches your console in its own words.

A minigame doesn't need a card. Add it as a skill check game and it's a choice in the Skill Check card, with Passed, Missed (out of time, or no answer) and Couldn't start (wire it back to a Wait for Press). whip_phone's seven phone games work this way.

Adding a card

Whip.card(type, def)SERVER#

Adds a card, or changes one. type is '<your namespace>.<name>': the first running resource to use a namespace has it, for cards and events. Call it at file scope or in Whip.register: it's sent again whenever whip_core restarts. A refusal is printed with the reason.

FieldTypeDescription
titlestringIts name in the palette
desc, helpstring?One line under it, and the editor's longer help
category, categoryTitle, color, iconstring?Its palette group (default: your namespace) and the group's name; a colour (blue, teal, green, amber, red, violet, slate); an icon
outputsstring[]Its outcomes, one pin each. labels = { sent = 'Sent' } names them; bad lists the ones drawn as going wrong
propstable[]?Its fields, up to 40: { key, kind, label, default?, required?, hint?, unit?, group?, showIf? }. group (30 characters) heads this field and those after it; showIf names a bool field that must be on
props[n].kindstringtext (maxLength, lines 1–6), number or duration (min, max), bool, select (up to 200 options: text, or { value, label }), world (a placed thing; worldKind: 'spot', 'npc'…), worlds (several placed things and groups of them; worldKind, max 1–50), item, var, job, players, lore, entries
props[n] of kind entries: button, add, maxstring, string, numberA list one of your Director buttons fills: button its id (kind 'card'), add the words to add one, max 1–12. Each entry is plain data, its text shown on its row
runfunction(card)?Its code; it may wait. Return an outcome, or nothing and answer later with Whip.answerCard
instantboolean?It returns at once and never waits
timeoutnumber?Seconds before Took Too Long (30; the builder can change it)
eventtable?{ name, match = 'player' | 'run' | 'any', once?, filter? } in place of run: it goes on when you send that event
failtable?A Fail Condition, in place of run and outputs: { event, match?, ends?, reason?, filter? }. It watches the whole run; when you send event about one of its players, the run fails for everyone or that player is taken out. ends ('everyone' or 'them') and reason are the defaults of its When it is broken and Why fields; match defaults to 'player'. filter(card, event): true or the words to tell them breaks it
checkfunction(props, doc)?Return a problem for the editor to show, and 'warning' if it doesn't stop a run. doc has the scenario's vars, world ({ id, kind, label } each) and data[worldId] (what your buttons saved)
onEndfunction(callId, why)?It ended without your answer: tidy up what it made
testSaysstring?What a Test says in place of running your code; {message} fills in a field
test'run'?Your code runs in a Test too, with card.test true: keep what it does to card.player
permissionstring?Only people with this permission may add it or change its fields
v, renamednumber?, table?Bumped when its fields change; its old names, { ['old.type'] = { pins = { old = 'new' } } }
once, onceOutboolean?, string?The Only once switch skips it on later visits, through onceOut (default: its first outcome). once = false removes the switch, for a card the run waits at for a player
Returns: true, or false (printed) when def isn't a card
Whip.card('mycafe.callStaff', {
    title = 'Call Staff', color = 'teal',
    desc = 'Tells the café staff on duty, with a message.',
    outputs = { 'sent', 'nobody' }, labels = { sent = 'Sent', nobody = 'Nobody on duty' }, bad = { 'nobody' },
    props = { { key = 'message', kind = 'text', label = 'Message', default = 'A customer is waiting', maxLength = 120 } },
    testSays = 'Would send "{message}" to the staff on duty',
    run = function(card)
        local staff = Whip.core:GetClockedOnEmployees('mycafe')
        if type(staff) ~= 'table' or #staff == 0 then return 'nobody' end
        for _, s in ipairs(staff) do
            if s.source then Whip.core:NotifyPlayer(s.source, card.props.message, 'info') end
        end
        card:record('called', { detail = card.props.message })
        return 'sent'
    end,
})
card: what your run is handedSERVER#

A copy of what the card is doing, with methods into whip_core, refused once the card has finished. Give card.tag to what you make for the run: it goes when the run ends.

Field or methodDescription
callId, runId, cardIdThis call, its run, the card. Whip.answerCard takes callId to settle it later: never send it to a player's game
scenario, name, rev, tag, testThe scenario's key, name and revision; the run's tag; true in a Test
player, starter, players, triggerWho the run acts for now, who started it, its players (server ids), what started it
propsThe fields as the builder set them. A world field is the placed thing, { id, kind, label, coords = { x, y, z }, heading } (nil when not placed); a worlds field a list of them, a group as each thing in it; a players field a list of server ids
card:var(name) · card:setVar(name, value)The run's variables
card:state() · card:setState(t)This card's own state, kept between its calls
card:place(id) · card:made(id)A placed thing's place, and what the run made for it
card:record(kind, { source?, detail? })A line in the run's history
card:objective(text, { who? }) · card:clearObjective()The objective band. It comes down by itself if the card ends without your answer; when you answer, take it down first
card:clock(seconds, label)A countdown on the band (0 stops it)
card:give(src, item, n, metadata?)Items, as Give Item gives them (a Test takes them back)
card:pay(src, amount, { method?, reason? }) · card:charge(src, amount, { method?, reason? })Money, with the run's protections: in a Test, Pay only says it and Charge charges nothing
card:finish('succeeded' | 'failed' | 'calledOff', reason?)Ends the run
card:log(fmt, …)A console line naming the run and the card
Returns: var, state, place, made: the value, or nil, why. The rest: true, or false, why
Whip.answerCard(callId, outcome, data?)SERVER#

Answers a waiting card later: an officer pressing E at the place, a phone reply. outcome is one of the card's own; data.source is which of the run's players what follows acts for. Only the card's own resource may answer.

Returns: true, or false, reason (no longer waiting, or not one of its outcomes)
Whip.answerCard(callId, 'responded', { source = officer })
A wrong outcome doesn't retry. One the card lacks (a typo, 'timeout') ends it as Didn't Work, or stops the run if nothing is wired there.
Whip.removeCard(type) · Whip.scenario(key, doc) · Whip.template(name, doc)SERVER#

Whip.removeCard takes one of your cards away (all go when your resource stops). Whip.scenario offers a scenario built in code to the Director admins: pending until one accepts it (unless they trust your resource), then read-only. Whip.template adds a starting point to the editor's New list. doc is a scenario document as the editor saves it; both are sent again when whip_core restarts.

Returns: removeCard: true, or false, reason. scenario, template: nothing (a refusal is printed)

Testing without the editor

Both run as a builder's Test: Give's items go back at the end, Pay and Charge only say it, and no script hears of the run. Both wait: call them from a thread.

TestDirectorCard(type, props?, opts)SERVERWAITS#

Runs one of your cards once for a player, until it has an outcome, with card.test true.

ParamTypeDescription
typestringOne of your own cards
propstable?Its fields; a place field takes { x, y, z, heading? }, a field of several (worlds) a list of them
opts.playernumberWhose test run it is (required)
opts.secondsnumber?How long to wait, 1 to 120 (default: its Give up after, and 5 more)
opts.eventtable?An event card's payload, as SendDirectorEvent's
Returns: { outcome, data } ('timeout' when time ran out), or false, reason (Check's first problem, it failed, no answer in time)
CreateThread(function()
    local result, why = Whip.core:TestDirectorCard('mycafe.callStaff', { message = 'Test call' }, { player = source })
    print(result and result.outcome or why)
end)
TestDirectorScenario(doc, opts) · SteerDirectorTest(runId, op, ...) · GetDirectorTestResult(runId)SERVERWAITS#

Runs a whole scenario document once as a Test for a player, until it ends, steering it as the test map does. It must pass Check (one that can never succeed is tested anyway). One per player at a time, three of yours at a time.

ParamTypeDescription
doctableA scenario document, as the editor saves it
opts.playernumberWhose test run it is (required, on a character)
opts.secondsnumber?1 to 600 (default 60): still going then, it's ended (late)
opts.varstable?{ name = value }, set before its first card
opts.steertable?Done in order: { op = 'take', node, pin } and { op = 'say', node, option, amount? } once their card waits; 'event', 'emit' and 'var' at once or once their when card waits; { op = 'end' }; { op = 'wait', ms }
opts.waitboolean?false: return at once, and steer it as it goes

SteerDirectorTest does one op now: 'take', nodeId, pin; 'say', nodeId, option, amount?; 'event', name, payload? (a script's event); 'emit', name, payload? (a Director event, to this run alone); 'var', name, value; 'end', outcome?, reason?. GetDirectorTestResult reads one of yours, kept ten minutes after its end.

Returns: { runId, status, reason, vars, steps, fired, entered, waiting, things, done, late } (fired[card][outcome] counts each way it went), or false, reason. Refused because the player already has a scripted test going that is yours, the third value is its runId: end it with SteerDirectorTest(runId, 'end'). SteerDirectorTest: true, or false, reason
CreateThread(function()
    local r = exports.whip_core:TestDirectorScenario(doc, { player = source, steer = {
        { op = 'say', node = 'offer', option = 'opt1' },   -- answer 1 of the Dialog Line 'offer'
    } })
    print(r and r.status, r and r.reason)
end)