Reactions and Actions

From WiCWiki

Jump to: navigation, search



Reactions are triggered by certain events in the game. May it be a unit being killed or a command point that has been captured, they can all trigger reaction.

Actions are vessels for functions and their arguments and are used in reactions and Refill commands etc. Actions are mainly used for function control when using them in for example reactions.

In the chapter e2, ‘Reactions the long version’ we will explain the reaction and action system more in detail.

In the following pages we will create and explain a couple of reactions and actions.

Using a reaction

In an earlier chapter we created a command point outside the village and some starting units. Now we will use those elements to create our first reaction.

The first thing we are going to use the reaction for, is to create a fail condition that trigger on if the player loses his starting units.

The starting units are gathered in a platoon, so we will use the reaction RE_OnEmptyPlatoon.

RE_OnEmptyPlatoon( aPlatoon, someActions )

This is the Platoon the reaction will trigger on.

This is a single Action or a list of Actions.

Before we start scripting the reaction we will create a variable in which we can add the reaction to. This is done so we can control the reaction and for save/load reasons.

Open the file and add the following line.

reactVillagePlayerDead = None

With that done we can go ahead and create the reaction. Open up the file and create a new function after the Intro() function. We will call it VillageStart( ).

In this function we can add the reaction to the variable we created earlier.

def VillageStart( ):
  mapvars.reactVillagePlayerDead = RE_OnEmptyPlatoon( aPlatoon, someActions )

Next we have to fill the reaction arguments with real inputs. In the chapter where we created the starting units, we put the created platoon into a variable. This variable will be our first argument.

Now we need a function to put in our Action. As we want this reaction to trigger a failcondition, we will use wicg.EndGame( aTeam ) and set the aTeam to TEAM_USSR.

This will show the ’Mission Failed’ screen when the player units in this case dies.

The VillageStart() function will look like this now.

def VillageStart( ):
  mapvars.reactVillagePlayerDead = RE_OnEmptyPlatoon( mapvars.pltPlayer, Action( wicg.EndGame, TEAM_USSR )  )

As you can see the function within the Action has no own parenthesis for its argument, instead separated by a comma (,). If you put a function in with parenthesis’s the map will surely crash at map start

If the function has more than one argument just keep on separating them with commas. Action( aFunction, anArgument, anArgument, anArgument )

The last step before our reaction will work is to call the VillageStart() function when the map starts. This is done by adding VillageStart() in the Intro( ) function.

Now when the map starts the reaction will start listening for the destruction of the platoon and will end the map if the platoon is destroyed. If you want to try this reaction and you don’t have any enemy units that can kill your units, use the disband button to disband your units to trigger it.

We have made it possible to fail the map, now we will make it possible to finish it to.

To end the map the player will have to take the command point we created earlier, CP_Village. The reaction to enable us to do this is RE_OnCommandPointTaken().

RE_OnCommandPointTaken( aCommandPoint, aTeam, someActions )

This is the command point the reaction will trigger on if taken.

This is the Team that has to take the command point for the reaction to trigger.

This is a single Action or a list of Actions.

As with the former reaction we will put this one in a variable, so start by opening and add reactVillageTaken = None to the file.

Now head back to and to the function we wrote earlier. Below the previous reaction we will add the new reaction, beginning with adding it to the newly created variable.

mapvars.reactVillageTaken = RE_OnCommandPointTaken( aCommandPoint, aTeam, someActions )

The command point we are going to use is already decided and the team will be that of the player, in this case NATO. The Action part will be a bit more tricky. We would like to shut the first reaction down when RE_OnCommandPointTaken is triggered. This so you won’t get the scenario that you fail after you first have succeeded.

The way to do that is to remove the first reaction. This is done with the function RemoveReaction(). In the function RemoveReaction() we use one parameter. As that parameter we will have the variable ’reactVillagePlayerDead’ we saved the RE_OnEmptyPlatoon reaction in before.

We will also need an Action with a function to win the map. This function is the same as the one used in the first reaction, but with the team argument set to the players, e.i. Nato.

With more than one Action to be executed when the reaction triggers, we have to put them in a list. This is done easiest by putting the Actions within brackets [].

Now we have all the statements covered, so it’s only to put the reaction together.

RE_OnCommandPointTaken( 'CP_Village', TEAM_NATO, [ Action( RemoveReaction, mapvars.reactVillagePlayerDead ) ,Action( wicg.EndGame, TEAM_NATO ) ] )

The whole VillageStart( ) function in should now look like this.

def VillageStart( ):
  mapvars.reactVillagePlayerDead = RE_OnEmptyPlatoon( mapvars.pltPlayer, Action( wicg.EndGame, TEAM_USSR )  )
  RE_OnCommandPointTaken( 'CP_Village', TEAM_NATO, [ Action( RemoveReaction, mapvars.reactVillagePlayerDead ) ,Action( wicg.EndGame, TEAM_NATO ) ] )

