Difference between revisions of "Create story script"

From XStoryPlayer Wiki
Jump to: navigation, search
Line 34: Line 34:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
This will make a door object from the scene object. Now we can also open the door using a script.
 
This will make a door object from the scene object. Now we can also open the door using a script.
 +
</li>
 +
<li>Now lets test the doors. Open the <code>/init/story/player/brain/run.dat</code>. This file contains the state code of the player.<br>
 +
Change the code to this:
 +
<syntaxhighlight lang="cpp">
 +
#include "init/std/base/main/brain/code/run.dat"
 +
 +
//-------------------------------------------
 +
 +
<state_run>
 +
 +
case (state.dyn.me.do.state)
 +
{
 +
  [RUN0] state_run0();
 +
}
 +
 +
</state_run>
 +
 +
//-------------------------------------------
 +
 +
<state_run0>
 +
 +
case (state.dyn.me.do.state2)
 +
{
 +
  [NONE]
 +
  {
 +
    // Set timer to 3 seconds
 +
    do_set_timer(3);
 +
   
 +
    state.dyn.me.do.state2 = START;
 +
  }
 +
 
 +
  [START]
 +
  {
 +
    // Wait for timeout
 +
    loc.ts = GetTs(); 
 +
    [loc.ts < state.dyn.me.do.ts] return;
 +
 +
    // Open doors
 +
    loc.so.obj = SPACESHIP1:CELL1;
 +
    loc.so.par = DOOR_SET_STATUS;
 +
    loc.so.val = DOOR_SETVAL_STATUS_OPEN;    
 +
    SetObject(loc.so);
 +
 +
    loc.so.obj = SPACESHIP1:CELL2;
 +
    loc.so.par = DOOR_SET_STATUS;
 +
    loc.so.val = DOOR_SETVAL_STATUS_OPEN;    
 +
    SetObject(loc.so);
 +
 +
    // Set timer to 6 seconds
 +
    do_set_timer(6);
 +
 +
    state.dyn.me.do.state2 = OPEN;
 +
  }
 +
 
 +
  [OPEN]
 +
  {
 +
    // Wait for timeout
 +
    loc.ts = GetTs(); 
 +
    [loc.ts < state.dyn.me.do.ts] return;
 +
 +
    // Close doors
 +
    loc.so.obj = SPACESHIP1:CELL1;
 +
    loc.so.par = DOOR_SET_STATUS;
 +
    loc.so.val = DOOR_SETVAL_STATUS_CLOSE;    
 +
    SetObject(loc.so);
 +
 +
    loc.so.obj = SPACESHIP1:CELL2;
 +
    loc.so.par = DOOR_SET_STATUS;
 +
    loc.so.val = DOOR_SETVAL_STATUS_CLOSE;    
 +
    SetObject(loc.so);
 +
 +
    // Set timer to 6 seconds
 +
    do_set_timer(6);
 +
 +
    state.dyn.me.do.state2 = START;   
 +
  }
 +
}
 +
 +
</state_run0>
 +
</syntaxhighlight>
 +
This code opens the doors and then closes them again.
 
</li>
 
</li>
 
</ol>
 
</ol>

Revision as of 15:31, 12 January 2015

In this tutorial we will add some scripting: Give feedback to player, make the doors open when a specific event occurs, let female alien walk by.

  1. We don't want the doors to open automatically. We need to make the doors objects that can be driven by the script.
    Open the /init/story/scenes.dat file and add under data {...} :
    door_objecti CELL1
    {
      rotate   = false; // Door translates
     
      q        = 4.5;  // Open height
      q_min    = 0.0;  // Min height
      q_max    = 6.0;  // Max height
      q_spring = 30.0; // Spring used for opening door
     
      open = true; // Door status
     
      obj_name = "cell1"; // Object in scene that is the door
    }
     
    door_objecti CELL2
    {
      rotate   = false;
     
      q        = 4.5;
      q_min    = 0.0;
      q_max    = 6.0;
      q_spring = 30.0;
     
      open = false;
     
      obj_name = "cell2";
    }

    This will make a door object from the scene object. Now we can also open the door using a script.

  2. Now lets test the doors. Open the /init/story/player/brain/run.dat. This file contains the state code of the player.
    Change the code to this:
    #include "init/std/base/main/brain/code/run.dat"
     
    //-------------------------------------------
     
    <state_run>
     
    case (state.dyn.me.do.state)
    {
      [RUN0] state_run0();
    }
     
    </state_run>
     
    //-------------------------------------------
     
    <state_run0>
     
    case (state.dyn.me.do.state2)
    {
      [NONE]
      {
        // Set timer to 3 seconds
        do_set_timer(3);
     
        state.dyn.me.do.state2 = START;
      }
     
      [START]
      {
        // Wait for timeout
        loc.ts = GetTs();  
        [loc.ts < state.dyn.me.do.ts] return;
     
        // Open doors	
        loc.so.obj = SPACESHIP1:CELL1;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_OPEN;	    
        SetObject(loc.so);
     
        loc.so.obj = SPACESHIP1:CELL2;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_OPEN;	    
        SetObject(loc.so);
     
        // Set timer to 6 seconds
        do_set_timer(6);
     
        state.dyn.me.do.state2 = OPEN;
      }
     
      [OPEN]
      {
        // Wait for timeout
        loc.ts = GetTs();  
        [loc.ts < state.dyn.me.do.ts] return;
     
        // Close doors	
        loc.so.obj = SPACESHIP1:CELL1;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_CLOSE;	    
        SetObject(loc.so);
     
        loc.so.obj = SPACESHIP1:CELL2;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_CLOSE;	    
        SetObject(loc.so);
     
        // Set timer to 6 seconds
        do_set_timer(6);
     
        state.dyn.me.do.state2 = START;    
      }
    }
     
    </state_run0>

    This code opens the doors and then closes them again.