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
3 registered members (NnamueN, Akow, 1 invisible), 1,421 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Managing 40 created entities #248895
01/29/09 21:13
01/29/09 21:13
Joined: Jan 2009
Posts: 86
Brasil - RS
D
DiegoFloor Offline OP
Junior Member
DiegoFloor  Offline OP
Junior Member
D

Joined: Jan 2009
Posts: 86
Brasil - RS
Hi!

I have an entity that creates other 40 entities. But the problem is that there's no way to differentiate them, to manipulate each one individually. I tried associating a function, instead of an action, to the created entities, so I can sue it as some sort of tag. But it's not possible to call the function when creating the entity.

Maybe with the code will be easier to understand. Bellow are the action of the pivot entity, and the function associated with the newly created entities.

Code:
action pivot()
{
	VECTOR finalvector;
	VECTOR tempvector;
	var i = 0 ;
	var j = 0 ;	

	phent_settype (me, PH_RIGID, PH_SPHERE); //physics..
	phent_setmass (me, 3, PH_SPHERE);
	phent_setfriction (me, 80);
	phent_setdamping (me, 40, 40);
	phent_setelasticity (me, 100, 50);

	//adjusting the position for the new entity
	vec_set (tempvector , vector(0,0,100));
	vec_set (finalvector, tempvector);
	vec_add (finalvector, my.x);
	
	ent_create ("triang.mdl", finalvector, pontosmoveis); //first (top) triangle created

	//adjusting position again
	vec_rotate(tempvector, vector(0,180,0));
	vec_set (finalvector, tempvector);
	vec_add (finalvector, my.x);  
	
	ent_create ("triang.mdl", finalvector, pontosmoveis); //bottom triangle created
	
	//the following loop creates all the triangles left
	while (i<5)
	{
		i+=1;
		vec_rotate(tempvector, vector(0,30,0));
		vec_set (finalvector, tempvector);
		vec_add (finalvector, vector(my.x, my.y, my.z));  
		while (j<8)
		{
			j +=1;
			ent_create("triang.mdl", finalvector , pontosmoveis);
			vec_rotate(tempvector,vector(45 ,0 ,0));
			vec_set (finalvector, tempvector);
			vec_add (finalvector, vector(my.x, my.y, my.z));  
		}
		j=0;
	}	
}


function pontosmoveis(indice)
{		
	VECTOR range;
	vec_set(range, vector(-10,10,0));	
	
	phent_settype (me, PH_RIGID, PH_SPHERE);
	phent_setmass (me, 1, PH_SPHERE);
	phent_setfriction (me, 80);
	phent_setdamping (me, 40, 40);
	phent_setelasticity (me, 50, 20);
	
	pivotobj = phcon_add(PH_SLIDER, me, you); //pivotobj is a previously defined pointer
	phcon_setparams2(pivotobj, range, nullvector, nullvector);
	
	while(1)
	{
		if(key_z)
		{
			vec_set(strength, vector(1000,10000,0));
		}		
		
		if(key_x)
		{
			vec_set(strength, vector(-1000,10000,0));
		}
		
		if(!key_z && !key_x)
		{
			vec_set(strength, vector(0,0,0));
		}
		
		phcon_setmotor(pivotobj, strength, nullvector, nullvector);
		phcon_setmotor(pivotobj, strength, nullvector, nullvector);
		
		wait(1);
	}	
}


edit: There's another problem I forgot to mention! Aparently, this lines:
phcon_setmotor(pivotobj, strength, nullvector, nullvector);
phcon_setmotor(pivotobj, strength, nullvector, nullvector);
Only influence the last entity created.

Last edited by DiegoFloor; 01/29/09 21:16.
Re: Managing 40 created entities [Re: DiegoFloor] #248897
01/29/09 21:19
01/29/09 21:19
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline
Member
yorisimo  Offline
Member
Y

Joined: Mar 2007
Posts: 197
You can make pointers to your entities.

ENTITY* TriangleEnt[40];

TriangleEnt(j) = ent_create("triang.mdl", finalvector , pontosmoveis);


Joris Lambrecht
My Contributions: Relative Rotation, Window Sizing
Re: Managing 40 created entities [Re: yorisimo] #248898
01/29/09 21:25
01/29/09 21:25
Joined: Jan 2009
Posts: 86
Brasil - RS
D
DiegoFloor Offline OP
Junior Member
DiegoFloor  Offline OP
Junior Member
D

Joined: Jan 2009
Posts: 86
Brasil - RS
I can create a array/entity? cool! smile

Re: Managing 40 created entities [Re: DiegoFloor] #248913
01/30/09 00:07
01/30/09 00:07
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

You can give each entity a number in skill[5] in WED
Then in your code
If (skill[5] == 2) .....


Ottawa smile

Re: Managing 40 created entities [Re: Ottawa] #248916
01/30/09 00:49
01/30/09 00:49
Joined: Jan 2009
Posts: 86
Brasil - RS
D
DiegoFloor Offline OP
Junior Member
DiegoFloor  Offline OP
Junior Member
D

Joined: Jan 2009
Posts: 86
Brasil - RS
Thanks! My problem is solved :]

I have another problem.. not sure if I start another topic to ask this but, I can't change the friction value of triangle[i]! Weird..
In the entity's action, I set up the pointer:
...
triangle[k] = me; //k is a global variable
pivotobj[k] = phcon_add(PH_SLIDER, me, you);
...

And inside a function (executated in main) I have:
...
phcon_setmotor(pivotobj[i], strength, nullvector, nullvector); //This one works!
phent_setfriction (triangle[i], friction_value); //this is the problematic line
...

When the code is running I get a message saying "empty pointer in main".

Re: Managing 40 created entities [Re: DiegoFloor] #248987
01/30/09 17:59
01/30/09 17:59
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
I think the entity is not exist already if you call the problematic line. Set a "wait(-3);" before, maybe it helps...


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