Message Boxes

From WiCWiki

Jump to: navigation, search

Contents

Create a message box

There are 2 ways of creating a message box…you can use the Juice maker tool or a text editor. Some of us prefer the Juice maker, I definitely prefer a text editor. But I leave to you to decide what you prefer and I’ll show you both ways. You will find the juice file here wic\maps\mapname\mapname_singleplayerdata.juice.


-the juice maker way

If you open the juice file in the Juice maker, you will have to start with adding a message box. Click on mySinglePlayerData -> mySinglePlayerMissionStats -> myMessageBoxList and you will probably find it empty at the moment. If you right click on myMessageBoxList you will see a window named “Edit script class” with a “Type” a “Name” and a bunch of buttons. Click on the button “Add” and you will see a new window named “Add ScriptClassData”. Enter a name, in this example “Test_1”, which is the name we will use to call the message box from the python code later, and click OK and OK in the “Edit ScriptClass” widow as well. Now it will look like this.


Image:Message_Boxes_001.jpg


To add more message boxes just right click on “myMessageBoxList” again. All the message boxes will be listed below “myMessageBoxList”.


There are 6 variables which values you can change when creating a message box. All of them are listed beneath the name of the message box. “MB_TIMED” and “0.0” are by default, the rest are <empty> by default, and should continue to be <empty> if they don’t get a new value. We’ll cover more about the variables soon.


-the text editor way

If you open the juice file in a text editor it will look like this.

myMessageBoxList
{
  MessageBoxData 
  {
  }
  “More message boxes will be added here”.
}


The “MessageBoxData” part is what will become a message box. All message boxes will be listed between the “myMessageBoxLists” curly brackets.

The first thing we will do is to give the message box a name. This name is what you will use to call it from the python code later. You write the name next to “MessageBoxData”.


myMessageBoxList
{
    MessageBoxData Test_1
    {
    }
}

There are 6 variables which values you can change when creating a message box. All of them are listed between the “MessageBoxDatas” curly brackets. If you don’t have a value for the variable for example, you don’t have a picture, you should write”<empty>” instead.

MessageBoxData Test_1
{
    myType 
    myText 
    mySoundFile 
    myVideoPortraitFile 
    myPortraitText <empty>
    myTimeToShow 
}

Message Box variables

myType. myText. mySoundFile. myVideoPortraitFile. myPortraitText. myTimeToShow.

Image:Message_Boxes_002.jpg

1- myType.


The variable myType has 3 (we use 2 actually) different values to choose between.

MB_TIMED – is preferable used if you don’t have a sound file and want to decide how long the message box will be visible. Used in combination with the variable “myTimeToShow”

MB_BUTTON – deprecated.

MB_AUTOMATIC – is preferably used in combination with a sound-file. The time the message box is shown will adjust to the length of the sound-file. If you use MB_AUTOMATIC without a sound-file, the message box will be shown for about 6 seconds.


If you use MB_TIMED and a time number and it is shorter that the sound file it will override the time of the sound-file so it won’t be able to finish.

In this example we’ll use MB_AUTOMATIC.

myType MB_AUTOMATIC


2 – myText.

The variable myText contains the text that will be shown in the message box. In the first example we use the text “Hello World in Conflict.”(See example picture above). If you write the text in a text editor instead of using the JuiceMaker you must put it within quotation marks, else you won’t see the text in the game.

myText "Hello World in Conflict."

Hint. If you want to use “new line” in a message box you will have to use “\n”.

myText "Hello \nWorld in \n\nConflict."

3 – mySoundFile.

The variable mySoundFile contains a file path to a sound file. The file can be either an *.mp3 or an *.wav file.

mySoundFile maps\europeTest\mySounds\Hello_World_in_Conflict.mp3

4 – myVideoPortraitFile.

The variable myVideoPortraitFile contains a file path to the *bik-file that will be shown in the message box. The file could be either a picture or an animation. (See example picture above).The Size of the picture or animation should be 128 x 128 pixels.

