Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Joey, flink, AndrewAMD), 1,226 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Array of entities #252076
02/16/09 10:36
02/16/09 10:36
Joined: Jan 2009
Posts: 57
Slovakia
wolodo87 Offline OP
Junior Member
wolodo87  Offline OP
Junior Member

Joined: Jan 2009
Posts: 57
Slovakia
Hi,
is it possible to create and save entities into an array? I need to create unknown number of entities and name them like name1, name2 etc...for further referencing. I also need to attach to each one an action. (flocking/boid algorithm)

Re: Array of entities [Re: wolodo87] #252078
02/16/09 10:51
02/16/09 10:51
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
yes its possible.. u working on simulation ?

use something like this:
------------------------------

typedef struct
{
ENTITY* entAgent;
int ID;
var variable1;
var variable2;
var variable3;

} structAgent;

structAgent TestAgent[1000];

.......................................

to access each agent.. u can access TestAgent[0].variable1, etc...


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: Array of entities [Re: wolodo87] #252082
02/16/09 11:07
02/16/09 11:07
Joined: Jan 2009
Posts: 57
Slovakia
wolodo87 Offline OP
Junior Member
wolodo87  Offline OP
Junior Member

Joined: Jan 2009
Posts: 57
Slovakia
Thanks, this looks promising. Yes, I am trying to create bird flock simulation for AI. But how can I use this struct with ent_create function. I need something like: when key pressed, create agent, when another key pressed, delete agent with name abc.

Re: Array of entities [Re: wolodo87] #252085
02/16/09 11:18
02/16/09 11:18
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
try someting like this way:
Code:
typede struct AGENT {
INT ID;
ENTITY *p_agentEnt;
STRING *agentName;
} AGENT;

AGENT pAgents[999];
var countAgents = 0;

AGENT* agent_create(STRING *name,) {
   if(name == NULL) {return;} //if no name is given return

   countAgents ++;

   AGENT *p_agent = malloc(sizeof(AGENT)); //create a new agent
   p_agent.ID = countAgents; //set agent-ID
   p_agent.p_agentEnt = ent_create("mdlFileName.mdl", vector(0,0,0), actionName); //create entity
   p_agent.agentName = str_create(name); //set agent-name

   return p_agent;
}

void main() {

   level_load("yourLevel.wmb");
   wait(1);
   pAgents[countAgents] = agent_create("max");
   pAgents[countAgents] = agent_create("john");
   pAgents[countAgents] = agent_create("lisa");
   [...]
}


Re: Array of entities [Re: wolodo87] #252151
02/16/09 20:25
02/16/09 20:25
Joined: Jan 2009
Posts: 57
Slovakia
wolodo87 Offline OP
Junior Member
wolodo87  Offline OP
Junior Member

Joined: Jan 2009
Posts: 57
Slovakia
Thanx to both of you. It is exactly what i wanted.

Thank god for this forum...there is always someone who knows the answer on my endless questions... laugh

Last edited by wolodo87; 02/17/09 13:39.

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