Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, Kingware, AemStones, RealSerious3D), 1,388 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
HOW: Multiple Entities on ONE path #134869
06/09/07 05:19
06/09/07 05:19
Joined: Sep 2006
Posts: 106
FairyLand!!!
RruthH Offline OP
Member
RruthH  Offline OP
Member

Joined: Sep 2006
Posts: 106
FairyLand!!!
Hey ppl,

I waz wonderin' how to code multiple entities and assign them to one path.
I already have my action code. Made it w/ the help of Kinji's Pathfinding tutorial. (great tut btw ). But when assigning it to more than one entity, only one follows the path and the other one doesn't move/do anything.

Here's my code:
Code:

action truck
{
wait(1);
move_truck();

////////// attach entity to nearest path
result = path_scan(me,my.x,my.pan,vector(360,180,1000));
if (result == 0) { return; }
if(result) { switch = 1; }

///////////////get 1st node on path
path_getnode(my,1,pos_node,null);
vec_to_angle(my.pan,vec_diff(temp,pos_node,my.x));

while(1)
{
wait(1);
distance = vec_dist(my.x,pos_node);
if(distance < 25)
{
switch = off;
node = path_nextnode(my,node,1);
path_getnode(my,node,pos_node, null);
vec_to_angle(my.pan,vec_diff(temp,pos_node,my.x));
wait(1);
switch = 1; // start moving again
}
}
}

/////////////////////////////////

function move_truck()
{
while(1)
{
wait(1);
if(switch == 1)
{
c_move(truck_ent,truck_speed,nullvector,IGNORE_YOU|GLIDE);
}
ent_animate(my,"frame",path_anim_speed,anm_cycle);
path_anim_speed += 3 * time;
path_anim_speed %= 100;
}
}



Any idea how to make multiple entities follow a single path
using this action?

Thanks!

Re: HOW: Multiple Entities on ONE path [Re: RruthH] #134870
06/09/07 15:30
06/09/07 15:30
Joined: Sep 2003
Posts: 281
Arkansas\USA
raiden Offline
Member
raiden  Offline
Member

Joined: Sep 2003
Posts: 281
Arkansas\USA
You need to use skills for all the variables in your code. This way each object uses it's own copy of the variable.

If you need an example let me know.

-raiden


"It doesn't matter if we win or lose, it's how we make the game."
--------------------
Links: 3DGS for Dummies
Re: HOW: Multiple Entities on ONE path [Re: raiden] #134871
06/09/07 15:36
06/09/07 15:36
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline
User
tompo  Offline
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
or use define to nodes or put var inside function
I've made this with second solution and it works


Never say never.
Re: HOW: Multiple Entities on ONE path [Re: tompo] #134872
06/10/07 05:47
06/10/07 05:47
Joined: Sep 2006
Posts: 106
FairyLand!!!
RruthH Offline OP
Member
RruthH  Offline OP
Member

Joined: Sep 2006
Posts: 106
FairyLand!!!
Ok I will try both solutions. Thanks for the help!

Re: HOW: Multiple Entities on ONE path [Re: RruthH] #134873
06/11/07 12:01
06/11/07 12:01
Joined: Sep 2006
Posts: 106
FairyLand!!!
RruthH Offline OP
Member
RruthH  Offline OP
Member

Joined: Sep 2006
Posts: 106
FairyLand!!!
Oh no...
Mine doesn't seem to work,
Even tho i've used DEFINE.
Still trying to fix it.

@raiden
If you have time, I'd like to see that example code please...
Thanks very much!!!

Re: HOW: Multiple Entities on ONE path [Re: RruthH] #134874
06/11/07 15:46
06/11/07 15:46
Joined: Sep 2006
Posts: 106
FairyLand!!!
RruthH Offline OP
Member
RruthH  Offline OP
Member

Joined: Sep 2006
Posts: 106
FairyLand!!!
But I think I did it right.
Here's my code.

Code:
  


action car
{
my.scale_x = 0.292;
my.scale_y = 0.292;
my.scale_z = 0.292;

var node = 1;
var node_pos[3];
var distance;
/////////////////////////////////////
// my.node = 1;
my.passable = on;

result = path_scan(my,my.x,my.pan,vector(360,180,1000));
if(result == 0){return;}

fade_in();
move_car();
///////////////////////////////////

path_getnode(my,1,node_pos,null);
vec_to_angle(my.pan,vec_diff(temp,node_pos,my.x));

while(1)
{
wait(1);
distance = vec_dist(my.x,node_pos);

if(distance < 25)
{
node = path_nextnode(my,node,1);
path_getnode(my,node,node_pos,null);
vec_to_angle(my.pan,vec_diff(temp,node_pos,my.x));
wait(1);
}

if(node >= 11)
{
fade_out();
return;
}
wait(1);
}
}



