Page 1 of 1

Custom Lua Functions - Adding Enum as a Parameter

Posted: Sun Nov 12, 2023 1:13 pm
by AvalonGames
Hey!

I was wondering if it was possible to pass in an enum as a parameter for custom Lua Functions. Or as an alternative, what is the best way to go about this issue.
gameState.png
gameState.png (4.81 KiB) Viewed 288 times
I have a function in my CustomLuaFunctions script and was wondering if this was possible.

Cheers!

Re: Custom Lua Functions - Adding Enum as a Parameter

Posted: Sun Nov 12, 2023 3:44 pm
by Tony Li
Hi,

Lua doesn't have enums. You can use strings. For example, your Script field might look like:

Code: Select all

ChangeGameState("Paused")
And your C# method might look like:

Code: Select all

public enum GameState { MainMenu, Paused, Playing }

public void ChangeGameState(string stateName)
{
    GameManager.State = Enum.Parse(typeof(GameState), stateName);
}