Most asked questions

Top  Previous  Next

Q: I'd need the code for a camera that allows you to fly freely in the level, and yet use collision detection. Can you help?

A: Attach the action below to your player model. Use the mouse to rotate; press and hold one of the mouse buttons to move.

 

action free_camera

{

   my.invisible = on;

   mouse_mode = 0;

   while (1)

   {

      camera.x = my.x;

      camera.y = my.y;

      camera.z = my.z;

      camera.pan = my.pan;

      camera.tilt = my.tilt;

      my.pan -= 10 * mouse_force.x * time;

      my.tilt += 10 * mouse_force.y * time;

      if (mouse_left == 1)

      {

          move_mode = ignore_passable + glide;

          result = ent_move (vector (10 * time, 0, 0), nullvector); // 10 = speed

      }

      if (mouse_right == 1)

      {

          move_mode = ignore_passable + glide;

          result = ent_move (vector (-10 * time, 0, 0), nullvector); // -10 = speed

      }

      wait (1);

   }

}

 

 

Q: Can you please tell me how can I use my models as a "resource"?

A: Follow these simple steps (you will need A5 pro or A6 pro):

 

- Create a small script file that looks like this and name it resources.wdl (or any other name):

 

bind <guard.mdl>;

bind <warlock.mdl>; // "bind" as many models as you need

 

- Start Wed, place a simple block in the level and assign it the resources.wdl script file (File -> Map properties).

 

- Use File -> Resource and you will see the newly created resources.wrs file inside the current folder.

 

- Use the resource file this way in your script.

 

resource "resources.wrs"; // open the "resources.wdl" file

 

string guard_mdl = "guard.mdl"; // retrieve the guard model from "resources.wrs"

 

starter create_guard_resource

{

  sleep (1); // wait until the level is loaded

  ent_create(guard_mdl, vector(100, 50, 200), null); // create the guard.mdl model at x = 100, y = 50, z = 200 quants

}

 

 

Q: Is there a simple method that would allow me to compute and display the number of frames per second? I can't use the default debugging panel in my game.

A: Use the code below:

 

var fpsec;

var init_frames;

 

starter compute_fpsec()

{

  while (1)

  {

     init_frames = total_frames; // store the initial total_frames value

     sleep (1); // wait for a second

     fpsec = total_frames - init_frames; // get the new total_frames value and subtract init_frames from it

  }

}

 

panel debug_panel

{

  layer = 20;

  pos_x = 50;

  pos_y = 50;

  digits = 10, 10, 3, _a4font, 1, fpsec;

  flags = overlay, refresh, visible;

}

 

 

Q: I'd like to be able to control 200 different actors for my strategy game but I don't like the idea of defining 200 separate pointers for them. What can I do?

A: Use "handle" instead:

 

entity* my_actor;

 

var index = 0;

var actors[200]; // store 200 handles in this array

 

action my_actors

{

  actors[index] = handle(my); // store the handle inside the array

  index += 1; // move to the next actor

  // put the rest of the code for your actors here

}

 

function move_actors_upwards(actor_number)

{

  my_actor = ptr_for_handle(actors[actor_number]);

  my_actor.z += 100;

}

 

function increase_height() // a simple test function

{

  move_actors_upwards(2); // increase the z of the 2nd actor by 100 quants

  move_actors_upwards(32); // increase the z of the 32nd actor by 100 quants

  move_actors_upwards(85); // increase the z of the 85th actor by 100 quants

}

 

on_i = increase_height;

 

 

Q: I need to place many trees at certain positions on my terrain and doing that in Wed takes too long. Is there an alternative method?

A: Place the trees close to their final positions and use the code below. Attach the action named "dummy_tree" to all your trees, build and run the level, and then move the mouse pointer over one of the trees. Use "A", "Z", "S", "X", "D", "C" to set the correct position of the tree, and then write down the 3 values (x, y, z) that appear on the screen and use them in Wed to set the proper coordinates for the tree. Repeat these steps until all the trees are positioned correctly. Oh, and don't forget to use F2 (quick save) and F3 (quick load) in order to save your current position in the level (if you need to).

 

bmap arrow_pcx = <arrow.pcx>;

 

panel entity_pan

{

  pos_x = 0;

  pos_y = 0;

  digits = 50, 10, 5, _a4font, 1, mouse_ent.x;

  digits = 50, 22, 5, _a4font, 1, mouse_ent.y;

  digits = 50, 34, 5, _a4font, 1, mouse_ent.z;

  flags = refresh, visible;

}

 

starter set_tree_coords()

{

  mouse_mode = 2;

  mouse_map = arrow_pcx;

  while (1)

  {

     mouse_pos.x = pointer.x;

     mouse_pos.y = pointer.y;

     if (mouse_ent != null) // entity detected?

     {

         if (key_a == on) {mouse_ent.x += 1 * time;}

         if (key_z == on) {mouse_ent.x -= 1 * time;}

         if (key_s == on) {mouse_ent.y += 1 * time;}

         if (key_x == on) {mouse_ent.y -= 1 * time;}

         if (key_d == on) {mouse_ent.z += 1 * time;}

         if (key_c == on) {mouse_ent.z -= 1 * time;}

     }

     wait (1);

  }

}

 

action dummy_tree // attach this action to all the tree models

{

  my.invisible = off; // put something (anything!) here

}