myVideoPortraitFile myPictures/Sawyer.bik

For more information about the bik-format, please visit [1].

5 – myPortraitText.

The variable myPortraitText contains the text that will be shown beneath the portrait in the message box. (See example picture above).

myPortraitText SAWYER

6 – myTimeToShow.

The variable myTimeToShow contains a value which decides how long the message box will be shown. If the variable myType is set to MB_TIMED and you forget to set a time, the message box will just flash by.

The first, nice and good looking, cute little message box.

If you followed this example you should have a message box that looks like this.


In the Juice maker.


Image:Message_Boxes_003.jpg


Or like this in a text editor.

MessageBoxData Test_1
{
    myType MB_AUTOMATIC
    myText "Hello World in Conflict."
    mySoundFile maps/europeTest/mySounds/Hello_World_in_Conflict.mp3
    myVideoPortraitFile maps/europeTest/myPictures/Sawyer.bik
    myPortraitText SAWYER
    myTimeToShow 0.0
}


Message boxes in the Python files

If you put this code in the Intro function in “server.py” file you’ll be able to start the game and take a look at it. The Intro function is not the best place to place message boxes, but for now, just to test it out it will do.

ShowMessageBox( 'Test_1', 1 )

The first parameter is the name of the message box, the one you gave it in the juice file.

The second parameter is the message boxes ID, in this case 1. It is optional to use an ID (but we will use it later to trigger things on). It must be a number else the game will crash, but it could be any number as long as it is an integer. Make sure, when you add more message boxes, that they have a unique ID.


Now you can start the game and you should se a message box that looks something like this.


Image:Message_Boxes_004.jpg


Trigger a message box

To make it as simple as possible right now we will trigger the message box on the command point you created in chapter 1. You can trigger on different actions, but we will try this first as a start.


To trigger on when the player takes the command point we will use a special function just to make it possible to try it. You can copy paste this code to your server file or write your own. Some might have another function to write the code in from previous examples and the important things here are that the command point is active and that the TestFunction is called from the Intro function.

def Intro():
  [More code will probably be here]

  TestFunction()


def TestFunction( ):
  DebugMessage( 'TestFunction::' )
  
  SetCommandPointActive( 'CP_Village', True )
  RE_OnCommandPointTaken( 'CP_Village', TEAM_NATO, Action( ShowMessageBox, 'Test_1', 1 ))

-The first parameter in the ‘RE_OnCommandPointTaken’ function is which command point it will react on.


-The second parameter is which team it will trigger on. In this case, because it is aEurope map and we want to trigger on the player units, we use NATO. You can trigger on TEAM_USSR and TEAM_NEUTRAL as well and if it is USA map, you should use TEAM_USA. But in this example we use TEAM_NATO.


-The third parameter is an Action or a list with Actions. In this case we use only one Action and in that we call the same message box function as we did before. We want the action to be executed when the player units take the Command Point and not directly when the code is executed, so we must “save” it in an Action. If you, as we did before, writes an open parentheses instead of a comma after the “ShowMessageBox”-code it will crash.


Now you can start the game and when your player units (if you created them in the chapter about starting units, that is) take the Command point you should see a message box.

Trigger a message box on another message box

Sometimes it is nice to trigger a message box on another message box, if two people talk to each other, for example. To make that happen we trigger the message box on when the previous message box is closed. This is the first time we need to use the message box ID to know on which message box we should trigger.


Make sure you have at least two message boxes in you juice file.


Image:Message_Boxes_005.jpg


The code to do trigger on a previous message box is.

RE_OnMessageBoxClosed(1, Action( ShowMessageBox, 'Test_2', 2 ) )


- The first parameter is the ID of the message box we want to trigger on.

- The second is an Action or a list with Actions. We use the same function as we did before but with the new message box name and a new unique ID.