Then I use this action to make countless numbers of cars every 10 seconds:

Code:
 
action car_creator
{
my.passable = on;
my.invisible = on;
while(1)
{
ent_create("car1.mdl",my.x,car);
sleep(5);
}
}



However, not one of the generated cars follow the path. The cars just
move straight. Not following paths or anything.

Have I missed something?
I really need to fix this. Thanks!

Re: HOW: Multiple Entities on ONE path [Re: RruthH] #134875
06/11/07 16:40
06/11/07 16:40
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline
Expert
Error014  Offline
Expert

Joined: Jul 2002
Posts: 3,208
Germany
Quote:

But I think I did it right.




OBJECTION!

OHNO STRIKE BACK!

Judge agrees!

Okay, thats enough.

Let's have a look at your function that moves the entities. It's called "move_car".

Whoa!

(Okay, I'm really done now)

Specifically, this part:

Code:

if(switch == 1)
{
c_move(truck_ent,truck_speed,nullvector,IGNORE_YOU|GLIDE);
}



Here, we have some things that I don`t like. And all in this short piece of code!

At first, it only moves as long as "switch" is equal to one. You likely have a variable called "switch" SOMEWHERE in your code - if its not set to 1, it won't work at all. Maybe you should make this a flag? Like this.

Code:

if(my.flag1 == on) {
... REST GOES HERE



This has some advantages: For example, you can now stop the cars individually and not just all at once. You can also combine that with your general swtich-variable, then you can stop them all at once (set switch to something other than 1) or just stop them by switching their flag1 to off.

Note though that you have to put the line "my.flag1 = on;" into the action of your trucks now.

Okay, I guess I won't be done for quite a while

So then. What else don't I like?

If you look at the c_move-instruction, you can clearly see that it only moves "truck_ent". That is a pointer. Pointer a magical beings full of HATE AND PAIN. Actually, they're quite neat. They point to things: In this case, they point to whatever entity we want to move. Who is it, then?

OH NO!

See? There is no line like "truck_ent=me;" anywhere in your code. Well, maybe it is in your fade_in-function, but I doubt that. So there.

Due to the fact that you call this from the entities' action, it would make sense to move the entity that originally called that function. We can simply use "me" here. No, not me, the pointer, of course!

Code:

c_move(me,truck_speed,nullvector,IGNORE_YOU|GLIDE);



The last thing that I don't like is "truck_speed". We expect a vector here, which states how to move that entity (you know... forward? Upwards?). You have to define it somewhere! Again, you could make this a skill of an entity or you could be superlazy and do this

Code:

c_move(truck_ent,vector(25*time_step,0,0),nullvector,IGNORE_YOU|GLIDE);



It's much, much, much better this way, because now there is a "time_Step" in there. This guarantees the same behaviour on different machines - otherwise, your truck would move faster on faster computers!


Thats all that I saw, but I haven't looked that long at your code, so maybe I missed something. Tell me if it works!

It is also true that I mainly did this post because I finally could use that Objection-site.


Also:

Quote:

...numbers of cars every 10 seconds:



Quote:

sleep(5);




OBJECTION!

Last edited by Error014; 06/11/07 16:42.

Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: HOW: Multiple Entities on ONE path [Re: Error014] #134876
06/12/07 04:27
06/12/07 04:27
Joined: Sep 2006
Posts: 106
FairyLand!!!
RruthH Offline OP
Member
RruthH  Offline OP
Member

Joined: Sep 2006
Posts: 106
FairyLand!!!
Quote:

But I think I did it right.




Ok I take that back.

Phoenix Wright! That's my favorite!
.....
....
...
..
.

OOMMGGG!!! IT WORKS!!! O_O Can't believe it! O_O Wooow!!
Alas, I have working code!!!

Thanks very much Error014!!! Tnx to all!

Woooo lets celebrate!



offtopic:
@Error014
How'd you use Franziska on the Objection Site? what's the secret code?
EDIT:
nvrmind...got it. tnx

Last edited by RruthH; 06/12/07 06:38.

Gamestudio download | chip programmers | 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