Book Image

Mastering CryENGINE

By : Michelle Martin
Book Image

Mastering CryENGINE

By: Michelle Martin

Overview of this book

Table of Contents (17 chapters)
Mastering CryENGINE
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using the state machine


CryENGINE provides simple state machine logic for Lua entities. This allows you to easily set up different states and create the behavior of a simple state machine. If you want to implement something similar to a switch that can be on or off, or a door that can be opened or closed, using the built-in state machine will do most of the work for you.

Not every entity needs to make use of this state machine logic, but for more complex entities, it is quite nice to have this extra bit of functionality built-in.

In order to add a state to an entity, you just need to list the names of all your states once within your main table so that the engine knows which states your entity has. This can be as many or as few as you need. Take a look at the following line of code:

States = {"SomeState", "AnotherState"},

Just like with any other state machine, only one state at a time can be active and there are specific functions to handle the transitions between the states. You need to add...