### Example — writing and saving with error handling Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Gets the current setup, sets a value, and saves it if the config is saveable. ```lua local setup = ac.INIConfig.currentSetup() if setup then setup:set('ENGINE', 'POWER', 100) setup:setAndSave('ENGINE', 'POWER', 120) -- persists if saveable end ``` -------------------------------- ### Basic storage usage example Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-storage.md Basic usage example. Shows plain string storage and typed storage with a number default, including setting and getting values. ```lua -- Plain string storage ac.storage['myKey'] = 'hello' print(ac.storage['myKey']) -- Typed value local bestLap = ac.storage('bestLap', 0) bestLap:set(92.5) print(bestLap:get()) ``` -------------------------------- ### Example: defining and using a class Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/class.md Shows how to define a class with class(), add a constructor and methods, and use isInstanceOf. The example prints 5 and true. ```lua local Point = class('Point') -- class declaration function Point:initialize(x, y) -- constructor self.x = x self.y = y end function Point:length() -- method return math.sqrt(self.x * self.x + self.y * self.y) end local p = Point(3, 4) print(p:length()) -- 5 print(Point.isInstanceOf(p)) -- true ``` -------------------------------- ### Example — reading user script settings Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Reads the script's settings.ini, gets a volume value, and maps a whole section with defaults. ```lua local settings = ac.INIConfig.scriptSettings() local volume = settings:get('AUDIO', 'VOLUME', 0.5) -- map a whole section with defaults local uiCfg = settings:mapSection('UI', { accent = rgb(1, 1, 1), enabled = true }) ``` -------------------------------- ### Configurable script example Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/configuration.md Complete example of a configurable script that reads user settings from settings.ini and uses them in the update loop. Shows how to retrieve typed values with defaults and apply them to UI styling. ```lua -- settings.ini [DISPLAY] RefreshRate=30 / Accent=(0.2,0.6,1.0) local settings = ac.INIConfig.scriptSettings() local refreshRate = settings:get('DISPLAY', 'RefreshRate', 30) local accent = settings:get('DISPLAY', 'Accent', rgb(0.2, 0.6, 1.0)) function script.update(dt) ui.pushStyleColor(ui.StyleColor.Text, accent) -- ... end ``` -------------------------------- ### Storage group usage example Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-storage.md Example of using a storage group. Creates a group with defaults and a prefix, then reads and writes fields. Unknown keys raise an error. ```lua local s = ac.storage({ foo = 0, bar = 'x' }, 'myPrefix') print(s.foo) -- reads s.bar = 'writes' -- writes ``` -------------------------------- ### ac.INIConfig.currentSetup() Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Loads the current setup configuration. The returned config is saveable and should be paired with ac.onSetupFile(). ```APIDOC ## ac.INIConfig.currentSetup() ### Description Loads the current setup configuration. The returned config is saveable and should be paired with ac.onSetupFile(). ### Returns - **ac.INIConfig** - The current setup configuration. Saveable. ``` -------------------------------- ### string.startsWith Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/string.md Checks if the string starts with the given substring, optionally starting at a specified offset. ```APIDOC ## string.startsWith ### Description Checks if the string starts with the given substring, optionally starting at a specified offset. ### Method string.startsWith ### Signature ```lua function string.startsWith(self, another, offset) end ``` ### Parameters - **self** (string) - Required - The string to check. - **another** (string) - Required - The substring to look for. - **offset** (integer?) - Optional - Default value: `0`. The position to start checking from. ### Returns - **boolean** - True if the string starts with the given substring, false otherwise. ``` -------------------------------- ### Example: drawing an image from an atlas Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-display.md Example of drawing an image from an atlas. It uses uvStart and uvEnd to select a 0.25 by 0.25 region of the texture. ```lua display.image{ image = 'textures/icons.dds', pos = vec2(0, 0), size = vec2(32, 32), uvStart = vec2(0, 0), uvEnd = vec2(0.25, 0.25) } ``` -------------------------------- ### Example — using enums Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-enums.md Demonstrates usage of ac.WeatherType, render.BlendMode, and ui.StyleVar enums in Lua code. ```lua local w = ac.WeatherType.Rain print(ui.weatherIcon(w)) -- icon glyph for rain render.fullscreenPass({ blendMode = render.BlendMode.BlendAdd, ... }) ui.pushStyleVar(ui.StyleVar.Alpha, 0.5) ``` -------------------------------- ### Storage group with error handling example Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-storage.md Example of a storage group with error handling. Creates a group with defaults and a prefix, updates a field in script.update, checks key existence with ac.storageHasKey, and catches errors from unknown keys using pcall. ```lua local settings = ac.storage({ volume = 0.8, color = rgb(1, 0, 0) }, 'app') function script.update(dt) settings.volume = math.clamp(settings.volume + dt * 0.1, 0, 1) end -- Unknown key raises an error; guard with ac.storageHasKey if ac.storageHasKey(settings, 'volume') then print('volume =', settings.volume) end local ok, err = pcall(function () return settings.nope end) if not ok then print('Missing key:', err) end ``` -------------------------------- ### Example — finding and moving meshes Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-scene.md Demonstrates how to find meshes with a specific tag, store their current transform, and move them. ```APIDOC ## Example — finding and moving meshes ### Description Shows how to find meshes with a specific tag, store their current transform, and move them. ### Code ```lua local needles = ac.findMeshes('needle:yes') needles:storeCurrentTransform() needles:setPosition(vec3(0, 1, 0)) ``` ``` -------------------------------- ### Example: drawing a dynamic texture Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-display.md Example of drawing a dynamic texture inside a scriptable display's update callback. It combines display.rect, display.text, and display.horizontalBar to show a red rectangle, RPM text, and a progress bar. ```lua -- inside a scriptable display's update callback display.rect{ pos = vec2(10, 10), size = vec2(100, 50), color = rgbm(1, 0, 0, 0.8) } display.text{ text = 'RPM: ' .. math.floor(car.rpm), pos = vec2(20, 20), letter = vec2(12, 24), color = rgbm.colors.white } display.horizontalBar{ pos = vec2(20, 60), size = vec2(180, 10), total = 10, active = 7 } ``` -------------------------------- ### Example — error handling Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-physics.md Demonstrates using pcall to catch errors when creating a rigid body, printing the error message if creation fails. ```lua local ok, err = pcall(physics.RigidBody, 'missing.kn5', 10) if not ok then print('RigidBody creation failed:', err) -- e.g. "Not allowed" end ``` -------------------------------- ### Example - finding and moving meshes Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-scene.md Shows how to find meshes with the 'needle:yes' tag, store their current transform, and move them to a new position. ```lua local needles = ac.findMeshes('needle:yes') needles:storeCurrentTransform() needles:setPosition(vec3(0, 1, 0)) ``` -------------------------------- ### Example — reading a track config Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Loads car data from 'tyres.ini' and reads the 'RIM_RADIUS' value from the 'FRONT' section, printing it. ```lua local tyres = ac.INIConfig.carData(0, 'tyres.ini') local rim = tyres:get('FRONT', 'RIM_RADIUS', 0.2) print('Front rim radius:', rim) ``` -------------------------------- ### Error handling with rgb.new Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/colors.md Error handling example showing how rgb.new rejects unsupported argument shapes, using pcall to catch the error. ```lua local ok, err = pcall(function() return rgb.new({}) -- empty table → cannot determine components end) if not ok then print('Failed to build color:', err) end ``` -------------------------------- ### Example — creating a rigid body Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-physics.md Shows how to create a rigid body from a KN5 file with a collider filter, set it semi-dynamic, apply a transformation, and continuously update a loaded model's transformation from the physics body. ```lua local physics = physics.RigidBody({ filename = 'cone.kn5', filter = 'collider', debug = true, transform = true }, 10) physics:setSemiDynamic(true, true) physics:setTransformation(mat4x4.translation(vec3(-2679.85, -41.06, -202.68))) setInterval(function () loadedModel:setTransformationFrom(physics) end) ``` -------------------------------- ### Minimal app script with ui.toolWindow Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/entry-points.md Minimal app script that creates a tool window and displays the speed of car 0 in km/h. Use as a starting point for a simple UI app. ```lua function script.update(dt) ui.toolWindow('MyApp', vec2(10, 10), vec2(150, 60), false, true, function () ui.text('Speed: ' .. math.floor(ac.getCar(0).speedKmh)) end) end ``` -------------------------------- ### Error handling with quat.new Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/quat.md Demonstrates error handling when passing an incompatible table type to quat.new. The example uses pcall to catch the error and prints the failure message. ```lua local ok, err = pcall(quat.new, { x = 1, y = 2, z = 3 }) -- table without 4 numbers if not ok then print('Failed:', err) end ``` -------------------------------- ### CSP-style filter matching with string.cspmatch Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/string.md Shows how to use string.cspmatch with a simple wildcard filter and a complex filter using '{…}' syntax with '&' and '!' operators. The examples print 'matches' when the filter matches. ```lua if string.cspmatch('myScript_v2.lua', 'myScript_v?.lua') then print('matches') end if string.cspmatch('anything', '{ ?matching & ! ?not }') then print('complex filter matched') end ``` -------------------------------- ### web.get function signature Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-web.md Sends a GET request. The callback receives an error string and a WebResponse. The headers parameter is optional. ```lua ---@param url string ---@param headers web.Headers? ---@param callback fun(err: string, response: WebResponse) ---@overload fun(url: string, callback: fun(err: string, response: WebResponse)) function web.get(url, headers, callback) end ``` -------------------------------- ### Example — geometric collider + collision callback Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-physics.md Creates a rigid body with a box collider and attaches a collision callback that prints whether the collision was with a car or something else. ```lua local body = physics.RigidBody({ physics.Collider.Box(vec3(1, 1, 1), vec3(0, 0.5, 0)) }, 5) body:onCollision(function (carIndex) if carIndex then print('Hit car', carIndex) else print('Hit something else') end end) ``` -------------------------------- ### Iterating cars with ac.debug Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-state.md Example iterating over all cars and displaying each driver name and car name using ac.debug. ```lua for i, c in ac.iterateCars() do ac.debug('car' .. i, c.driverName .. ' | ' .. c.name) end ``` -------------------------------- ### Basic use of JSON.stringify and JSON.parse Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/json.md Example showing how to serialize a Lua table to JSON and parse it back. The output of print(json) is shown in a comment. ```lua local payload = { name = 'player', score = 100, tags = { 'a', 'b' } } local json = JSON.stringify(payload) print(json) -- {"name":"player","score":100,"tags":["a","b"]} local decoded = JSON.parse(json) print(decoded.name, decoded.score) ``` -------------------------------- ### Regex helpers with string.regfind and string.reggsub Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/string.md Demonstrates using string.regfind to locate a pattern and string.reggsub to replace all occurrences of a pattern. The example shows that regfind returns the position of the match, and reggsub returns the modified string. ```lua local pos = string.regfind('Order #12345 ready', '#%d+') if pos then print('Found at', pos) end local replaced = string.reggsub('hello 42 world', '%d+', 'NUM') -- 'hello NUM world' print(replaced) ``` -------------------------------- ### Load file-based event with error handling using ac.AudioEvent.fromFile Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-audio.md Loads an audio event from a file and checks validity before starting it. Prints an error if loading fails; a commented dispose call shows cleanup after use. ```lua local beep = ac.AudioEvent.fromFile({ filename = 'content/audio/beep.ogg', loop = false }, false) if not beep:isValid() then print('Audio event failed to load') else beep:start() end -- clean up when done -- beep:dispose() ``` -------------------------------- ### Splitting and parsing strings with string.split and string.numbers Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/string.md Shows how to split a string by a delimiter and extract numbers from a string. The examples demonstrate that string.split returns a table of substrings and string.numbers returns a list of numbers. ```lua local parts = string.split('a,b,c', ',') -- {'a','b','c'} local nums = { string.numbers('1 2 3.5') } -- {1, 2, 3.5} local first = string.split('x=1|y=2', '|')[1] -- 'x=1' ``` -------------------------------- ### Using stringify instead of JSON for Lua data Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/json.md Example showing how to use stringify and stringify.parse to store and reload Lua-native data, preserving vectors. The output of restored.pos:table() is shown in a comment. ```lua local data = { pos = vec3(1, 2, 3), label = 'marker' } local s = stringify(data) -- Lua-syntax, preserves vectors local restored = stringify.parse(s) print(restored.pos:table()) -- 1, 2, 3 ``` -------------------------------- ### Optional-value sentinels Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Defines sentinel values to pass as defaultValue to :get() or :mapSection() to get a typed nil-able result. ```lua ac.INIConfig.OptionalBoolean = {} -- boolean or nil ac.INIConfig.OptionalNumber = {} -- number or nil ac.INIConfig.OptionalString = {} -- string or nil ac.INIConfig.OptionalList = {} -- list of original values or nil ``` -------------------------------- ### ac.INIConfig:get(section, key, defaultValue, offset) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Reads a value from the INI configuration. The defaultValue determines the result type, or you can pass an Optional* sentinel to get a typed nil-able result. ```APIDOC ## ac.INIConfig:get(section, key, defaultValue, offset) ### Description Reads a value from the INI configuration. The defaultValue determines the result type, or you can pass an Optional* sentinel to get a typed nil-able result. ### Parameters - **section** (string) - Required - The section name. - **key** (string) - Required - The key name. - **defaultValue** (any) - Required - Determines result type (or an Optional* sentinel). - **offset** (integer?) - Optional - Offset for indexed values. ### Returns - **any** - The value read from the configuration. ``` -------------------------------- ### GET request with error handling Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-web.md Performs a GET request with error handling. The callback receives an error and a response object. If err is truthy, the request failed; otherwise response.status and response.body are available. ```lua web.get('https://api.example.com/version', function (err, response) if err then print('Request failed:', err) return end print('Status:', response.status) print('Body:', response.body) end) ``` -------------------------------- ### ui.MediaPlayer supported and constructor Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Checks support and creates a media player (video/audio) usable as an image source and audio emitter. ```lua function ui.MediaPlayer.supported() end function ui.MediaPlayer(source, audioParams) end ``` -------------------------------- ### web.get Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-web.md Sends a GET request to the specified URL. ```APIDOC ## `web.get(url, headers, callback)` ### Description Sends a GET request. ### Parameters - **url** (string) - Required - The URL to request. - **headers** (web.Headers?) - Optional - Request headers. - **callback** (fun(err: string, response: WebResponse)) - Required - Callback invoked with an error string and the response. ### Overloads - `web.get(url, callback)` - Callback as second argument. ### Request Example ```lua web.get("https://example.com", function(err, response) -- handle response end) ``` ### Response - **err** (string) - Error message, empty if successful. - **response** (WebResponse) - The response object. ``` -------------------------------- ### Windows / containers (transparentWindow, toolWindow, etc.) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Functions for creating windows, tooltips, columns, child windows, tree nodes, tabs, and tab items. ```APIDOC ## ui.transparentWindow(id, pos, size, noPadding, inputs, content) ### Description Creates a transparent floating window. The content callback is executed inside the window. ### Parameters - **id** (string) - Unique window ID. - **pos** (vec2) - Window position. - **size** (vec2) - Window size. - **noPadding** (boolean?) - Default `false`. - **inputs** (boolean?) - Enable input handling. Default `false`. - **content** (fun():T?) - Content callback. ### Overloads - `ui.transparentWindow(id, pos, size, content)` - `ui.transparentWindow(id, pos, size, noPadding, content)` ### Return - T? - Return value of the content callback. --- ## ui.toolWindow(id, pos, size, noPadding, inputs, content) ### Description Creates a tool-style window. ### Parameters - Same as `ui.transparentWindow`, but with tool window styling. --- ## ui.tooltip(padding, content) ### Description Displays a tooltip. The content callback is executed inside. ### Parameters - **padding** (vec2?) - Default `vec2(20, 8)` - **content** (fun():T?) - Content to display. ### Overload - `ui.tooltip(content)` --- ## ui.columns(columns, border, id) ### Description Divides the layout into columns. ### Parameters - **columns** (integer?) - Default 1 - **border** (boolean?) - Default `true` - **id** (string|nil) - Optional ID. ### Overload - `ui.columns(columns, flags, id)` --- ## ui.childWindow(id, size, border, flags, content) ### Description Creates a child window inside the current window. ### Parameters - **id** (string) - Unique child window ID. - **size** (vec2) - Size of the child window. - **border** (boolean) - Draw a border. - **flags** (integer?) - Window flags. - **content** (fun()) - Content callback. --- ## ui.treeNode(label, flags, content) ### Description Creates a collapsible tree node. ### Parameters - **label** (string) - Node label. - **flags** (integer?) - Flags. - **content** (fun()) - Content of the node. --- ## ui.tabBar(id, flags, content) ### Description Creates a tab bar. ### Parameters - **id** (string) - Tab bar ID. - **flags** (integer?) - Flags. - **content** (fun()) - Content with tab items. --- ## ui.tabItem(label, flags, content, opened) ### Description Creates a tab item inside a tab bar. ### Parameters - **label** (string) - Tab label. - **flags** (integer?) - Flags. - **content** (fun()) - Tab content. - **opened** (refbool?) - Optional reference to boolean status. ``` -------------------------------- ### Windows and containers helper function signatures Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Functions for creating windows, tooltips, columns, child windows, tree nodes, tab bars, and tab items. Includes overloads and default values. ```lua ---@param id string @Unique window ID. ---@param pos vec2 ---@param size vec2 ---@param noPadding boolean? @Default `false`. ---@param inputs boolean? @Enable inputs. Default `false`. ---@param content fun(): T? ---@return T ---@overload fun(id, pos, size, content) ---@overload fun(id, pos, size, noPadding, content) function ui.transparentWindow(id, pos, size, noPadding, inputs, content) end function ui.toolWindow(id, pos, size, noPadding, inputs, content) end ---@param padding vec2? @Default `vec2(20, 8)`. ---@param content fun(): T? ---@overload fun(content) function ui.tooltip(padding, content) end ---@param columns integer? @Default 1. ---@param border boolean? @Default `true`. ---@param id string|nil ---@overload fun(columns, flags, id) function ui.columns(columns, border, id) end function ui.childWindow(id, size, border, flags, content) end function ui.treeNode(label, flags, content) end function ui.tabBar(id, flags, content) end function ui.tabItem(label, flags, content, opened) end -- opened: refbool? ``` -------------------------------- ### ac.emptySceneReference Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-scene.md Returns an empty scene reference. This is a nil-safe function that can be used as a starting point for chained operations. ```APIDOC ## ac.emptySceneReference() ### Description Returns an empty scene reference. This is a nil-safe function that can be used as a starting point for chained operations. ### Method Function ### Endpoint ac.emptySceneReference() ### Parameters None. ### Returns - **ac.SceneReference** - An empty scene reference. ``` -------------------------------- ### Iterating cars with ac.iterateCars Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-state.md Example loop that iterates over all cars and prints each car's index and position. ```lua for i, c in ac.iterateCars() do print(i, c.position) end ``` -------------------------------- ### _classPool:recycled() Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/class.md Called when an object is about to get recycled. Return false to prevent recycling and destroy the object instead. ```APIDOC ## _classPool:recycled() ### Description Called when an object is about to get recycled. Return false to prevent recycling and destroy the object instead. ### Method recycled ### Parameters None ### Returns - **boolean** - Return false if this object should not be recycled. ``` -------------------------------- ### ac.INIConfig.videoConfig() Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Loads the video configuration INI file. ```APIDOC ## ac.INIConfig.videoConfig() ### Description Loads the video configuration INI file. ### Returns - **ac.INIConfig** - The video configuration. ``` -------------------------------- ### MyFirstApp.lua - main script Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/wiki/Lua-apps Lua script for the app. Defines the main window function, optional settings and render callbacks, and an optional update function called each frame. ```lua function script.windowMain(dt) ui.text('Hello world!') end -- optional function script.windowSettings(dt) -- draw settings ui end -- optional function script.Draw3D(dt) -- draw something with the render. functions end -- optional, standard available function function script.update(dt) -- called each frame!! end ``` -------------------------------- ### Reading methods Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Methods for reading values from INI configs, including get, tryGetLut, tryGet2DLut, mapSection, mapConfig, iterate, and iterateValues. ```lua ---@param section string ---@param key string ---@param defaultValue any @Determines result type (or an Optional* sentinel). ---@param offset integer? ---@return any function ac.INIConfig:get(section, key, defaultValue, offset) end ---@param section string ---@param key string ---@return ac.Lut? @Look-up table from a value. function ac.INIConfig:tryGetLut(section, key) end ---@return ac.Lut? function ac.INIConfig:tryGet2DLut(section, key) end ---@param section string ---@param defaults table @Map of key → default. ---@return table @Map of key → value. function ac.INIConfig:mapSection(section, defaults) end ---@param defaults table @Map of section → defaults. ---@return table @Map of section → map of key → value. function ac.INIConfig:mapConfig(defaults) end function ac.INIConfig:iterate(prefix, noPostfixForFirst) end function ac.INIConfig:iterateValues(section, prefix, digitsOnly) end ``` -------------------------------- ### Basic usage of ac.getCar Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-state.md Gets the player car (index 0) and prints its name, speed, and position, checking for nil first. ```lua local player = ac.getCar(0) if player then print('Player car:', player.name) print('Speed:', player.speedKmh) print('Position:', player.position:table()) end ``` -------------------------------- ### Basic color usage Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/colors.md Basic usage of rgb, rgbm, and hsv constructors, including hex parsing and applying a color to UI style. ```lua local red = rgb(1, 0, 0) local tinted = red:mul(rgb(0.5, 1, 1)) -- scale channels local bright = rgbm(1, 0.5, 0, 0.8) -- orange with 0.8 alpha local fromHex = rgbm('#ff8000') -- parse hex local light = hsv(0.08, 0.9, 1.0) -- warm hue ui.pushStyleColor(ui.StyleColor.Text, rgb.colors.white) ``` -------------------------------- ### SmoothInterpolation example Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Uses ui.SmoothInterpolation to smoothly approach a target value (car.speedKmh) over time. The displayed speed is rounded down to the nearest integer. ```lua local speed = ui.SmoothInterpolation(0) function script.update(dt) local target = car.speedKmh local shown = speed(target) -- smoothly approaches target ui.text(string.format('%d km/h', math.floor(shown))) end ``` -------------------------------- ### Clamping and saturation functions (math.clampN, math.saturateN, math.clampV, math.saturateV, math.clamp, math.saturate) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/math.md Defines clamping and saturation functions. math.clampN clamps a number, math.saturateN clamps to [0,1], math.clampV and math.saturateV operate on vectors and return clones, and math.clamp/math.saturate dispatch on whether the input is a number or vector. ```lua ---@param x number ---@param min number ---@param max number ---@return number function math.clampN(value, min, max) end -- plain number clamp ---@param value number ---@return number function math.saturateN(value) end -- clamp to [0, 1] ---@param value vecN ---@param min vecN ---@param max vecN ---@return vecN @Clone of value, clamped. function math.clampV(value, min, max) end ---@param value vecN ---@return vecN @Clone of value, saturated. function math.saturateV(value) end ---@overload fun(x: number, min: number, max: number): number ---@overload fun(x: vecN, min: vecN, max: vecN): vecN function math.clamp(x, min, max) end ---@overload fun(x: number): number ---@overload fun(x: vecN): vecN function math.saturate(x) end ``` -------------------------------- ### ui.MediaPlayer(source, audioParams) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Creates a media player (video/audio) usable as an image source and as an audio emitter. ```APIDOC ## ui.MediaPlayer(source, audioParams) ### Description Creates a media player (video/audio) usable as an image source and as an audio emitter. ### Static Methods #### supported() Checks if media player is supported. ### Parameters - **source** (unknown) - Required - The media source. - **audioParams** (unknown) - Required - Audio parameters. ``` -------------------------------- ### Handling nil car return Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-state.md Example checking if a car index is valid, since ac.getCar may return nil for non-existent indices. ```lua local car = ac.getCar(7) -- may be nil if car 7 doesn't exist if car == nil then print('No car at index 7') end ``` -------------------------------- ### Basic vector operations with vec3 Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/vectors.md Shows creating vec3 vectors, adding them, computing length, and chaining methods like set, add, scale, and normalize. Chaining avoids GC pressure. ```lua local a = vec3(1, 2, 3) local b = vec3(4, 5, 6) local sum = a + b -- vec3(5, 7, 9) local len = a:length() -- 3.741657... local n = vec3.tmp():set(a):normalize() -- reuse a temp, no extra allocations -- Chaining avoids GC pressure local v = vec3() v:set(a):add(b):scale(2):normalize() ``` -------------------------------- ### quat instance methods Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/quat.md Instance methods for quat, including cloning, unpacking, setting, angle/axis operations, arithmetic, interpolation, and slerp. Methods like setAngleAxis, setBetween, and setDirection return self. ```lua function quat:clone() end function quat:unpack() end -- number, number, number, number function quat:table() end -- number[] function quat:type() end function quat:set(x, y, z, w) end -- (quat|number, y?, z?, w?) → self ---@param angle number @In radians. ---@param x vec3|number ---@param y number? ---@param z number? ---@return quat @Returns itself. function quat:setAngleAxis(angle, x, y, z) end ---@return number @Angle in radians. ---@return number @Axis, X. ---@return number @Axis, Y. ---@return number @Axis, Z. function quat:getAngleAxis() end ---@param u quat ---@param v quat ---@return quat @Returns itself. function quat:setBetween(u, v) end ---@param x vec3|number ---@param y number? ---@param z number? ---@return quat @Returns itself. function quat:setDirection(x, y, z) end function quat:add(valueToAdd, out) end -- quat|number function quat:sub(valueToSubtract, out) end -- quat|number function quat:mul(valueToMultiplyBy, out) end -- quat (rotation composition) function quat:scale(multiplier, out) end -- number function quat:length() end function quat:normalize(out) end function quat:lerp(otherVector, mix, out) end ---Rewrites own values with slerp of itself and other quaternion. function quat:slerp(otherVector, mix, out) end ``` -------------------------------- ### ac.VertexBuffer / ac.IndicesBuffer Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-scene.md Constructors for vertex and index buffers used in mesh manipulation. Both extend ac.GenericList, providing methods like get, set, size, and reserve. ```APIDOC ## ac.VertexBuffer / ac.IndicesBuffer ### Description Creates a new vertex buffer or index buffer for mesh data. Both classes extend `ac.GenericList`. ### Constructors #### ac.VertexBuffer(size) - **size** (integer) - Required - Initial size of the buffer. #### ac.IndicesBuffer(size) - **size** (integer) - Required - Initial size of the buffer. ### Inherited Methods (from ac.GenericList) - `:get()` - Get an element. - `:set()` - Set an element. - `:size()` - Get the number of elements. - `:reserve()` - Reserve capacity. ### Example ```lua local vb = ac.VertexBuffer(100) local ib = ac.IndicesBuffer(100) ``` ``` -------------------------------- ### Building a range and joining to CSV with table.range, table.map, table.join Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/table.md Builds a range from 1 to 5, converts each number to a string with table.map, joins them with commas using table.join, and prints the resulting CSV string. ```lua local items = table.range(5, 1, 1) -- {1, 2, 3, 4, 5} local csv = table.join(table.map(items, tostring), ',') print(csv) -- "1,2,3,4,5" ``` -------------------------------- ### Rotating a vector with a quaternion Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/quat.md Rotates a vector by a quaternion created from an angle and axis. The example rotates a point 90° around the Y axis and prints the resulting vector. ```lua -- Rotation of 90° around the Y axis local rot = quat.fromAngleAxis(math.pi / 2, vec3(0, 1, 0)) local point = vec3(1, 0, 0) point:rotate(rot) -- point becomes (0, 0, -1) roughly print(point:table()) ``` -------------------------------- ### Load KN5 model and animate it Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-scene.md Loads a KN5 model synchronously from a node with dynamicRoot:yes, sets an animation, and updates it in script.update. The animation update line is an illustration and may not be functional. ```lua local root = ac.findNodes('dynamicRoot:yes') local model = root:loadKN5({ filename = 'model.kn5', filter = 'mesh' }) if model then model:setAnimation('spin.ksanim', 0.0) function script.update(dt) model:setAnimation(nil, (model:getTransformationRaw().row1.x * 0) or 0) -- illustration end end ``` -------------------------------- ### Sim callbacks Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/wiki/Lua-apps Optional callbacks triggered at different points of the AC loop, allowing the app to get actual data or do work at specific points. Configured in the manifest. ```APIDOC ## Sim callbacks ### Description Optional callbacks triggered at different points of AC loop, in case app would need to get actual data or do some work at a very specific point. ### Configuration Set in manifest like so: ```ini [SIM_CALLBACKS] FRAME_BEGIN = fn ; if set, will be called right before scene has started rendering (can be used to move camera around) UPDATE = fn ; if set, function `script.fn()` will be called after a whole simulation update ``` ### Callbacks - **FRAME_BEGIN** - Called right before scene has started rendering. Can be used to move camera around. - **UPDATE** - Called after a whole simulation update. The function `script.fn()` will be called. ``` -------------------------------- ### Configure UI_CALLBACKS in manifest Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/wiki/Lua-apps Sets an optional UI callback for creating fullscreen UIs. IN_GAME is called before rendering ImGui apps. Requires creating a window with ui.transparentWindow() or ui.toolWindow() to draw. ```ini [UI_CALLBACKS] IN_GAME = fn ; called before rendering ImGui apps to draw things on screen ``` -------------------------------- ### ac.INIConfig.onlineExtras() Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Loads the online extras configuration. Returns nil if not an online session. ```APIDOC ## ac.INIConfig.onlineExtras() ### Description Loads the online extras configuration. Returns nil if not an online session. ### Returns - **ac.INIConfig|nil** - The online extras configuration, or nil if not an online session. ``` -------------------------------- ### Enum inlining example Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/wiki/Lua-preprocessor The preprocessor replaces CSP enums like `ac.Wheel.FrontRight` with the corresponding numeric value. No visible code block exists; only prose mentions the behavior. ```lua local value = const(math.pow(math.pi / math.pow(2, 0.1), 4.71)) ``` -------------------------------- ### ac.VertexBuffer and ac.IndicesBuffer class definitions Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-scene.md Defines the ac.MeshVertex class and the ac.VertexBuffer and ac.IndicesBuffer constructors. Both buffers extend ac.GenericList, providing methods like :get(), :set(), :size(), and :reserve(). ```lua ---@class ac.MeshVertex ---@class ac.VertexBuffer : ac.GenericList ---@param size integer function ac.VertexBuffer(size) end ---@class ac.IndicesBuffer : ac.GenericList ---@param size integer function ac.IndicesBuffer(size) end ``` -------------------------------- ### Serialization methods Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Methods for serializing the INI config to a string and saving to a file. ```lua function ac.INIConfig:__tostring() end ---@return string @Serialized INI. function ac.INIConfig:serialize() end ---@param filename string function ac.INIConfig:save(filename) end ``` -------------------------------- ### ac.INIConfig.scriptSettings() Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Loads the script's settings.ini file, which is customizable with Content Manager. ```APIDOC ## ac.INIConfig.scriptSettings() ### Description Loads the script's "settings.ini" file, which is customizable with Content Manager. ### Returns - **ac.INIConfig** - The script settings configuration. ``` -------------------------------- ### ac.storage(key, default) — typed storage value Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-storage.md Creates a typed storage reference with :get() and :set() methods. The default value determines the type of the stored value. ```APIDOC ## ac.storage(key, default) — typed storage value ### Description Creates a typed storage reference. The returned object has :get() and :set() methods. Supported default types: string, number, boolean, and cdata types vec2, vec3, vec4, rgb, rgbm. Unsupported types raise an error. ### Method N/A (function call) ### Endpoint N/A ### Parameters #### Arguments - **key** (string) - Required - The storage key. - **default** (any) - Required - The default value that determines the type. ### Request Example ```lua local bestLap = ac.storage('bestLap', 0) bestLap:set(92.5) print(bestLap:get()) ``` ### Response #### Success Response - **ac.StoredValue** (object) - An object with :get() and :set() methods. #### Response Example ```lua { get = function(self) ... end, set = function(self, value) ... end } ``` ``` -------------------------------- ### Typed storage value metatable Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-storage.md Metatable for a typed storage value. The get method returns the current value synced with persistent storage; set writes a new value. ```lua { get = function(self) ... end, -- returns current value (synced with persistent storage) set = function(self, value) ... end } ``` -------------------------------- ### ac.INIConfig.load(filename, format, includeFolders) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Loads an INI file from disk into an ac.INIConfig object. The format parameter defaults to ac.INIFormat.Default, and includeFolders is used for ExtendedIncludes. ```APIDOC ## ac.INIConfig.load(filename, format, includeFolders) ### Description Loads an INI file from disk into an ac.INIConfig object. ### Parameters - **filename** (string) - Required - The path to the INI file. - **format** (ac.INIFormat?) - Optional - Default `ac.INIFormat.Default`. - **includeFolders** (('@cars'|'@tracks'|string)[]?) - Optional - Folders to include from (ExtendedIncludes only). ### Returns - **ac.INIConfig** - The loaded configuration object. ``` -------------------------------- ### ac.INIConfig:iterate(prefix, noPostfixForFirst) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ini.md Iterates over sections or keys with a given prefix. ```APIDOC ## ac.INIConfig:iterate(prefix, noPostfixForFirst) ### Description Iterates over sections or keys with a given prefix. ### Parameters - **prefix** (string) - Required - The prefix to filter by. - **noPostfixForFirst** (boolean?) - Optional - Whether to omit the postfix for the first item. ### Returns - (none documented) ``` -------------------------------- ### Build a camera matrix with mat4x4.look Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/matrices.md Builds a camera matrix with mat4x4.look, then moves the camera forward each frame by adjusting its position along the look direction. Apply the result to a scene node with setTransformation (illustrative). ```lua local cam = mat4x4.look(vec3(0, 5, -10), vec3(0, 1, 0)) -- move the camera forward each frame cam.position = cam.position + cam.look * 0.5 someNode:setTransformation(cam) -- apply to a scene node (illustrative) ``` -------------------------------- ### Using ac.configValues for customizable display Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/entry-points.md Shows how to use ac.configValues to read configuration values defined in the script's config section. The example reads showText and conditionally displays text. ```lua -- Values come from the config section that created the script local cfg = ac.configValues({ refreshRate = 30, color = rgb(1, 1, 1), showText = true }) function script.update(dt) if cfg.showText then ui.text('Configured color works') end end ``` -------------------------------- ### Sign, rounding, interpolation, and remapping functions (math.sign, math.round, math.lerp, math.lerpInvSat, math.remap, math.smoothstep, math.smootherstep) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/math.md Defines sign, rounding, interpolation, and remapping helpers. math.sign returns 1, -1, or 0; math.round rounds to a given number of decimals (default 0); math.lerp linearly interpolates; math.lerpInvSat computes saturate((v-min)/(max-min)); math.remap maps a value from one range to another; math.smoothstep and math.smootherstep apply smooth interpolation curves. ```lua ---@param x number ---@return number @1, -1, or 0. function math.sign(x) end ---@param x number ---@param decimals number? @Default value: 0. ---@return number function math.round(number, decimals) end ---@param x number ---@param y number ---@param mix number ---@return number function math.lerp(x, y, mix) end ---@param value number ---@param min number ---@param max number ---@return number function math.lerpInvSat(value, min, max) end -- saturate((v-min)/(max-min)) ---@param value number ---@param oldA number ---@param oldB number ---@param newA number ---@param newB number ---@return number function math.remap(value, oldA, oldB, newA, newB) end ---@param x number ---@return number function math.smoothstep(x) end -- x*x*(3-2x) ---@param x number ---@return number function math.smootherstep(x) end -- x*x*x*(x*(x*6-15)+10) ``` -------------------------------- ### ClassPool base class definition Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/class.md Base class for all classes created with the class.Pool flag. Instances get a :recycled() hook called before recycling; returning false destroys the object instead of pooling it. ```lua ClassPool = {} function ClassPool.isInstanceOf(obj) end function ClassPool:isSubclassOf(classDefinition) end function ClassPool:subclass(...) end function ClassPool:include(mixin) end function ClassPool:subclassed(classDefinition) end ---Called when object is about to get recycled. ---@return boolean @Return false if this object should not be recycled. function _classPool:recycled() end ``` -------------------------------- ### stringify.substep(out, ptr, obj, lineBreak, depthLimit) Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/stringify.md Serialization substep for use inside custom `__stringify` methods. ```lua ---@param out string[] @Output table of words to concatenate later. ---@param ptr integer @Position in `out` to write next. ---@param obj any @Item to serialize. ---@param lineBreak string|nil @Line break + indentation, or `nil` in compact mode. ---@param depthLimit integer @Max depth; 0 or below serializes no tables. ---@return integer @Updated `ptr`. function stringify.substep(out, ptr, obj, lineBreak, depthLimit) end ``` -------------------------------- ### Tool window with a slider Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Creates a tool window named 'MyTool' with a slider for brightness and a text display of the current value. The window is positioned at (10,10) with size (200,100), not collapsed, and visible. ```lua local myValue = 0.5 function script.update(dt) ui.toolWindow('MyTool', vec2(10, 10), vec2(200, 100), false, true, function () ui.slider('Brightness', myValue, 0, 1, '%.2f') ui.text('Value: ' .. math.floor(myValue * 100) .. '%') end) end ``` -------------------------------- ### ui.FileIcon constructor and style method Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Creates a file icon object. specialized defaults to false. The style method sets the icon style. ```lua ---@param filename string ---@param specialized boolean? @Try to get exact-file icon. Default `false`. ---@return ui.FileIcon ui.FileIcon = function (filename, specialized) end ---@param style ui.FileIcon.Style function _uiFileIcon:style(style) end ``` -------------------------------- ### Play a soundbank event with ac.AudioEvent Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-audio.md Creates an audio event from a soundbank and starts it. Sets volume and an RPM parameter, then updates the event's position each frame using the car's transform and velocity. ```lua local engine = ac.AudioEvent('/cars/player/engine_ext', true) engine:start() engine.volume = 0.8 engine:setParam('RPM', 5000) function script.update(dt) engine:setPosition(car.position, car.look, car.up, car.localVelocity) end ``` -------------------------------- ### ui.itemPopup and ui.combo function signatures Source: https://github.com/ac-custom-shaders-patch/acc-lua-sdk/blob/main/_autodocs/api-reference/ac-ui.md Functions for creating item popups and combo boxes. ```lua function ui.itemPopup(id, mouseButton, content) end function ui.combo(label, previewValue, flags, content) end ```