Editor plugin reference
studio
The editor: register panels, commands and tools, and read and change the place.
| Function | Returns | Description |
|---|---|---|
studio.panel(config: any) | nothing | Registers 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) | nothing | Registers 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) | nothing | Registers 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() | string | The id of the active tool. |
studio.set_tool(id: string) | nothing | Makes a registered tool the active one. |
studio.selection() | any | The ids of the selected parts, as a list. |
studio.select(ids: any) | nothing | Selects the parts with these ids (a list). |
studio.tree(open: any, first: number, count: number, filter: string?) | any | A 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() | any | What is selected: a table { count, class, name }. class is the one class of every selected part, or Mixed. |
studio.fields() | any | The 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) | string | The 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) | nothing | Sets 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) | any | The 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) | nothing | Sets 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) | number | Adds a Part, Model, PointLight, SpotLight, Sound, Script, LocalScript or ModuleScript at the origin, selects it, and returns its id. |
studio.delete() | nothing | Deletes the selected parts and everything under them. |
studio.duplicate() | nothing | Copies the selected parts, and selects the copies. |
studio.copy() | nothing | Remembers the selected parts, and everything under them, for paste. |
studio.cut() | nothing | Remembers the selected parts and deletes them. |
studio.paste() | nothing | Adds 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() | boolean | Whether there is something to paste. |
studio.undo() | nothing | Undoes the last step. |
studio.redo() | nothing | Redoes the last undone step. |
studio.can_undo() | boolean | Whether there is a step to undo. |
studio.can_redo() | boolean | Whether there is a step to redo. |
studio.panel_visible(id: string) | boolean | Whether a panel is showing. |
studio.toggle_panel(id: string) | nothing | Shows a hidden panel or hides a showing one. |
studio.output(first: number, count: number) | any | A 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() | nothing | Empties the output. |
studio.open_script(id: number) | nothing | Opens 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() | nothing | Moves the 3D view to frame the selection, or everything when nothing is selected. |
studio.view_project(x: number, y: number, z: number) | any | Where 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) | number | How 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?) | nothing | Draws 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) | nothing | Draws a filled rectangle over the 3D view this frame, in screen points. Call it from a tool's on_draw. |
studio.selection_center() | any | The middle of the box around the selected parts: three numbers, or nothing when nothing is selected. |
studio.selection_parts() | any | The 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?) | nothing | Changes 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?) | boolean | Moves 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) | nothing | Opens 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) | nothing | Declares 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) | any | The value of a setting: the one the person chose, else its default. A color is a vector. |
studio.set_setting(id: string, value: any) | nothing | Chooses a value. A number is held to its range; a value of the wrong kind is an error. |
studio.reset_setting(id: string) | nothing | Puts a setting back to its default. |
studio.reset_all() | nothing | Puts every setting, the layout, the key bindings and the changed colors back to their defaults. |
studio.settings() | any | Every declared setting, as a list of { id, title, category, type, value, default, min, max, step, choices, doc, changed }. |
studio.settings_path() | string | Where the settings file is, or an empty string when settings are kept nowhere. |
studio.theme(config: any) | nothing | Registers 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() | any | The themes there are, as a list of { id, title, base }. dark and light are built in. |
studio.theme_colors() | any | The 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?) | nothing | Changes one color of the theme in force, or with no color puts it back. |
studio.theme_metrics() | any | The 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?) | nothing | Changes one metric (held to its range), or with no value puts it back to the theme's. |
studio.look() | any | The 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?) | nothing | Chooses 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() | nothing | Puts the metrics, fonts and icon pack back to the theme's. |
studio.icon_packs() | any | The 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) | number | Writes 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() | nothing | Shows the icon packs folder in the file manager, making it first if it is not there. |
studio.pick_font(which: string) | nothing | Asks for a font file and uses it as ui_font or code_font. |
studio.save_theme(id: string, title: string?) | nothing | Saves 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() | nothing | Puts every changed color back. |
studio.move_panel(id: string, dock: string) | nothing | Moves 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() | any | The names of the saved layouts, as a list. |
studio.save_layout(name: string) | nothing | Keeps 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) | nothing | Makes a saved layout the one in force. A panel it does not mention stays where it is. |
studio.delete_layout(name: string) | nothing | Forgets a saved layout. |
studio.panels() | any | Every panel, as a list of { id, title, dock, visible }. |
studio.reset_layout() | nothing | Puts every panel and dock size back where it started. |
studio.commands() | any | Every command, as a list of { id, title, menu, shortcut, default }. |
studio.bind(command: string, shortcut: string?) | string | Gives 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() | nothing | Puts every shortcut back. |
studio.reload_plugins() | nothing | Runs the plugins in the plugin folder again; what they registered is replaced. |
studio.plugins() | any | Every 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) | nothing | Lets 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) | nothing | Switches 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() | nothing | Asks 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() | nothing | Makes 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) | nothing | Opens 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() | nothing | Makes 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) | nothing | Deletes 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) | nothing | Runs 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) | nothing | Changes 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) | nothing | Hangs 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() | any | The functions explorer_decorator registered. The Explorer calls them; a plugin rarely needs this. |
studio.properties_section(config: any) | nothing | Adds 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() | any | The sections properties_section registered, as { id, title, draw }. The Properties panel draws them. |
studio.context_item(menu: string, command: string) | nothing | Adds a command (by id) to the right-click menu of the explorer or the viewport. |
studio.context_items(menu: string) | any | The command ids context_item added to a menu. The built-in menus use them. |
studio.status_item(id: string, text: any) | nothing | Shows 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() | nothing | Shows the plugin folder in the file manager, making it first if it is not there. |
studio.toggle_theme() | nothing | Switches between the light and the dark theme. |
studio.new_place() | nothing | Starts an empty place, asking first what to do with unsaved changes. |
studio.open() | nothing | Asks for a place file and opens it, asking first what to do with unsaved changes. |
studio.save() | nothing | Saves the place to its file, or asks where when it has none. |
studio.save_as() | nothing | Asks where to save the place and saves it there. |
studio.play() | nothing | Runs the place in a game window with a local server. Output shows what the server prints. |
studio.stop_play() | nothing | Closes the game windows and the local server. |
studio.playing() | boolean | Whether game windows are running. |
studio.cloud() | any | The 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() | nothing | Opens the browser to sign in to Studz. The editor never sees the password. |
studio.cancel_sign_in() | nothing | Stops waiting for the browser. |
studio.retry_sign_in() | nothing | Checks a saved sign-in again after the site could not be reached. |
studio.sign_out() | nothing | Signs out of Studz. |
studio.refresh_games() | nothing | Asks the site for the account's games again; cloud().games fills when they arrive. |
studio.open_game(id: number) | nothing | Opens a game from the account in place of this place, after asking about unsaved changes. |
studio.publish(name: string?, note: string?) | nothing | Publishes 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) | nothing | Turns on or off saving the place to its game every 15 seconds. |
studio.library(kind: string) | any | What 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) | nothing | Loads the account's uploads of that kind again. |
studio.insert_asset(kind: string, id: number) | nothing | Adds 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?) | any | The 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) | nothing | Takes 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?) | nothing | Sends 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) | nothing | Turns 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) | nothing | Forgets what the profiler has found for that target. |
studio.profile_report(target: string) | any | What 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() | any | How 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) | nothing | Runs 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) | nothing | Opens a page of the Studz site (such as /develop) in the browser. |
studio.quit() | nothing | Closes the editor. |
ui
Interface widgets, called while a panel draws. Each is drawn where it is called and answers at once.
| Function | Returns | Description |
|---|---|---|
ui.label(text: string, color: any?) | nothing | Text. color is a Color (rgb(...)) or nil for the normal text color. |
ui.button(text: string) | boolean | A button. True on the frame it is clicked. |
ui.toggle(text: string, value: boolean) | any | A check box. Returns two values: whether it changed, and the new value. |
ui.text_edit(key: string, value: string, hint: string?) | any | A 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?) | any | A 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?) | boolean | A collapsible section header with an optional Silk icon. True on the frame it is clicked; flip open then. |
ui.icon(name: string) | nothing | A Silk icon in the flow, for the start of a row. |
ui.placeholder(icon: string, title: string, hint: string) | nothing | What 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) | nothing | Splits 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) | any | A 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) | nothing | A small square of a color. |
ui.progress(fraction: number, text: string?) | nothing | A 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?) | boolean | A 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() | any | The shortcut pressed this frame, written such as 'Ctrl+Shift+K', or nil. For a panel that lets the person pick one. |
ui.separator() | nothing | A thin line. |
ui.space(height: number) | nothing | Empty space. |
ui.row(content: any) | nothing | Lays out what content draws left to right. |
ui.field(label: string, content: any, label_width: number?) | nothing | A 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) | nothing | Splits the line into count equal cells and calls content(i) for each, i from 1. |
ui.scroll(key: string, content: any) | nothing | A scrolling area that fills what is left of the panel; content draws inside it. |
ui.list(key: string, count: number, content: any) | nothing | A 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?) | any | One 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) | nothing | A 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?) | nothing | Inside 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) | nothing | Inside a canvas: a filled rectangle. |
ui.draw_circle(x: number, y: number, radius: number, color: any) | nothing | Inside a canvas: a filled circle. |
ui.draw_text(x: number, y: number, text: string, color: any?) | nothing | Inside 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) | nothing | While on (call it each frame), the tree row under the pointer is outlined as a place something would drop. |
ui.guard(content: any) | any | Runs 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() | boolean | True 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() | boolean | Whether the left mouse button is held. |
ui.mouse_released() | boolean | Whether the left mouse button went up this frame. |
ui.modifier(name: string) | boolean | Whether a modifier key is held: 'ctrl', 'shift' or 'alt'. |
