Questions from the forum

Top  Previous  Next

Q: Is there any way to enter some text in Wed's behavior panel using comment tags?

A: Sure, just use a string for that and you'll be set.

 

//entry: Text input example

//help: using a string to display and allow text input here

STRING* my_info_str = "Secret Agent Pie"; // use this string as you desire

 

aum97_questions1

 

 

Q: I would like to know how to terminate all particle and shaders functions before changing the level.

A: Simply set the materials to NULL before loading the new level and stop the while loops that generate the particles. A quick way of implementing these things is listed below.

 

// set loading_new_level to 1 before loading a new level

var loading_new_level = 0;

 

action particle_generator()

{

       while (!loading_new_level)

       {

               generate_particles_here();

               wait (1);

       }

       // the particles won't be generated anymore here

}

 

action entity_shader()

{

       my.material = my.superb_shader;

       while (!loading_new_level) {wait (1);}

       my.material = NULL;

}

 

 

Q: I'm creating a racing game. How can I create smoke particles that are positioned near the exhaust pipe?

A: Here's a simple example.

 

BMAP* smoke_tga = "smoke.tga";

 

ENTITY* car;

 

function fade_smoke(PARTICLE *p)

{

       p.alpha -= 5 * time_step; // fade in the smoke particles

       if (p.alpha < 0)

               p.lifespan = 0;

}

 

function smoke_effect(PARTICLE *p)

{

       p->vel_x = 0.5 - random(1);

  p->vel_y = 0.5 - random(1);

  p->vel_z = 0.5 - random(1);

       p.alpha = 10 + random(20);

       p.bmap = smoke_tga;

       p.size = 2; // 2 gives the size of the smoke particle

       p.flags |= (MOVE);

       p.lifespan = 350; // lifespan for the smoke particles

       p.event = fade_smoke;

}

 

function smoke_startup()

{

       VECTOR temp;

       while (!car) {wait (1);}

  while (1)

  {

         vec_for_vertex (temp, car, 301); // generate smoke from the 301th vertex on the car (use your own number here)

     // create more smoke particles on more powerful computers

     effect (smoke_effect, 5, temp.x, normal); // generate 5 smoke particles each frame

     wait (1);

       }

}

 

action my_car()

{

       car = my;

       // put the rest of your car code here        

}

 

aum97_questions2

 

 

Q: I have several panels with buttons on them. When you click on a button, a new panel with buttons should appear. But after the first panel's buttons are clicked, the subsequent panel's buttons do not respond at all. Can you help?

A: There you go:

 

BMAP* pointer_tga = "pointer.tga";

 

BMAP* panel1_pcx = "panel1.pcx";

BMAP* panel2_pcx = "panel2.pcx";

BMAP* newgame1_pcx = "newgame1.pcx";

BMAP* newgame2_pcx = "newgame2.pcx";

BMAP* quitgame1_pcx = "quitgame1.pcx";

BMAP* quitgame2_pcx = "quitgame2.pcx";

BMAP* start1_pcx = "start1.pcx";

BMAP* start2_pcx = "start2.pcx";

BMAP* previous1_pcx = "previous1.pcx";

BMAP* previous2_pcx = "previous2.pcx";

 

function second_panel();

function exit_game();

function init_game();

function first_panel();

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

PANEL* one_pan =

{

       layer = 15;

       pos_x = 100;

       pos_y = 200;

       bmap = panel1_pcx;

       button(140, 110, newgame2_pcx, newgame1_pcx, newgame2_pcx, second_panel, NULL, NULL);

       button(140, 160, quitgame2_pcx, quitgame1_pcx, quitgame2_pcx, exit_game, NULL, NULL);

       flags = SHOW;

}

 

PANEL* two_pan =

{

       layer = 15;

       pos_x = 100;

       pos_y = 200;

       bmap = panel1_pcx;

       button(140, 110, start2_pcx, start1_pcx, start2_pcx, init_game, NULL, NULL);

       button(140, 160, previous2_pcx, previous1_pcx, previous2_pcx, first_panel, NULL, NULL);

}

 

function second_panel()

{

       while (mouse_left) {wait (1);} // wait until the player releases the left mouse button

       one_pan.flags &= ~SHOW;

       two_pan.flags |= SHOW;

       wait (1);        

}

 

function exit_game()

{

       sys_exit(NULL);        

}

 

function init_game()

{

       beep(); // initialize and start your game here        

}

 

function first_panel()

{

       while (mouse_left) {wait (1);} // wait until the player releases the left mouse button

       two_pan.flags &= ~SHOW;

       one_pan.flags |= SHOW;        

}

 

 

Q: How can I make a countdown timer that will turn into red if its near the end?

A: Here's a simple, fully working example.

 

var countdown_timer = 100; // this timer will run for 100 seconds

 

FONT* arial_font = "Arial#48b";

 

PANEL* timer_pan =

{

       layer = 15;

       digits(200, 120, 4 ,arial_font, 1, countdown_timer);

       flags = SHOW;

}

 

function countdown_startup()

