Custom Lua Functions - Adding Enum as a Parameter

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
AvalonGames
Posts: 10
Joined: Wed Apr 27, 2022 11:01 pm

Custom Lua Functions - Adding Enum as a Parameter

Post 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 305 times
I have a function in my CustomLuaFunctions script and was wondering if this was possible.

Cheers!
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Lua Functions - Adding Enum as a Parameter

Post 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);
}
Post Reply