Beginner's corner

Top  Previous  Next

Synonyms wdl pointers

A synonym is a container for one or more objects. But why would we need them?

Let’s say that the player enters a dark room and wants to turn on the light by shooting a switch. The switch is on the wall, the light is on the ceiling. We need something to point to the light on the ceiling, because we want to increase its LIGHTRANGE (from 0 to 500). When we place the light source in Wed it receives a name, but that name can’t be used in our actions. We have to define a SYNONYM

SYNONYM lamp_syn {TYPE entity;} // lamp is an entity
var lamp_counter = 1; // 1 for on, 0 for off.

We need to create two actions: one for the switch, the other for the lamp.
We don’t use functions because they don’t appear in Wed's action list

ACTION light_switch
{
       MY.ENABLE_SHOOT = ON; // the switch is sensible at shooting
       MY.EVENT = lamp_on; // triggered when the switch is shot
}

ACTION light_switch will use a gun to trigger the event; lamp_on will be executed if the switch is shot.

ACTION lamp
{
       lamp_syn = ME;
       MY.LIGHTRED = 200; // lamp light colors
       MY.LIGHTGREEN = 200;
       MY.LIGHTBLUE = 150;
}

lamp_syn = ME; means that from now on the lamp is known as lamp_syn in every action and function and responds accordingly. We could even type

lamp_syn.SCALE_X /= 2;

at the console and the lamp will shrink.

function lamp_on () // a different function, but can control the lamp using lamp_syn
{
       if (lamp_counter == 1)
       {
               lamp_syn.LIGHTRANGE = 500; // turn the light on
               lamp_counter = 0; // reset counter
       }
       else
       {
               lamp_syn.LIGHTRANGE = 0; // turn it off
               lamp_counter = 1; // set counter
       }
}

Don’t forget that before using a synonym, you must define it and assign it (to an entity, etc) using SET synonym_name, ME; in entity’s action / function.

 

Vector instructions

This time we are going to use the vec_dist instruction to create a flare effect. The idea is to place a flare sprite somewhere in the level, and control its SCALE depending on the distance between the player and the flare sprite.

var flare_dist = 0; // well store the distance in it

ACTION flare_ok // attach it to the flare sprite
{
       MY.FLARE = ON;
       WHILE (1)
       {
               flare_dist = vec_dist(PLAYER.X, MY.X); // distance between the player and flare
               IF (flare_dist > 2000)
               {
                       flare_dist = 2000; // dont let the flare sprite become extremely big
               }
               MY.SCALE_X = (flare_dist / 300 + 0.1);
               MY.SCALE_Y = (flare_dist / 300 + 0.1);
               IF (flare_dist < 40)
               {
                       SET MY.INVISIBLE, ON; // if too close to the flare, remove it
               }
               ELSE
               {
                       SET MY.INVISIBLE, OFF; // otherwise, make it visible
               }
               WAIT 1;
       }
}

You can choose another expression to change the scale according to your needs; I have used a simple one here.