{

       while (1)

       {

               countdown_timer -= time_step / 16;

               countdown_timer = maxv(countdown_timer, 0); // don't allow the timer to go below zero

 

               if (countdown_timer <= 10) // counting down the last 10 seconds? Then let's make the digit red!

                       vec_set(timer_pan.blue, vector(0, 0, 255)); // setting the blue, green, red vector color components

               wait (1);

       }

}

 

aum97_questions3

 

 

Q: How can I make the player return to its initial position when it is eaten by the enemy?

A: The easiest method is to reload the level using a level_load instruction; the regular entities that are placed in the level through Wed will restart their actions and reset their coordinates / position.

 

 

Q: I'd like to have my enemies change their colors to red when the player is coming very close to them.

A: Use this snippet as a base for your code; it moves several balls in random directions and changes their color when the player is in their vicinity.

 

function init_startup() // start with a random sequence of numbers each time

{

       random_seed(0);

}

 

function ball_event()

{

       vec_to_angle (my.pan, bounce);

}

 

action bouncing_enemy()

{

       while (!player) {wait (1);} // wait until the player model is loaded

       my.pan = random(360); // each ball starts with a random pan angle

       // make the ball sensitive to impacts with the level blocks or other entities

       my.emask |= (ENABLE_BLOCK | ENABLE_IMPACT | ENABLE_ENTITY);

       my.event = ball_event;

       set(my, LIGHT); // allow this entity to change its color

       my.green = 0;

       my.blue = 0;

       while(1)

       {

               c_move (my, vector(3 * time_step, 0, 0), nullvector, IGNORE_PASSABLE);

               if (vec_dist(player.x, my.x) < 150) // this ball is really close to the player?

                       my.red = 255; // then let's make it change its color to red

               else // the ball is away from the player

                       my.red = 0; // then let's restore its normal color

               wait(1);

       }

}

 

aum97_questions4

 

 

Q: How can I compare two objects based on their rank? I'd like the one that has a bigger score to win.

A: Here's an example with two barrels that grow vertically by changing their z scale, adding random values to it each frame. The first one that reaches a scale of 10 is the winner.

 

ENTITY* barrel_black;

ENTITY* barrel_red;

 

action black_barrel()

{

       barrel_black = my;

       my.scale_z = 1;

       while (my.scale_z < 10)

       {

               my.scale_z += 0.01 * (1 + random(2)) * time_step;        

               wait (1);

       }        

}

 

action red_barrel()

{

       barrel_red = my;        

       my.scale_z = 1;

       while (my.scale_z < 10)

       {

               my.scale_z += 0.01* (1 + random(2)) * time_step;        

               wait (1);

       }        

}

 

function check_startup() // checks to see which one of the barrels is the winner

{

       random_seed(0); // start with a random sequence of numbers each time

       wait (3); // wait until the level is loaded

       while (1)

       {

               if (barrel_black.scale_z >= 10)

               {

                       printf ("Black Barrel Wins!"); // display a message

                       sys_exit(NULL);

               }        

               if (barrel_red.scale_z >= 10)

               {

                       printf ("Red Barrel Wins!"); // display a message

                       sys_exit(NULL);

               }        

               wait (1);

       }

}

 

aum97_questions5

 

 

Q: I need to display an image when the player touches an object. How do I trigger this?

A: Use this example as a base for your code.

 

BMAP* image_pcx = "image.pcx";

 

PANEL* image_pan =

{

       pos_x = 200;

       pos_y = 100;

       layer = 15;

       bmap = image_pcx;

}

 

function display_image()

{

       // the entity has impacted with the player?

       // we don't want to display the image if the entity has collided with another entity        

       if (you == player)

       {

               my.event = NULL; // make the entity insensitive to other collisions with the player (for now)

               image_pan.flags |= SHOW; // display the image

               while (vec_dist (player.x, my.x) < 200) {wait (1);} // wait until the player moves away from the entity

               my.event = display_image; // the entity is sensitive to impacts again

               image_pan.flags &= ~SHOW; // hide the image until the player collides with the entity again

       }

}

 

action sensitive_entity() // this entity is sensitive to impacts with the player

{

       while (!player) {wait (1);} // wait until the player model is loaded in the level

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY);

       my.event = display_image; // the image is actually a panel

}

 

 

Q: I have noticed that the memory usage for my game is always increasing (I'm using Windows' task manager to track it). Why do this happen and how can I fix it?

A: You are probably creating lots of entities, functions, or particles in a loop that never stops. Start the game, and then press the F11 key; you will be able to track the number of functions, entities, and so on. Here's a faulty piece of code that ent_creates lots of entities; in this case, you would notice the constantly increasing number of entities and functions on the panel.

 

function some_function() // nothing special here, just keeping a while(1) loop running at all times

{

       while (1)

       {

               wait (1);

       }

}

 

function faulty_startup()

{

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

       while (1)

       {

               // this loop creates a new barrel each frame, using more and more memory

               ent_create("barrel.mdl", vector(random(1000), random(1000), random(1000)), some_function);

               wait (1);                

       }

}

 

aum97_questions6