State: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Mblackwell (talk | contribs)
mNo edit summary
 
No edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
A state is a block of code written outside of any [[actor]]s or [[event]]s, that can be called from within them. This is useful because it allows you to use the same code in multiple places without rewriting it.
A state is a block of code written outside of any [[actor]]s or [[event]]s, that can be called from within them. This is useful because it allows you to use the same code in multiple places without rewriting it.


Syntax for state creation:
Use the token '''defstate''' to create a state outside of other states, actors, or events. ('''State''' works too, but '''defstate''' is preferable if you use a syntax highlighter that can collapse blocks.) The token '''ends''' marks the end of the state.


state <name> { state code } [[ends]]
'''defstate''' <name>
 
    // (state code...)
<name> is the name of the state.
'''ends'''
 
{ state code } is the code executed within that state.
 
[[ends]] denotes the end of a state.
 
 
Calling a state within an [[actor]] is simply:
 
state <name>


Calling a state within an [[actor]] is simply:  <code>'''state''' <name></code>


Example code:
Example code:


define MYACTOR1 3585
define MYACTOR2 3586
define MYACTOR3 3587
defstate spawnblood
    ifhitweapon
    {
        guts JIBS6 12
        spawn BLOODPOOL
        killit
    }
ends
useractor notenemy MYACTOR1 2
    state spawnblood
enda
useractor notenemy MYACTOR2 2
    state spawnblood
enda
useractor notenemy MYACTOR3 2
    state spawnblood
enda


[[define]] MYACTOR1 3585
Use [[break]] to exit a state before all of its code is finished executing.
 
[[define]] MYACTOR2 3586
 
[[define]] MYACTOR3 3587
 
state spawnblood
 
[[ifhitweapon]]
 
{
 
:[[guts]] JIBS6 12
 
:[[spawn]] BLOODPOOL
 
:[[killit]]
 
}
 
[[ends]]
 
[[useractor]] notenemy MYACTOR1 2
 
state spawnblood
 
[[enda]]
 
[[useractor]] notenemy MYACTOR2 2
 
state spawnblood
 
[[enda]]
 
[[useractor]] notenemy MYACTOR3 2
 
state spawnblood
 
[[enda]]
 


Use [[break]] to exit a state before all of it's code is finished executing.
[[Category:Duke3D 1.3/1.5 commands]]

Latest revision as of 00:00, 24 September 2015

A state is a block of code written outside of any actors or events, that can be called from within them. This is useful because it allows you to use the same code in multiple places without rewriting it.

Use the token defstate to create a state outside of other states, actors, or events. (State works too, but defstate is preferable if you use a syntax highlighter that can collapse blocks.) The token ends marks the end of the state.

defstate <name>
    // (state code...)
ends

Calling a state within an actor is simply: state <name>

Example code:

define MYACTOR1 3585
define MYACTOR2 3586
define MYACTOR3 3587

defstate spawnblood
    ifhitweapon
    {
        guts JIBS6 12
        spawn BLOODPOOL
        killit
    }
ends

useractor notenemy MYACTOR1 2
    state spawnblood
enda

useractor notenemy MYACTOR2 2
    state spawnblood
enda

useractor notenemy MYACTOR3 2
    state spawnblood
enda

Use break to exit a state before all of its code is finished executing.