2 registered members (7th_zorro, dr_panther),
724
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
problem with "magnetfield-code"
#347974
11/21/10 15:31
11/21/10 15:31
|
Joined: Dec 2009
Posts: 53
Vyshess
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 53
|
I`m working on a little "Magnet-Game". So I was trying out the Code from AUM74. It works fine except one error message. Every time my player detected a magnet-entity the message " invalid call in event got_scanned" appears. Okay, then I was debbuging my Code. The error comes always after this line:
c_move (my, vector(6 * time_step, 6 * time_step, 6 * time_step), nullvector, GLIDE);
But why? And if i klick ok, the error-message disappears and i can play(the magnets working good). But why this message if it works fine after that?? Here the "magnet-code":
action player_move()
{
...//movement code
c_scan(my.x, my.pan, vector(360, 180, 200), IGNORE_ME);
}
function got_scanned()
{
my.event = NULL; // the entities will follow the magnet from now on
VECTOR temp_pos;
while (1)
{
if (vec_dist (player.x, my.x) > 100) // the object isn't close enough to the magnet?
{
vec_set(temp_pos, player.x);
vec_sub(temp_pos, my.x);
vec_to_angle(my.pan, temp_pos);
// the entity is oriented towards the magnet here
c_move (my, vector(6 * time_step, 6 * time_step, 6 * time_step), nullvector, GLIDE); //AFTER THAT THE ERROR APPEARS
}
wait (1);
}
}
// the entities that have this action attached to them are sensitive to the magnet entity
action sensitive_ents()
{
my.emask |= ENABLE_SCAN; // make this entity sensitive to scanning
my.event = got_scanned;
}
thx for help!
A8 Commercial A5 Standart --------------- created games: - Bomber Maniacs
|
|
|
Re: problem with "magnetfield-code"
[Re: Pappenheimer]
#348027
11/21/10 22:15
11/21/10 22:15
|
Joined: Dec 2009
Posts: 53
Vyshess
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 53
|
nope, that doesn`t works. the error appears again...
A8 Commercial A5 Standart --------------- created games: - Bomber Maniacs
|
|
|
Re: problem with "magnetfield-code"
[Re: Vyshess]
#348047
11/22/10 07:30
11/22/10 07:30
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
This works great (TESTED):
function main()
{
fps_max = 75;
level_load("1.WMB");
wait(3);
}
function got_scanned()
{
my.event = NULL; // the entities will follow the magnet from now on
VECTOR temp_pos;
wait(1);
while (1)
{
if (vec_dist (player.x, my.x) > 50) // the object isn't close enough to the magnet?
{
vec_set(temp_pos, player.x);
vec_sub(temp_pos, my.x);
vec_to_angle(my.pan, temp_pos);
my.tilt = 0;
// the entity is oriented towards the magnet here
c_move (my, vector(3 * time_step, 0, 0), nullvector, GLIDE);
}
wait (1);
}
}
// the entities that have this action attached to them are sensitive to the magnet entity
action sensitive_ents()
{
my.emask |= ENABLE_SCAN; // make this entity sensitive to scanning
my.event = got_scanned;
}
action my_magnet() // attach this action to your entity
{
player = my; // I'm the player
while (1)
{
// move the player using the cursor keys
c_move (my, vector(10 * (key_cuu - key_cud) * time_step, 6 * (key_cul - key_cur) * time_step, 0), nullvector, GLIDE);
vec_set (camera.x, player.x); // use player's x and y for the camera as well
camera.z += 500; // place the camera 500 quants above the player on the z axis
camera.tilt = -90;
// make the magnet active on a radius of up to 200 quants around it
c_scan(my.x, my.pan, vector(360, 180, 200), IGNORE_ME);
wait (1);
}
}
And make sure that in WED player was created first! If you'll need I can upload the demo. Good luck.
|
|
|
Re: problem with "magnetfield-code"
[Re: 3run]
#348118
11/22/10 19:53
11/22/10 19:53
|
Joined: Dec 2009
Posts: 53
Vyshess
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 53
|
Thanks 3run (maybe you saved my day)!! yeah, your code works good, but is it possible to make the player moving to the magnet-entity and not the magnet-Entity to the player?? I was given the Magnet-Entity the scan part, and the player got the event "got_scanned()". I have problems with this part:
if (vec_dist (player.x, my.x) > 50) // the object isn't close enough to the magnet?
{
vec_set(temp_pos, player.x);
vec_sub(temp_pos, my.x);
vec_to_angle(my.pan, temp_pos);
my.tilt = 0;
// the entity is oriented towards the magnet here
c_move (my, vector(3 * time_step, 0, 0), nullvector, GLIDE);
}
I know that i have to replace "player.x", but what can i use? i think "you.x" will create a crash. Maybe a pointer for the magnet-Entity?? But then i can only use one magnet in a level, can`t I ?
A8 Commercial A5 Standart --------------- created games: - Bomber Maniacs
|
|
|
Re: problem with "magnetfield-code"
[Re: 3run]
#348268
11/24/10 17:09
11/24/10 17:09
|
Joined: Dec 2009
Posts: 53
Vyshess
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 53
|
I got it!! It wasn`t so triky^^
Thanks for your Help!
A8 Commercial A5 Standart --------------- created games: - Bomber Maniacs
|
|
|
|