GOOC - Game Oriented Object C

GOOC - Game Oriented Object C

Next: The code Block, Up: States
[Contents]

10.1. Defining a State

10.1. Defining a State

You write the state definition to specify what a state actually does and how it's made up. A state definition consists of information regarding the state’s name and the body of the state. The state body is a series of state statements enclosed in braces: state state-name { ... } state-name is the name of the state. The name must be unique to the state, otherwise a compiler error will be thrown.

Although not technically mandatory, a state cannot function if it does not have a code block defined. A compiler warning will be thrown if it isn't.

Each of the three blocks in a state can be defined in-line within the state (state subroutine), or through the lambda operator =>: sub MySub () { do { playanim(0, 0) } while (1) } state FirstState { code => sub MySub // set the code block to the subroutine MySub trans { x += 1.0 } } state SecondState { code => state FirstState // the code block used will be the same as FirstState's trans => state FirstState // the trans block used will be the same as FirstState's } This allow quick and easy re-use of code and state functionality.