Invoking Methods
Now, we can easily define custom methods and call them from our server proxy. Here's an example of how to do that:
warning
Custom methods are remote calls for multiple clients under the hood, so they cannot return values.
- Luau
- TypeScript
myEffect.lua
local refx = require(path.to.refx)
local myEffect = refx.CreateEffect("myEffect")
function myEffect:OnConstruct()
self.DestroyOnEnd = false -- so our effect don't get destroyed instantly.
self.MaxLifetime = 10
end
function myEffect:DoSomething(arg) -- our custom method
print(arg)
end
return myEffect
myEffect.ts
import { BaseEffect, VisualEffectDecorator } from "@rbxts/refx";
@VisualEffectDecorator
export class myEffect extends BaseEffect {
protected readonly DestroyOnEnd = false; // so our effect don't get destroyed instantly.
protected readonly MaxLifetime = 10;
public DoSomething(arg: number) { // our custom method
print(arg);
}
}
Let's create our effect and call our method from the server proxy:
- Luau
- TypeScript
somewhere.lua
local myEffect = require(path.to.effect)
local effect = myEffect.new():Start(game.Players:GetPlayers())
effect:DoSomething(10)
somewhere.ts
import { myEffect } from "./myEffect";
import { Players } from "@rbxts/services";
const effect = new myEffect().Start(Players.GetPlayers());
effect.DoSomething(10);