Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
Stooq now requires an API key
by VHX. 06/08/26 20:14
ZorroGPT
by TipmyPip. 06/06/26 12:36
Zorro 3.01 recoded MMI function issue
by TipmyPip. 06/04/26 05:44
SGT_FW
by Aku_Aku. 05/31/26 11:05
Issues resuming trades on Demo account
by Martin_HH. 05/22/26 13:31
XTB
by pr0logic. 05/18/26 12:27
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 3,506 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Seraphinang, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
vec_dist has a mind of its own! #314765
03/10/10 19:52
03/10/10 19:52
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

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 Offline
Expert
Xarthor  Offline
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:
Code:
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:
Quote:

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] #314798
03/11/10 00:53
03/11/10 00:53
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
now when I run it it says
Syntax error: while (awd)
what I meant before was that I didn't put all of rbc's action on the forum.
The distance check is in a while (1) loop and in the action I have working
code that is activated when rbc is withing a certain distance from wbc.
Sorry I wasn't clear, please help with the sytax error
rtsgamer706

Re: vec_dist has a mind of its own! [Re: rtsgamer706] #314812
03/11/10 08:48
03/11/10 08:48
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Is the entity pointer "awd" declared _before_ the action rbc_stuff?

Re: vec_dist has a mind of its own! [Re: Xarthor] #314832
03/11/10 12:53
03/11/10 12:53
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
all my entity pointers are the first thing in my code.
(you mean

ENTITY* awd;

right?)

Re: vec_dist has a mind of its own! [Re: rtsgamer706] #314860
03/11/10 16:53
03/11/10 16:53
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Yes thats what I meant.

Hm, I'm not sure what the problem is then.
Could maybe post all relevant code as it is now?
But please use the [ code ] ... [ /code ] tags (without the spaces)

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 Offline
Expert
EvilSOB  Offline
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...
Code:
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
Re: vec_dist has a mind of its own! [Re: EvilSOB] #314875
03/11/10 18:32
03/11/10 18:32
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
I no longer get an error
but no matter where I put it in the action rbc just no longer moves.
I have decided that its really an unimportant part of my game
and to forget about it. There is no need to respond to this relpy.
Thanks for the help anyway though.
rtsgamer706


Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1