Skip to main content

FBase

Inherits BaseObject

FBase provides a structure for setting up and fetching Instances in an OOP fashion while still being fluid in its interactions with Fusion. It is intended to be used as a base class for other FusionOnRails classes.

Any class that inherits this can have their .new() constructor called via calling the class itself as a function in order to match Fusion.

[NOTE] :Bind must be called exactly once. If you do not pass anything to the FBase constructor then you must call this method yourself, ideally in the constructor of the inheriting class.

[EXAMPLE USAGE]

-- (Assume Fusion Imports)
local ExampleUI = setmetatable({}, FBase)
ExampleUI.__index = ExampleUI
ExampleUI.ClassName = "ExampleUI"


function ExampleUI.new(props)
	local self = setmetatable(FBase.new(), ExampleUI)

	self.Pulsate = Value(false)

	self:Bind(New "Frame" {
		Name = props.Name;
		Transparency = Computed(function(use) -- Makes the frame fade in and out repeatedly
			if use(self.Pulsate) then
				local t = use(self:Clock())
				return math.sin(t) / 2 + 0.5
			end
			return 0
		end);
	})

	return self
end

-------------------------------------

local ExampleUI = Import("ExampleUI")

local myUI = ExampleUI {
	Name = "MyUI";
}

print(myUI:GetInstance().Name) -- "MyUI"

self.Pulsate:set(true) -- turns on the pulsating effect

task.wait(5)

myUI:Destroy() -- Destroys the FBase and its GuiObject

Functions

getObjectFromInstance

static
FBase.getObjectFromInstance(
objInstance--

The Instance to fetch the FBase from

) → FBase?

Fetches the FBase that is bound to the given GuiObject.

is

static
FBase.is(
objany--

The object to check

) → boolean--

Whether or not the object inherits FBase

Can but used to check if a passed object inherits FBase.

new

static
FBase.new(
obj(Instance | string)?,
propsPropTable?,
priorityPropsPropTable?
) → FBase

Creates a new FBase.

Destroy

FBase:Destroy() → ()

Destroys the FBase and its Instance if not done so already. This method is automatically called if the bound Gui is Destroyed.

Bind

FBase:Bind(
objInstance | string,--

Takes an Instance or a string containing the Instance ClassName to create

propstable?,--

The default props to apply. (Only used if a ClassName is passed)

priorityPropstable?--

A table of props that will override the indices of the props table. (Only used if a ClassName is passed)

) → GuiObject

Initializes the FBase with a Instance. It binds this Object's lifecycle to the lifecycle of the Instance. If either is destroyed, the other is aswell. This method should be called exactly once and will throw an error if called again.

IsBound

FBase:IsBound() → boolean

Checks to see if the FBase is bound to an Instance.

GetInstance

FBase:GetInstance() → Instance

Returns the Instance that this FBase is bound to.

Clock

FBase:Clock() → StateObject<number>

Fetches a state object JIT that can be used to force update computeds each frame. This state will update every frame at RenderStep for the duration of the FBase's lifetime. The number stored in the state is the time since the FBase was constructed.

HeartbeatUpdate

FBase:HeartbeatUpdate(dtnumber) → ()

If this method is present on an FBase Class, then it will be automatically connected to RunService.Heartbeat.

function MyFBaseClass:HeartbeatUpdate(dt)
end

SteppedUpdate

FBase:SteppedUpdate(dtnumber) → ()

If this method is present on an FBase Class, then it will be automatically connected to RunService.Stepped.

function MyFBaseClass:SteppedUpdate(dt)
end

RenderSteppedUpdate

This item only works when running on the client. Client
FBase:RenderSteppedUpdate(dtnumber) → ()

If this method is present on an FBase Class, then it will be automatically connected to RunService.RenderStepped. If the [FBase].RenderPriority field is found, then the component will instead use RunService:BindToRenderStep() to bind the function.

-- Example that uses `RunService.RenderStepped` automatically:
function MyFBaseClass:RenderSteppedUpdate(dt)
end
-- Defining a RenderPriority will force the component to use BindToRenderStep instead
MyFBaseClass.RenderPriority = Enum.RenderPriority.Camera.Value

