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.
Adding a card
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.
| Field | Type | Description |
|---|---|---|
| title | string | Its name in the palette |
| desc, help | string? | One line under it, and the editor's longer help |
| category, categoryTitle, color, icon | string? | Its palette group (default: your namespace) and the group's name; a colour (blue, teal, green, amber, red, violet, slate); an icon |
| outputs | string[] | Its outcomes, one pin each. labels = { sent = 'Sent' } names them; bad lists the ones drawn as going wrong |
| props | table[]? | 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].kind | string | text (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, max | string, string, number | A 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 |
| run | function(card)? | Its code; it may wait. Return an outcome, or nothing and answer later with Whip.answerCard |
| instant | boolean? | It returns at once and never waits |
| timeout | number? | Seconds before Took Too Long (30; the builder can change it) |
| event | table? | { name, match = 'player' | 'run' | 'any', once?, filter? } in place of run: it goes on when you send that event |
| fail | table? | 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 |
| check | function(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) |
| onEnd | function(callId, why)? | It ended without your answer: tidy up what it made |
| testSays | string? | 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 |
| permission | string? | Only people with this permission may add it or change its fields |
| v, renamed | number?, table? | Bumped when its fields change; its old names, { ['old.type'] = { pins = { old = 'new' } } } |
| once, onceOut | boolean?, 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 |
true, or false (printed) when def isn't a cardWhip.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,
})
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 method | Description |
|---|---|
| callId, runId, cardId | This 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, test | The scenario's key, name and revision; the run's tag; true in a Test |
| player, starter, players, trigger | Who the run acts for now, who started it, its players (server ids), what started it |
| props | The 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 |
var, state, place, made: the value, or nil, why. The rest: true, or false, whyAnswers 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.
true, or false, reason (no longer waiting, or not one of its outcomes)Whip.answerCard(callId, 'responded', { source = officer })
'timeout') ends it as Didn't Work, or stops the run if nothing is wired there.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.
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.
Runs one of your cards once for a player, until it has an outcome, with card.test true.
| Param | Type | Description |
|---|---|---|
| type | string | One of your own cards |
| props | table? | Its fields; a place field takes { x, y, z, heading? }, a field of several (worlds) a list of them |
| opts.player | number | Whose test run it is (required) |
| opts.seconds | number? | How long to wait, 1 to 120 (default: its Give up after, and 5 more) |
| opts.event | table? | An event card's payload, as SendDirectorEvent's |
{ 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)
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.
| Param | Type | Description |
|---|---|---|
| doc | table | A scenario document, as the editor saves it |
| opts.player | number | Whose test run it is (required, on a character) |
| opts.seconds | number? | 1 to 600 (default 60): still going then, it's ended (late) |
| opts.vars | table? | { name = value }, set before its first card |
| opts.steer | table? | 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.wait | boolean? | 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.
{ 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, reasonCreateThread(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)