Now we have both a reaction with a fail condition and one with a win condition.

To this you can use the tutorial chapter about units to create Russian defenders who will hinder the player trying to capture the command point.

If you want to know more about reactions and actions, you can read about them in the chapter e2, ’Reactions the long version’.

You can find more reaction to use in install directory\python\

PostEvent and custom reactions

A reaction we used a lot in the creation of WIC is the custom reaction, RE_OnCustomEvent(). This reaction listens for events we post ourselves by script using the PostEvent() function.

Here follows a simple explanation of the reaction and the function PostEvent. A more detailed description can be found in chapter e2, ’Reactions the long version’.

RE_OnCustomEvent( aString, someActions ) 

This is the string the reaction waits for to trigger.

This is a single Action or a list of Actions.

PostEvent( aString )

This is the string being sent as an event, which custom reaction will be able to react on.

As an example we create a scenario where we will print a debug message to the debug file when the event ‘PrintADebugMessage’ is posted.

The reaction and PostEvent should look like this and be in the intro function in the fille.

def Intro():
  [More code will probably be here]
  RE_OnCustomEvent( 'PrintADebugMessage', Action( DebugMessage, ‘A nice and cute little debug message’ ) )
  PostEvent( 'PrintADebugMessage')

The reaction is now set and will trigger when PostEvent( 'PrintADebugMessage') is executed and there will be an ‘Python debug: A nice and cute little debug message’ line added to the debug file.

A more detailed description of the DebugMessage function and the debug file can be found in chapter 1,’ Before we start’.


In chapter five we add reactions to trigger the start of events, complete and fail. We have also saved some reactions in the file.

Changed files in this chapter:

Changes in the file.

def VillageSetup( aKickStart = False ):    
  DebugMessage( "VillageSetup::" )

  # Setup the start reaction for the event.

  RE_OnCustomEvent( 'IntroEnd', Action( VillageStart ) )
  RE_OnCustomEvent( 'VillageCamEnd', Action( VillageStart ) )

  if aKickStart:
    DebugMessage( "VillageSetup::KickStart" )

    PostEvent( 'IntroEnd' )

def VillageCam( ):
  [More code here.]
  # Setup reactions for what to do if/when the player click esc or the cam is done.
  RE_OnCustomEvent( 'END_OF_CUTSCENE', Action( PostEvent, 'VillageCamEnd' ) )
  RE_OnCustomEvent( 'SKIP_CUTSCENE', Action( PostEvent, 'END_OF_CUTSCENE' ) )         

def VillageStart( ):
  DebugMessage( "VillageStart::" )

  PostEvent( 'RescueArtyStart' )

  mapvars.reactVillagePlayerDead = RE_OnEmptyPlatoon( mapvars.pltPlayer, Action( wicg.EndGame, TEAM_USSR )  )

  # setup a reaction for when Nato takes the CP and then run the complete queue. And remove the fail reaction.
  # Use the complex reaction so we can test if NATO already owns the command point.
  RE_OnCommandPointTakenEx( [ 'CP_Village' ], TEAM_NATO, [ Action( RemoveReaction, mapvars.reactVillagePlayerDead ) ,Action( VillageEnd ) ], True )

def VillageEnd():
  DebugMessage( 'VillageEnd::' )

  # Post that the village event is done and we want to start the next one.
  PostEvent( 'VillageEnd' )

#-------------------------  RescueArty  -------------------------   
def RescueArtySetup( aKickStart = False ):
  DebugMessage( 'RescueArtySetup::' )

  RE_OnCustomEvent( 'RescueArtyStart', Action( RescueArtyStart ) )

  if aKickStart:
    PostEvent( 'RescueArtyStart' )       

def RescueArtyStart( ):
  DebugMessage( 'RescueArtyStart::' )

  # Make the reaction for complete and fail condition.         
  mapvars.reactRescueArtyComplete = RE_OnEmptyGroup( mapvars.grpRescueArtyRu1, Action( PostEvent, 'RescueArtyRuDead' ) )
  mapvars.reactRescueArtyFail = RE_OnEmptyGroup( mapvars.grpRescueArty, Action( PostEvent, 'RescueArtyDead' ) )

Changes in the file.

#---------------------------  Village ---------------------------
 reactVillagePlayerDead = None

#-------------------------  RescueArty  -------------------------   

[More variable here.]
reactRescueArtyComplete = None
reactRescueArtyFail = None

Chapter 4: Player Starting Units < > Chapter 6: Message Boxes
Personal tools
User Created Content