function MyFBaseClass:RenderSteppedUpdate(dt)
end
Show raw api
{
    "functions": [
        {
            "name": "getObjectFromInstance",
            "desc": "Fetches the FBase that is bound to the given GuiObject.",
            "params": [
                {
                    "name": "obj",
                    "desc": "The Instance to fetch the FBase from",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "FBase?"
                }
            ],
            "function_type": "static",
            "tags": [
                "static"
            ],
            "source": {
                "line": 172,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "is",
            "desc": "Can but used to check if a passed object inherits FBase.",
            "params": [
                {
                    "name": "obj",
                    "desc": "The object to check",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "Whether or not the object inherits FBase",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "tags": [
                "static"
            ],
            "source": {
                "line": 186,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "new",
            "desc": "Creates a new FBase.",
            "params": [
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "(Instance | string)?"
                },
                {
                    "name": "props",
                    "desc": "",
                    "lua_type": "PropTable?"
                },
                {
                    "name": "priorityProps",
                    "desc": "",
                    "lua_type": "PropTable?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "FBase"
                }
            ],
            "function_type": "static",
            "tags": [
                "static"
            ],
            "source": {
                "line": 198,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys the FBase and its Instance if not done so already.\nThis method is automatically called if the bound Gui is Destroyed.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 217,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "Bind",
            "desc": "Initializes the FBase with a Instance. It binds this Object's lifecycle to\nthe lifecycle of the Instance. If either is destroyed, the other is aswell.\nThis method should be called exactly once and will throw an error if called again.",
            "params": [
                {
                    "name": "obj",
                    "desc": "Takes an Instance or a string containing the Instance ClassName to create",
                    "lua_type": "Instance | string"
                },
                {
                    "name": "props",
                    "desc": "The default props to apply. (Only used if a ClassName is passed)",
                    "lua_type": "table?"
                },
                {
                    "name": "priorityProps",
                    "desc": "A table of props that will override the indices of the props table. (Only used if a ClassName is passed)",
                    "lua_type": "table?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "GuiObject"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 234,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "IsBound",
            "desc": "Checks to see if the FBase is bound to an Instance.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 292,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "GetInstance",
            "desc": "Returns the Instance that this FBase is bound to.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 300,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "Clock",
            "desc": "Fetches a state object JIT that can be used to force update\ncomputeds each frame. This state will update every frame at\nRenderStep for the duration of the FBase's lifetime.\nThe number stored in the state is the time since the FBase\nwas constructed.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "StateObject<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 314,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "HeartbeatUpdate",
            "desc": "If this method is present on an FBase Class, then it will be\nautomatically connected to `RunService.Heartbeat`.\n\n```lua\nfunction MyFBaseClass:HeartbeatUpdate(dt)\nend\n```",
            "params": [
                {
                    "name": "dt",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 342,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "SteppedUpdate",
            "desc": "If this method is present on an FBase Class, then it will be\nautomatically connected to `RunService.Stepped`.\n\n```lua\nfunction MyFBaseClass:SteppedUpdate(dt)\nend\n```",
            "params": [
                {
                    "name": "dt",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 356,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        },
        {
            "name": "RenderSteppedUpdate",
            "desc": "If this method is present on an FBase Class, then it will be\nautomatically connected to `RunService.RenderStepped`. If\nthe `[FBase].RenderPriority` field is found, then the\ncomponent will instead use `RunService:BindToRenderStep()`\nto bind the function.\n\n```lua\n-- Example that uses `RunService.RenderStepped` automatically:\nfunction MyFBaseClass:RenderSteppedUpdate(dt)\nend\n```\n```lua\n-- Defining a RenderPriority will force the component to use BindToRenderStep instead\nMyFBaseClass.RenderPriority = Enum.RenderPriority.Camera.Value\n\nfunction MyFBaseClass:RenderSteppedUpdate(dt)\nend\n```",
            "params": [
                {
                    "name": "dt",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Client"
            ],
            "source": {
                "line": 382,
                "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "FBase",
    "desc": "Inherits BaseObject\n\nFBase provides a structure for setting up and fetching Instances in an OOP\nfashion while still being fluid in its interactions with Fusion. It is intended\nto be used as a base class for other FusionOnRails classes.\n\nAny class that inherits this can have their .new() constructor called\nvia calling the class itself as a function in order to match Fusion.\n\n[NOTE] :Bind must be called exactly once. If you do not pass\nanything to the FBase constructor then you must call this method\nyourself, ideally in the constructor of the inheriting class.\n\n\n[EXAMPLE USAGE]\n```lua\n-- (Assume Fusion Imports)\nlocal ExampleUI = setmetatable({}, FBase)\nExampleUI.__index = ExampleUI\nExampleUI.ClassName = \"ExampleUI\"\n\n\nfunction ExampleUI.new(props)\n\tlocal self = setmetatable(FBase.new(), ExampleUI)\n\n\tself.Pulsate = Value(false)\n\n\tself:Bind(New \"Frame\" {\n\t\tName = props.Name;\n\t\tTransparency = Computed(function(use) -- Makes the frame fade in and out repeatedly\n\t\t\tif use(self.Pulsate) then\n\t\t\t\tlocal t = use(self:Clock())\n\t\t\t\treturn math.sin(t) / 2 + 0.5\n\t\t\tend\n\t\t\treturn 0\n\t\tend);\n\t})\n\n\treturn self\nend\n\n-------------------------------------\n\nlocal ExampleUI = Import(\"ExampleUI\")\n\nlocal myUI = ExampleUI {\n\tName = \"MyUI\";\n}\n\nprint(myUI:GetInstance().Name) -- \"MyUI\"\n\nself.Pulsate:set(true) -- turns on the pulsating effect\n\ntask.wait(5)\n\nmyUI:Destroy() -- Destroys the FBase and its GuiObject\n```",
    "source": {
        "line": 64,
        "path": "src/fusiononrails/src/FusionOnRails/Classes/FBase.lua"
    }
}