Start the game and if you have at least two message boxes in your juice file and these two lines in your server.py you should get a message box when you takes the command point and when that one is finished you should see the other one.


RE_OnCommandPointTaken( 'CP_Village', TEAM_NATO, Action( ShowMessageBox, 'Test_1', 1 ) )

RE_OnMessageBoxClosed(1, Action( ShowMessageBox, 'Test_2', 2 ) )


Appendix

Now that we have learned how to make message boxes we can add some of them to the code. We don’t add all message boxes yet because we want to use the Action Queue. We have a list of all message boxes that we need for the two first events to work.


Changed files in this chapter:

Server.py

europeTest_singleplayerdata.juice



Changes in the server.py file.

def VillageStart( ):
  [More code here.]

  RE_OnCommandPointTakenEx( 'CP_Village'],TEAM_NATO,[Action(RemoveReaction,mapvars.reactVillagePlayerDead),Action(VillageEnd)], True)

  # Show a messagebox when we get in the first fight.
  RE_OnPlayerInCombatWithPlatoon( PLAYER_HUMAN, mapvars.pltVillage, Action( ShowMessageBox, 'e1_3', 103 ) )


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

  # Show a messagebox when the arty is under fire.
  RE_OnGroupInCombat( mapvars.grpRescueArty, Action( ShowMessageBoxQueue, 'e1_7', 107 ) ) 


Changes in the europeTest_singleplayerdata.juice file.


If you open europeTest.juice in the ‘JuiceMaker’ tool you will find myMessageBoxList under mySinglePlayerData -> mySinglePlayerMissionStats -> myMessageBoxList.


myMessageBoxList
{
  MessageBoxData e1_1
  {
    myType MB_TIMED
    myText "Take the commandpoint to complete the objective"
    mySoundFile <empty>
    myVideoPortraitFile messagebox_characters/wic/Sawyer.bik
    myPortraitText SAWYER
    myTimeToShow 6.0
  }

  MessageBoxData e1_2
  {
    myType MB_TIMED
    myText "Good job!"
    mySoundFile <empty>
    myVideoPortraitFile messagebox_characters/wic/Sawyer.bik
    myPortraitText SAWYER
    myTimeToShow 6.0
  }
 
  MessageBoxData e1_3
  {
    myType MB_TIMED
    myText "We have enemy contact."
    mySoundFile <empty>
    myVideoPortraitFile maps/europeTest/myPictures/tankDude.bik
    myPortraitText TANKDUDE
    myTimeToShow 6.0
  }

  MessageBoxData e1_4
  {
    myType MB_TIMED
    myText "I just got a call from our mortar detachment! They're under attack near the ruins. Aid them if possible."
    mySoundFile <empty>
    myVideoPortraitFile messagebox_characters/wic/Sawyer.bik
    myPortraitText SAWYER
    myTimeToShow 6.0
  }
 
  MessageBoxData e1_5
  {
    myType MB_TIMED
    myText "Well done. I'm giving you command of the mortars. Provide what support you can."
    mySoundFile <empty>
    myVideoPortraitFile messagebox_characters/wic/Sawyer.bik
    myPortraitText SAWYER
    myTimeToShow 6.0
  }
 
  MessageBoxData e1_6
  {
    myType MB_TIMED
    myText "I just lost contact with our mortar detachment. That's some good men we just lost."
    mySoundFile <empty>
    myVideoPortraitFile messagebox_characters/wic/Sawyer.bik
    myPortraitText SAWYER
    myTimeToShow 6.0
  }
 
  MessageBoxData e1_7
  {
    myType MB_TIMED
    myText "The artillery are taking hits, they need assistant now!"
    mySoundFile <empty>
    myVideoPortraitFile messagebox_characters/wic/Sawyer.bik
    myPortraitText SAWYER
    myTimeToShow 6.0
  }
}


Chapter 5: Reactions and Actions < > Chapter 7: Action Queue
Personal tools
User Created Content