Hello there,
i've been playing around with the tutorial on keyboards and here is a code that i wrote and don't really understand how it works.
If you have a free minute i'd be happy if you could help me out here.
Here is the code:
////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
////////////////////////////////////////////////////////////////////////////
function main();
function enemy();
function spawn_object();
function spam_objects();
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
ENTITY*spaceship;
ENTITY*enemy;
////////////////////////////////////////////////////////////////////////////
function main()
{
level_load("Test1.wmb");
camera.x = -250;
spam_objects();
}
function spam_objects()
{
while (key_w)
{
spawn_object();
wait(10);
}
}
function spawn_object()
{
ent_create("enemy.mdl", vector(0,0,0), enemy);
wait(1);
}
function enemy()
{
while(1)
{
c_move(my, vector(5,0,0), nullvector, GLIDE);
wait(1);
}
}
Now the thing I have a problem with is that pressing w does not create an entity.
Pressing a button should return the value 1. And as long as while receives the value 1 it executes its function over and over again. (which it doesnt)
I've made it work using "on_w" but I really want to understand whats missing here.
Also replacing "while (key_w)" with "while (key_w == 1)" doesn't do anything.
Also writing the following code directly into the main function won't allow me to create an entity using q:
if (key_q == 1)
{
spawn_object();
}
Again, it works just fine if you use on_key...
Any suggestions?
Thanks in advance for your help and have a great weekend.