|
|
|
|
|
|
|
|
SGT_FW
by Aku_Aku. 05/31/26 11:05
|
|
|
|
|
XTB
by pr0logic. 05/18/26 12:27
|
|
|
1 registered members (TipmyPip),
3,688
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
vec_dist has a mind of its own!
#314765
03/10/10 19:52
03/10/10 19:52
|
Joined: Dec 2009
Posts: 361
rtsgamer706
OP
Senior Member
|
OP
Senior Member
Joined: Dec 2009
Posts: 361
|
I am a programmer working with the free version of lite-c. I am making a game where I have an entity called "rbc" this entity is supposed to junp to the its side when it hits an entity called "awd". I used the code:
action rbc_stuff () { if (vec_dist(me.x, awd.x) < 20) { c_move... } }
my probelm is that when I put this code in SED when I run the game it just says "crash in rbc_stuff" the part that makes it weird is if I make it the distance between an different entity called "wbc" then I don't get this error with evey other entity I do... It might be connected to the fact that rbc already has an action using vec_dist with wbc but i don't know.
here are the actions for the other two entitys:
action awd_stuff() { awd = me; c_setminmax(me); }
action wbc_stuff () { wbc = me; c_setminmax(me); var swim = 0; while (1) { if (key_cuu) { c_move (my, vector(0.5, 0, 0), nullvector, GLIDE); ent_animate (my, "vert", swim, ANM_CYCLE); swim += 0.7; } if (key_cuu && key_cur) { ent_animate (my, "diar", swim, ANM_CYCLE); swim += 0.7; } if (key_cud && key_cul) { ent_animate (my, "diar", swim, ANM_CYCLE); swim -= 0.7; } if (key_cud) { c_move (my, vector(-0.5, 0, 0), nullvector, GLIDE); ent_animate (my, "vert", swim, ANM_CYCLE); swim -= 0.7; } if (key_cuu && key_cul) { ent_animate (my, "dial", swim, ANM_CYCLE); swim += 0.7; } if (key_cud && key_cur) { ent_animate (my, "dial", swim, ANM_CYCLE); swim -= 0.7; } if (key_cul) { c_move (my, vector(0, 0.5,0), nullvector, GLIDE); ent_animate (my, "hori", swim, ANM_CYCLE); swim += 0.7; } if (key_cur) { c_move (my, vector(0, -0.5, 0), nullvector, GLIDE); ent_animate (my, "hori", swim, ANM_CYCLE); swim -= 0.7; }
PLEASE HELP! rstgamer706
|
|
|
Re: vec_dist has a mind of its own!
[Re: rtsgamer706]
#314768
03/10/10 20:06
03/10/10 20:06
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
The main problem here is that you cannot tell when which entity exists or rather in what order the entities are created at level start up. So you have to implement a simple check if the entity pointer that you want to use later on in the action is valid. So lets edit this into your rbc action:
action rbc_stuff()
{
while(!awd) { wait(1); } // wait until the awd pointer becomes valid
if(vec_dist(my.x,awd.x) < 20)
{
...
}
}
Note: This might _not_ be the problem if the rbc entity ist definatly created _after_ the awd entity. Next thing that I noticed: The rbc_stuff action does not include a while loop. Thus the vec_dist check is only executed once. After that nothing will happen. So you may need to add this (depending on your game). edit: I don't quite get the following sentence: It might be connected to the fact that rbc already has an action using vec_dist with wbc but i don't know.
What do you mean with "rbc already has an action using ..."?
Last edited by Xarthor; 03/10/10 20:08.
|
|
|
Re: vec_dist has a mind of its own!
[Re: Xarthor]
#314868
03/11/10 17:55
03/11/10 17:55
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
change youre declarations for your entities to ENTITY* awd = NULL; (because "ENTITY* awd;" DOESNT garantee awd is NULL)Then Xarthor's code should work. But my preferrance is this...
ENTITY* awd = NULL;
...
action rbc_stuff ()
{ while(1)
{ if(awd) if(vec_dist(me.x, awd.x)<20)
{ c_move... }
wait(1);
}
}
It may look more complex, but it isnt really. But it is more bulletproof and doesnt get upset if awd 'temporarily' is removed.
Last edited by EvilSOB; 03/11/10 17:57.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|