Instance.PublicMethod
Definition
Define a function that can be called from hammers I/O system. Once defined, trigger an input on the point_script with the public method name in the "Via this input" field.
import { Instance } from "cspointscript"
Instance.PublicMethod("PublicFunc", () => {
// Runs when this scripts point_script entity receives an input of 'PublicFunc'
})
Example of the output on a func_button to trigger the above method:
S2TS needs to know the name of the method at compile time. It does this by checking for the text inbetween the quotes defined as the first parameter, so its important that the name is defined as a single string and not created at run time.
const methodName = "InputReceived"
Instance.PublicMethod(methodName, () => {})
Instance.PublicMethod("Input" + "Received", () => {})
Instance.PublicMethod("InputReceived", () => {})
Arguments
Public functions can also take string parameters but must be declared with the correct type.
import { Instance } from "cspointscript"
Instance.PublicMethod("InputReceived", (input: string) => {
// 'input' will be whatever was specified in the "With a parameter override of" field
})
S2TS needs to know the argument type at compile time. It does this by checking for the text ": string" in your argument type. If that type is not found, the public method will get defined with no argument.
Instance.PublicMethod("InputReceived", (input) => {})
Instance.PublicMethod("InputReceived", (input: SomeCustomType) => {})
Instance.PublicMethod("InputReceived", (input: string) => {})