|
|
Makes no sense!!
#235473
11/07/08 20:41
11/07/08 20:41
|
Joined: Aug 2008
Posts: 218 U.S.
GamerX
OP
Member
|
OP
Member
Joined: Aug 2008
Posts: 218
U.S.
|
Ok i have spent all day on this and it should work it looks perfect to me but everytime it crashes. So heres The code ill explain after it. function move()
{
c_setminmax(me);
set(my,FLAG2);
while(my.x > posa.x)///this crashes!!
{
c_move (my, vector(20 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | IGNORE_FLAG2);
my.pan = 180;
wait(1);
}
}
action test_spawn()
{
while(1)
{
ent_create("ship.mdl",vector(my.x,my.y,ship.z),move);
wait(-5);
}
}
action ship_move()
{
ship = my;
while(1)
{
if (key_w) c_move (my, vector(40 * time_step, 0, 0), nullvector,GLIDE | IGNORE_FLAG2);
if (key_s) c_move (my, vector(-40 * time_step, 0, 0), nullvector, GLIDE | IGNORE_FLAG2);
if (key_d) c_move (my, vector(0 ,-40* time_step , 0), nullvector,GLIDE | IGNORE_FLAG2);
if (key_a) c_move (my, vector(0 , 40* time_step , 0), nullvector,GLIDE | IGNORE_FLAG2);
wait(1);
my.pan = 0; my.tilt= 0; my.roll = 0;
}
}So basically it creates a ship model every 5 seconds and the ship model get the action move() and im trying to make it move while the .x position is greater than posa.x. There is a file included called defines.c that has posa in it it looks like this. ENTITY* enemy;
ENTITY* ship;
ENTITY* pos1;
ENTITY* pos2;
ENTITY* pos3;
ENTITY* pos4;
ENTITY* pos5;
ENTITY* pos6;
ENTITY* pos7;
ENTITY* pos8;
ENTITY* pos9;
ENTITY* pos10;
ENTITY* posa;
ENTITY* posb;
ENTITY* posc;
ENTITY* posd;
action pos1_action()
{
pos1 = my;
}
action pos2_action()
{
pos2 = my;
}
action pos3_action()
{
pos3 = my;
}
action pos4_action()
{
pos4 = my;
}
action pos5_action()
{
pos5 = my;
}
action pos6_action()
{
pos6 = my;
}
action pos7_action()
{
pos7 = my;
}
action pos8_action()
{
pos8 = my;
}
action pos9_action()
{
pos9 = my;
}
action pos10_action()
{
pos10 = my;
}
action posa_action()
{
posa = my;
}
action posb_action()
{
posb = my;
}
action posc_action()
{
posc = my;
}
action posd_action()
{
posd = my;
}there is a block in the level that has the posa action attached to it. But the problem is when i run the script it crashes. Sometimes it crashes in move() and sometimes in test_spawn. However it does work if i put ship.x in referring to the pointer attached to the ship_move function. I have tried changing the names i have tried doing just about everything i know how to. It looks perfectly fine to me and i don't see the problem. It really makes no sense so either it is a bug or it is right in front of my eyes and i am so annoyed i don't see it. So if You see the reason could you help me? I have done all this before (in a different project) and it worked fine. I have been working with GS for a couple of months know on and off and should be able to blow right through this since it is so easy but i must be missing something. I have fixed problems harder than this heck i have helped other people with bigger problems but this one is just so simple it has me beet. Thanks.
Last edited by GamerX; 11/07/08 20:42.
"You may never know what results come of your action, but if you do nothing there will be no result." -Mahatma Gandhi
|
|
|
Re: Makes no sense!!
[Re: GamerX]
#235476
11/07/08 21:06
11/07/08 21:06
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
First initialize all your pointers with NULL, i.e. ENTITY* enemy;
ENTITY* ship = NULL;
ENTITY* pos1 = NULL;
ENTITY* pos2 = NULL;
ENTITY* pos3 = NULL;
//etc. Second change your function move to: function move()
{
c_setminmax(me);
set(my,FLAG2);
while (posa == NULL)
wait(1);
while(my.x > posa.x)///this crashes!!
{
c_move (my, vector(20 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | IGNORE_FLAG2);
// and the rest of your code.Most probably the move action is executed before your pointers were initialized. Common mistake.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Makes no sense!!
[Re: Uhrwerk]
#235478
11/07/08 21:14
11/07/08 21:14
|
Joined: Aug 2008
Posts: 218 U.S.
GamerX
OP
Member
|
OP
Member
Joined: Aug 2008
Posts: 218
U.S.
|
Awsome thanks, didn't even think of that.
"You may never know what results come of your action, but if you do nothing there will be no result." -Mahatma Gandhi
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|