Questions from the forum

Top  Previous  Next

Q: How can I play several music files in a loop, one after the other?

A: Use the following example.

 

var track_handle;

 

starter game_music()

{

       while (player == null) {wait (1);}

       while (1)

       {

               track_handle = media_play("track1.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               track_handle = media_play("track2.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               track_handle = media_play("track3.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               track_handle = media_play("track4.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               wait (1);

       }

}

 

 

Q: How can I highlight an object in my strategy game by moving the mouse over it?

A: Use this snippet.

 

function highlight_me()

{

       if (event_type == event_touch)

       {

               my.ambient = 100; // highlight the unit

       }

       while (event_type != event_release) {wait (1);}

       my.ambient = 0;

}

 

action my_unit

{

       my.enable_touch = on;

       my.enable_release = on;

       my.event = highlight_me;

}

 

 

Q: How can I run a "while" loop (every frame) for a specified number of seconds?

A: Use this example.

 

function countdown_timer()

{

       var time_passed = 12; // the loop will run for 12 seconds

       while (time_passed > 0)

       {

               time_passed -= time / 16; // decrease time_passed every frame

               // do something useful here for 12 seconds

               camera.ambient = random(100); // now that's useful stuff!

               wait (1);

       }

       // the action would goes on here after 12 seconds

}

 

on_c = countdown_timer; // press "C" to run the function

 

 

Q: How can I create a decent looking torch effect?

A: Use this snippet.

 

bmap fire_tga = <fire.tga>;

bmap smoke1_tga = <smoke1.tga>;

bmap smoke2_tga = <smoke2.tga>;

 

function fire_effect();

function fade_flames();

function smoke_effect();

function fade_smoke();

 

action my_torch

{

       my.passable = on;

       while (1)

       {

               vec_set(temp.x, my.x);

               vec_add(temp.x, vector(random(2) - 4, random(2) - 4, 25 + random(3))); // play with 25

               effect (fire_effect, 10 * time, temp.x, normal); // play with 10

               if (random(1) > 0.85)

               {

                       temp.z += 5 + random(5); // play with 5

                       effect (smoke_effect, 1, temp.x, normal);

               }

               my.lightrange = 200;

               my.lightred = 200;

               my.lightgreen = 150 + random(50);

               my.lightblue = 100;

               wait (1);

       }

}

 

function fire_effect()

{

       temp.x = random(4) - 2;

       temp.y = random(4) - 2;

       temp.z = random(2); // play with 2

       vec_add (my.vel_x, temp);

       my.alpha = 20 + random(80);

       my.bmap = fire_tga;

       my.size = 25; // play with 25        

       my.bright = on;

       my.move = on;

       my.lifespan = 5;

       my.function = fade_flames;

}

 

function fade_flames()

{

       my.vel_x /= 2;

       my.alpha -= 2 * time;

       if (my.alpha < 0) {my.lifespan = 0;}

}

 

function smoke_effect()

{

       temp.x = random(1) - 0.5;

       temp.y = random(1) - 0.5;

       temp.z = random(1); // play with 1

       vec_add (my.vel_x, temp);

       my.alpha = 20 + random(20);

       if (random(1) > 0.7)

       {

               my.bmap = smoke2_tga;

       }

       else

       {

               my.bmap = smoke1_tga;        

       }

       my.size = 20; // play with 20

       my.bright = on;

       my.move = on;

       my.lifespan = 500;

       my.function = fade_smoke;

}

 

function fade_smoke()

{

       my.alpha -= 0.2 * time; // play with 0.2

       if (my.alpha < 0) {my.lifespan = 0;}

}

 

aum54_faq1

 

 

 

Q: Can I play an animated movie (my logo) at the beginning of the game, and then display the main menu?

A: Use this piece of code.

 

var logo_handle;

 

function main()

{

       fps_max = 60; // limit the frame rate to 60 fps

       logo_handle = media_play("logo.avi", null, 100); // play your logo movie

       while (media_playing(logo_handle)) {wait (1);} // wait until the movie has ended

       level_load (mylevel_wmb); // now load the level

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

       mainmenu_pan.visible = on; // don't forget to define this panel first

       // put the rest of the code for function main here

}

 

 

Q: How can I have an object that follows the player at all times? I'd like to be able to specify the distance to the player as well...

A: Use this example:

 

string follower_mdl = <follower.mdl>;

 

function follow_player()

{

       proc_late();

       while (1)

       {

               vec_set (my.x, vector (100, 50, 30)); // play with these values

               vec_rotate (my.x, player.pan);

               vec_add (my.x, player.x);

               my.pan = player.pan; // only if you need this as well

               wait (1);

       }

}

 

 

action player1

{

       player = my; // I'm the player

       ent_create (follower_mdl, my.x, follow_player);

       ................................

}

 

 

Q: I'd like to control the ambient in my game using the mouse wheel. Is this even possible?

A: Sure. Examine the code below.

 

starter set_ambient()

{

       while (1)

       {

               camera.ambient -= 0.2 * mickey.z * time;

               camera.ambient = min (max (camera.ambient, 0), 100); // limit camera.ambient to 0...100

               wait (1);

       }

}

 

 

Q: Do you know of a tool that can create robotic speech?

A: Try the good old SayIt from AnalogX - www.analogx.com

 

 

Q: I want an entity to become "player" if I click on it.

A: Use the following snippet.

 

function become_player()

{

       player = my;

}

 

action potential_player // attach this action to several entities

{

       my.enable_click = on;

       my.event = become_player;

}

 

starter control_player()

{

       while (1)

       {

               if (player != null)

               {

                       player.pan += 1 * time;

               }

               wait (1);

       }

}

 

 

Q: How can I animate a sprite using ent_animate? I can't see the animation frames!

A: Use this example.

 

action animated_sprite // attach this action to a sprite that contains several frames

{

       var anim_speed;

       while (1)

       {

               ent_animate(my, "test", anim_speed, anm_cycle); // put any animation name here ("test", "stand", whatever)

               anim_speed += 5 * time; // "5" controls the animation speed

               wait (1);

       }

}