Editor plugin reference

studio

The editor: register panels, commands and tools, and read and change the place.

FunctionReturnsDescription
studio.panel(config: any)nothingRegisters a panel: { id, title, icon?, dock = 'left', 'right' or 'bottom', visible = true, draw = function() end }. visible = false makes one that starts closed and opens from a View command. icon is the name of a Silk icon, such as 'sitemap'. The editor draws the panel's frame and calls draw to fill it each time it redraws.
studio.command(config: any)nothingRegisters a command: { id, title, menu?, shortcut?, icon?, toolbar?, separator?, enabled?, run }. With a menu it appears there; with toolbar and an icon it is a toolbar button. enabled is a function returning a boolean.
studio.tool(config: any)nothingRegisters a tool for the toolbar: { id, title, icon, shortcut? }, the icon a Silk icon name and the shortcut a single letter such as W. One tool is active at a time. Move, scale and rotate are plugin tools like any other. A tool with another id may give on_press, a function called with the first step of a drag (the shape on_drag gets) the moment the button goes down: return true to take the press (the drag follows at once, with no click slop) or false to let the view select as usual. on_draw is called every frame with { x?, y?, down } (the pointer, when it is over the view) to draw handles with view_line and view_rect. A tool may give on_click, a function called with { x, y, origin, dir, hit?, ctrl, shift } when the 3D view is clicked while it is active: origin and dir are the ray through the pointer, and hit is the id of the part under it (absent on empty ground). The view selects nothing itself then; the function does what the tool is for. It may also give on_drag, called for each step of a drag with { phase, x, y, start_x, start_y, origin, dir, hit?, ctrl, shift }: phase is begin, move (every frame) or end, x and y the pointer, start_x and start_y where the button went down, origin and dir the ray through the pointer, and hit the part under the start. What it changes while the button is held joins one undo step.
studio.active_tool()stringThe id of the active tool.
studio.set_tool(id: string)nothingMakes a registered tool the active one.
studio.selection()anyThe ids of the selected parts, as a list.
studio.select(ids: any)nothingSelects the parts with these ids (a list).
studio.tree(open: any, first: number, count: number, filter: string?)anyA window onto the Explorer tree. open is a table of expanded ids. A filter lists the parts whose names contain it, flat, instead. Returns two values: a list of up to count rows { id, depth, name, class, open, selected } starting at row first (1 is the top), and the total number of rows.
studio.summary()anyWhat is selected: a table { count, class, name }. class is the one class of every selected part, or Mixed.
studio.fields()anyThe properties of the selection, from the API schema: a list of { name, type, value, mixed, min, max, doc }. type is number, bool, string, vec or color; mixed is true when the selected parts differ.
studio.part_name(id: number)stringThe name of the part with this id, or an empty string when there is none (or the id is 0).
studio.set(property: string, value: any)nothingSets a property on every selected part that has it. Calls made while the mouse button is held join one undo step.
studio.place_settings(kind: string)anyThe settings of the place itself, kind lighting or workspace: a list of { name, type, value } (type is number, bool, string or color). The lighting has clock_time, brightness, the sun's angles and colors; the workspace gravity, the void height, wind and the camera.
studio.set_place_setting(kind: string, name: string, value: any)nothingSets one of the place's settings. A value past its limit is brought back inside. Calls made while the mouse button is held join one undo step. Moving clock_time moves the sun with it.
studio.insert(class: string)numberAdds a Part, Model, PointLight, SpotLight, Sound, Script, LocalScript or ModuleScript at the origin, selects it, and returns its id.
studio.delete()nothingDeletes the selected parts and everything under them.
studio.duplicate()nothingCopies the selected parts, and selects the copies.
studio.copy()nothingRemembers the selected parts, and everything under them, for paste.
studio.cut()nothingRemembers the selected parts and deletes them.
studio.paste()nothingAdds a copy of what copy or cut took, where it was, with new ids, and selects it. With one Model or Folder selected the copy goes inside it.
studio.can_paste()booleanWhether there is something to paste.
studio.undo()nothingUndoes the last step.
studio.redo()nothingRedoes the last undone step.
studio.can_undo()booleanWhether there is a step to undo.
studio.can_redo()booleanWhether there is a step to redo.
studio.panel_visible(id: string)booleanWhether a panel is showing.
studio.toggle_panel(id: string)nothingShows a hidden panel or hides a showing one.
studio.output(first: number, count: number)anyA window onto the output: what plugins printed and the editor reported. Returns two values: a list of up to count lines starting at line first (1 is the oldest), and the total number of lines.
studio.clear_output()nothingEmpties the output.
studio.open_script(id: number)nothingOpens the script held by the part with this id in the editor, or shows its tab. Parts that are not scripts are ignored.
studio.focus()nothingMoves the 3D view to frame the selection, or everything when nothing is selected.
studio.view_project(x: number, y: number, z: number)anyWhere a world point is on the 3D view's screen: two numbers, x and y in points, or nothing when the point is behind the camera. For a tool to place handles.
studio.view_scale(x: number, y: number, z: number)numberHow many studs one point of the screen spans at a world point, so a handle can keep one size on screen at any distance.
studio.view_line(ax: number, ay: number, bx: number, by: number, color: any, width: number?)nothingDraws a line over the 3D view this frame, in screen points. color is rgb(...). Call it from a tool's on_draw.
studio.view_rect(x: number, y: number, w: number, h: number, color: any)nothingDraws a filled rectangle over the 3D view this frame, in screen points. Call it from a tool's on_draw.
studio.selection_center()anyThe middle of the box around the selected parts: three numbers, or nothing when nothing is selected.
studio.selection_parts()anyThe selected parts, and everything under them, as a list of { id, x, y, z (where), sx, sy, sz (how big, in studs), qx, qy, qz, qw (how turned, a quaternion) }.
studio.set_parts(rows: any, label: string?)nothingChanges parts: rows is a list of { id } with any of x y z, sx sy sz or qx qy qz qw (each group whole or left out; a size stays at least 0.05). Calls made while the mouse button is held join one undo step, named label (Edit when missing).
studio.reparent(ids: any, parent: number?)booleanMoves the parts with these ids (a list) under the Model or Folder with id parent, or to the top level when parent is nil. One undo step. False, with the reason in the Output, when the move is not allowed.
studio.context_menu(commands: any)nothingOpens a menu at the pointer listing registered commands by id (a list; a single dash is a separator). Call it on the frame of a right click.
studio.setting(config: any)nothingDeclares a setting: { id, title, type, default, category?, min?, max?, step?, choices?, doc? }. type is number, bool, string, choice (with choices, a list of words) or color (with rgb(...)). The Settings window lists it under its category, and its value is kept between runs.
studio.get_setting(id: string)anyThe value of a setting: the one the person chose, else its default. A color is a vector.
studio.set_setting(id: string, value: any)nothingChooses a value. A number is held to its range; a value of the wrong kind is an error.
studio.reset_setting(id: string)nothingPuts a setting back to its default.
studio.reset_all()nothingPuts every setting, the layout, the key bindings and the changed colors back to their defaults.
studio.settings()anyEvery declared setting, as a list of { id, title, category, type, value, default, min, max, step, choices, doc, changed }.
studio.settings_path()stringWhere the settings file is, or an empty string when settings are kept nowhere.
studio.theme(config: any)nothingRegisters a theme: { id, title, base = 'dark' or 'light', colors = { name = rgb(...) } }. The colors change those of the base; the names are the ones studio.theme_colors lists. metrics = { radius = 3, text_scale = 1 } shapes the interface, icons = "folder name" picks an icon pack, and fonts = { ui = "path.ttf", code = "path.ttf" } sets fonts. The person picks it in Settings.
studio.themes()anyThe themes there are, as a list of { id, title, base }. dark and light are built in.
studio.theme_colors()anyThe colors the theme in force is made of, as a list of { name, value, custom }. custom is true for one the person changed.
studio.set_theme_color(name: string, color: any?)nothingChanges one color of the theme in force, or with no color puts it back.
studio.theme_metrics()anyThe numbers the interface is shaped by, as a list of { name, value, default, min, max, custom }: radius (corner radius, in points), text_scale, spacing (gaps and padding), row_height (rows, tree rows and controls) and bar_height (tab strips, title bar, menu bar, toolbar and status bar). The last four are scales, 1 being as designed. custom is true for one the person changed.
studio.set_theme_metric(name: string, value: number?)nothingChanges one metric (held to its range), or with no value puts it back to the theme's.
studio.look()anyThe fonts and icon pack in force: { icon_pack, ui_font, code_font, custom = { icon_pack = bool, ... } }. An empty text is the built-in one.
studio.set_look(name: string, value: string?)nothingChooses icon_pack (a folder name, see icon_packs), ui_font or code_font (a path to a .ttf or .otf file), or with no value puts it back to the theme's.
studio.reset_look()nothingPuts the metrics, fonts and icon pack back to the theme's.
studio.icon_packs()anyThe icon packs there are, as a list of { id, title, count }; the first, with id empty, is the built-in Silk set. A pack is a folder of .png files named like icons, in the icon_packs folder beside the plugin folder.
studio.export_icons(name: string)numberWrites every built-in icon as a .png named like the icon into a new pack folder (named from name), to edit them as a starting point; returns how many. An icon pack is picked with set_look.
studio.icon_packs_folder()nothingShows the icon packs folder in the file manager, making it first if it is not there.
studio.pick_font(which: string)nothingAsks for a font file and uses it as ui_font or code_font.
studio.save_theme(id: string, title: string?)nothingSaves the theme in force, with the colors, metrics, fonts and icons changed on top of it, as a plugin file that registers it, and chooses it. The changes on top are cleared: they are the theme now.
studio.reset_theme_colors()nothingPuts every changed color back.
studio.move_panel(id: string, dock: string)nothingMoves a panel to 'left', 'right', 'bottom', 'left2' (a second group under the left dock's first group), 'right2', 'bottom2' (beside the bottom dock's first group), 'float' (a panel that is dragged and resized) or 'window' and shows it. The layout is kept between runs.
studio.layouts()anyThe names of the saved layouts, as a list.
studio.save_layout(name: string)nothingKeeps the layout as it is now (where every panel is, which are open, the sizes of the docks and dividers, the floating panels) under a name; the same name again replaces it.
studio.apply_layout(name: string)nothingMakes a saved layout the one in force. A panel it does not mention stays where it is.
studio.delete_layout(name: string)nothingForgets a saved layout.
studio.panels()anyEvery panel, as a list of { id, title, dock, visible }.
studio.reset_layout()nothingPuts every panel and dock size back where it started.
studio.commands()anyEvery command, as a list of { id, title, menu, shortcut, default }.
studio.bind(command: string, shortcut: string?)stringGives a command a shortcut such as 'Ctrl+Shift+K', or with none removes it. Returns the title of the command that already has that shortcut, in which case nothing changed, or an empty string.
studio.reset_keymap()nothingPuts every shortcut back.
studio.reload_plugins()nothingRuns the plugins in the plugin folder again; what they registered is replaced.
studio.plugins()anyEvery plugin, as a list of { name, ok, enabled, builtin, essential, trusted }: the editor's own first, then the files of the plugin folder. ok is false when it failed to run; essential ones (the editor cannot work without them) cannot be switched off.
studio.set_plugin_trusted(name: string, allowed: boolean)nothingLets a plugin use the functions that reach the Studz account (sign in and out, publish, the store, uploads, opening pages) and the computer (files, running the game, adding plugins, quitting), or stops it. Any other plugin gets an error from those functions. Plugins written in the editor are allowed; the editor's own always are. Needs the same permission itself.
studio.set_plugin_enabled(name: string, enabled: boolean)nothingSwitches a plugin off, taking away what it added (panels, commands, tools, settings, themes, handlers and the rest), or on, running it. The choice is kept between runs. Output says why when it cannot be done.
studio.add_plugin()nothingAsks for a .luau plugin file, copies it into the plugin folder and runs it. A file that does not start with --!studio is refused, and the reason is shown in Output.
studio.new_plugin()nothingMakes a new plugin file from a template in the plugin folder and opens it in a tab above the 3D view. Ctrl+S in that tab saves it and runs it.
studio.edit_plugin(name: string)nothingOpens a plugin file of the plugin folder (name as plugins() lists it, ending in .luau) in a tab above the 3D view.
studio.install_script()nothingMakes the selected Script of the place into a plugin: its --!server or --!client line becomes --!studio, and it is saved in the plugin folder and run.
studio.remove_plugin(name: string)nothingDeletes a plugin's file from the plugin folder (name as plugins() lists it). What it added goes away when the editor restarts.
studio.on(event: string, id: string, handler: any)nothingRuns handler when something happens: selection_changed (called with the ids), document_changed (the place changed; it fires every frame during a drag), command_run (called with the command id), play_started and play_stopped. id names the handler; using it again replaces it, so running a plugin twice does not add it twice. What a handler changes does not call it back.
studio.customize(config: any)nothingChanges how something of the editor's own looks, without touching what it does: { command = id, title?, icon?, menu? (empty text takes it out of the menus), toolbar?, separator?, hidden? }, { panel = id, title?, icon? } or { tool = id, title?, icon? }. A hidden command is in no menu or toolbar but its shortcut still works.
studio.explorer_decorator(id: string, decorate: any)nothingHangs something on every Explorer row: decorate(row) is called with { id, depth, name, class, open, selected } and answers nil or a table { icon? = a Silk icon name, suffix? = text shown after the name }. Several decorators combine; a mistake in one is ignored.
studio.explorer_decorators()anyThe functions explorer_decorator registered. The Explorer calls them; a plugin rarely needs this.
studio.properties_section(config: any)nothingAdds a collapsible section to the Properties panel when something is selected: { id, title, draw = function() end }, drawn with the ui functions. A mistake in it is shown inside the section and does not affect the rest.
studio.property_sections()anyThe sections properties_section registered, as { id, title, draw }. The Properties panel draws them.
studio.context_item(menu: string, command: string)nothingAdds a command (by id) to the right-click menu of the explorer or the viewport.
studio.context_items(menu: string)anyThe command ids context_item added to a menu. The built-in menus use them.
studio.status_item(id: string, text: any)nothingShows a text in the status bar: text() is called each frame and answers a string (or nil for nothing). One that fails is taken out and reported.
studio.open_plugins_folder()nothingShows the plugin folder in the file manager, making it first if it is not there.
studio.toggle_theme()nothingSwitches between the light and the dark theme.
studio.new_place()nothingStarts an empty place, asking first what to do with unsaved changes.
studio.open()nothingAsks for a place file and opens it, asking first what to do with unsaved changes.
studio.save()nothingSaves the place to its file, or asks where when it has none.
studio.save_as()nothingAsks where to save the place and saves it there.
studio.play()nothingRuns the place in a game window with a local server. Output shows what the server prints.
studio.stop_play()nothingCloses the game windows and the local server.
studio.playing()booleanWhether game windows are running.
studio.cloud()anyThe Studz account: { state (unavailable, verifying, signed_out, waiting, signed_in or unreachable), notice, name, role, can_publish, busy, opening, publishing, games_loading, games_error, games = list of { id, name, access, version, parts, visits }, link = { id, name, version, access, owner, shared, clan } for the game the place came from (shared: the account may edit it but not publish it or change its settings, because it was invited to it or holds a clan role that only edits; clan: the name of the clan the game belongs to, or an empty string), team = { ready, reset, peers = list of { name, selection = list of part ids, editing = the id of the script they have open in front of them, or 0 } (a script another editor has open is read only for the person who opens it after them) } for editing the game together with others (reset: the editor missed too much and the game has to be opened again), autosave, autosave_error }.
studio.sign_in()nothingOpens the browser to sign in to Studz. The editor never sees the password.
studio.cancel_sign_in()nothingStops waiting for the browser.
studio.retry_sign_in()nothingChecks a saved sign-in again after the site could not be reached.
studio.sign_out()nothingSigns out of Studz.
studio.refresh_games()nothingAsks the site for the account's games again; cloud().games fills when they arrive.
studio.open_game(id: number)nothingOpens a game from the account in place of this place, after asking about unsaved changes.
studio.publish(name: string?, note: string?)nothingPublishes the place as the next version of the game it came from, or, with a name, as a new game. The note describes the version.
studio.set_autosave(on: boolean)nothingTurns on or off saving the place to its game every 15 seconds.
studio.library(kind: string)anyWhat the account uploaded, for kind sound: { items = list of { id, name, detail }, loading, error }. Asking starts loading it the first time.
studio.refresh_library(kind: string)nothingLoads the account's uploads of that kind again.
studio.insert_asset(kind: string, id: number)nothingAdds an uploaded sound to the place, on the selected part (or in the Workspace). It becomes the selection.
studio.store(kind: string, query: string?, page: number?)anyThe Creator Store, what everyone shared, for kind model or audio: { items = list of { id, name, creator, uses, detail }, loading, error, more }. Asking with a new kind, query or page starts the search; the results fill in when they arrive.
studio.store_insert(kind: string, id: number)nothingTakes an item from the current store results: a sound goes on the selected part, a model is fetched and placed in the Workspace.
studio.publish_model(name: string, description: string?, tags: string?, listed: boolean?)nothingSends the selected parts, with everything under them, to the Creator Store as a model. listed (default true) lets everyone find it; otherwise only the account can. Models take at most 2000 parts and 2 MB.
studio.profile(target: string, on: boolean)nothingTurns the script profiler on or off for target editor (the editor's own plugins) or server (the game server Play started).
studio.profile_reset(target: string)nothingForgets what the profiler has found for that target.
studio.profile_report(target: string)anyWhat the profiler found, or nil for a server when no game is running: { running, elapsed, busy, slices, longest, memory, scripts = list of { name, ms }, functions = list of { script, line, func, ms, samples } } in milliseconds, hottest first. The server also reports tick_avg, tick_max, ticks and players for the last second.
studio.frame_stats()anyHow long the parts of the editor's frame take: a list of { name, ms, peak }, averaged over recent frames. ms is the average, peak a slowly falling maximum.
studio.run_console(target: string, line: string)nothingRuns a line of Dialect in the editor's plugins or in the game server's scripts and prints the result in Output. A line that is an expression prints its value.
studio.open_site(path: string)nothingOpens a page of the Studz site (such as /develop) in the browser.
studio.quit()nothingCloses the editor.

ui

Interface widgets, called while a panel draws. Each is drawn where it is called and answers at once.

FunctionReturnsDescription
ui.label(text: string, color: any?)nothingText. color is a Color (rgb(...)) or nil for the normal text color.
ui.button(text: string)booleanA button. True on the frame it is clicked.
ui.toggle(text: string, value: boolean)anyA check box. Returns two values: whether it changed, and the new value.
ui.text_edit(key: string, value: string, hint: string?)anyA one-line text field. key names it; hint shows dimmed while it is empty. Returns three values: changed, submitted (Enter or clicking away), and the text. While it has the keyboard it keeps its own draft, so pass the stored value each frame.
ui.drag(value: number, speed: number, min: number, max: number, label: string?)anyA number field: drag sideways or click to type. label (X, Y, Z, R, G or B) is shown inside it in the axis color. Returns two values: whether it changed, and the new value.
ui.header(text: string, open: boolean, icon: string?)booleanA collapsible section header with an optional Silk icon. True on the frame it is clicked; flip open then.
ui.icon(name: string)nothingA Silk icon in the flow, for the start of a row.
ui.placeholder(icon: string, title: string, hint: string)nothingWhat to show where there is nothing yet: an icon, a line saying so and a hint under it, centered in what is left of the panel.
ui.split(width: number, left: any, right: any)nothingSplits what is left of the panel into a column of the given width and a column filling the rest, and draws left() in one and right() in the other.
ui.choice(options: any, selected: number)anyA row of buttons, one pressed. options is a list of words and selected a 1-based position. Returns two values: whether it changed, and the new position.
ui.swatch(color: any)nothingA small square of a color.
ui.progress(fraction: number, text: string?)nothingA flat bar filled to fraction (0 to 1) of its width with text over it: a share of a total, such as the time a function takes.
ui.icon_button(icon: string, tip: string, enabled: boolean?)booleanA small button showing a Silk icon. True on the frame it is clicked. A button that is not enabled is faded and never clicked.
ui.capture_shortcut()anyThe shortcut pressed this frame, written such as 'Ctrl+Shift+K', or nil. For a panel that lets the person pick one.
ui.separator()nothingA thin line.
ui.space(height: number)nothingEmpty space.
ui.row(content: any)nothingLays out what content draws left to right.
ui.field(label: string, content: any, label_width: number?)nothingA label on the left and what content draws filling the rest of the line. label_width sets how wide the label column is.
ui.cells(count: number, content: any)nothingSplits the line into count equal cells and calls content(i) for each, i from 1.
ui.scroll(key: string, content: any)nothingA scrolling area that fills what is left of the panel; content draws inside it.
ui.list(key: string, count: number, content: any)nothingA scrolling list of count rows of equal height that draws only the rows in view: content(first, last) is called with the 1-based range to draw, one tree_row each.
ui.tree_row(depth: number, text: string, open: boolean?, selected: boolean, icon: string?)anyOne row of a tree. open is nil for a leaf; icon is a Silk icon name or nil. Returns five values: pressed, arrow_clicked, double, right (the right button went down on it) and over (the pointer is on it, even while a drag started elsewhere).
ui.canvas(height: number, draw: any)nothingA full-width rectangle of the panel, height points tall, for plots and the like. draw(c) is called with c = { w, h (its size), x, y (the pointer from its top left; missing when the pointer is neither over it nor dragging out of it), hovered, pressed (the left button went down on it this frame), down (held, after going down on it), released, double }. Inside draw, the draw_* functions paint in points from the top left, clipped to the rectangle.
ui.draw_line(ax: number, ay: number, bx: number, by: number, color: any, width: number?)nothingInside a canvas: a line from one point to another. color is rgb(...).
ui.draw_rect(x: number, y: number, w: number, h: number, color: any)nothingInside a canvas: a filled rectangle.
ui.draw_circle(x: number, y: number, radius: number, color: any)nothingInside a canvas: a filled circle.
ui.draw_text(x: number, y: number, text: string, color: any?)nothingInside a canvas: small text whose left edge is x and whose middle is y, in the dim text color when color is missing.
ui.dropping(on: boolean)nothingWhile on (call it each frame), the tree row under the pointer is outlined as a place something would drop.
ui.guard(content: any)anyRuns content() and catches a mistake in it: returns true, or false and the message, after closing whatever layouts it left open. For drawing code that may fail without taking its panel down.
ui.right_clicked()booleanTrue on the frame the right button went down over the panel's body, wherever in it. A row that was right-clicked reports it too, so keep a flag if the empty space has a menu of its own.
ui.mouse_down()booleanWhether the left mouse button is held.
ui.mouse_released()booleanWhether the left mouse button went up this frame.
ui.modifier(name: string)booleanWhether a modifier key is held: 'ctrl', 'shift' or 'alt'.