Gamestudio Links
Zorro Links
Newest Posts
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
1 registered members (AndrewAMD), 1,577 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
get far entity from detected opponent #120131
03/29/07 20:34
03/29/07 20:34
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Hi again !

1 - Now i have saved in the skill my._ds_OpponentClosestDIST the distance between my and the closest opponent;

2 - And i want to iterate all the entities list and return which entity is the ds_MOST_FREE_ENTITY, i mean, which entity is far away from the closest opponent;

3 - Its not working and my eyes are burning today;

Code:


function test_ITERATE_ENTITIES()
{
var iDist;
var i;
you = 0;
while( i < ds_numberOfEntities)
{
if(ds_scan_array_list[i] == 0)
{
i += 1;
continue;
}
temp_ITERATE_ENT = ptr_for_handle(ds_scan_array_list[i]);
i += 1;

if(!temp_ITERATE_ENT)
{
continue;
}
if(my._ds_OpponentClosestDIST > iDist)
{
you = temp_ITERATE_ENT;
iDist = my._ds_OpponentClosestDIST;
}
}
ds_MOST_FREE_ENTITY = you;
return (iDist);
}




Thanks for your time.

Re: get far entity from detected opponent [Re: demiGod] #120132
03/29/07 22:25
03/29/07 22:25
Joined: Jul 2004
Posts: 1,205
Greece
LarryLaffer Offline
Serious User
LarryLaffer  Offline
Serious User

Joined: Jul 2004
Posts: 1,205
Greece
Hello demiGod,

You were so close.. A little bit more, and you'd figure this out yourself . But oh well, here you go..

Code:

function test_ITERATE_ENTITIES()
{
var iDist;
var i;
you = 0;
while( i < ds_numberOfEntities)
{
if(ds_scan_array_list[i] == 0)
{
i += 1;
continue;
}
temp_ITERATE_ENT = ptr_for_handle(ds_scan_array_list[i]);
my=temp_ITERATE_ENT;

i += 1;

if(!temp_ITERATE_ENT)
{
continue;
}
if(my._ds_OpponentClosestDIST > iDist)
{
you = temp_ITERATE_ENT;
iDist = my._ds_OpponentClosestDIST;
}
}
ds_MOST_FREE_ENTITY = you;
return (iDist);
}




You just never defined my, and suddently you use it to compare distances. You can skip that temp entity pointer all together, and just use my instead.


Note, that continue; is not a very safe command, and should only be used when absolutely nessecery (it's very much similar to the very hatred GOTO command from the Basic language. It can lead to errors if you're not very carefull).


I re-wrote your algorithm without using continue. If these are your first steps into coding, better get it right from the start, than having to correct bad habits later on..

Code:

function test_ITERATE_ENTITIES()
{
var MaxDist;
var i;

while (i<ds_numberOfEntities)
{
if (ds_scan_array_list[i])
{
my=ptr_for_handle(ds_scan_array_list[i]);
if (my)
{
if (my._ds_OpponentClosestDIST>MaxDist)
{
ds_MOST_FREE_ENTITY=my;
MaxDist=my._ds_OpponentClosestDIST;
}
}
}

i+=1;
}

return(MaxDist);
}




Good luck with your AI.

Cheers,
Aris



INTENSE AI: Use the Best AI around for your games!
Join our Forums now! | Get Intense Pathfinding 3 Free!
Re: get far entity from detected opponent [Re: LarryLaffer] #120133
03/29/07 22:44
03/29/07 22:44
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Yeap, today its not my day..

Thanks again Larry, now it works it was the my pointer assignment.
Sometimes the easiest things are actually the hard ones to see.

Well, about the AI i hope i will handle such a task, too much math here..

Thank you again.
Cheers.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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