Posted: 30th Apr 2023 3:38
If I say this in a open loop

+ Code Snippet
For x=AllEnemys.length to 0 Step -1	
	 AllEnemys[x].Distance=getDistance(GloabPower,AllEnemys[x].ID)
	 print(AllEnemys[x].HitPoints)
	 if AllEnemys[x].Distance<20 
	 dec AllEnemys[x].HitPoints,5
	 endif
next x


Only one enemy looses health, is not the reason for a array to hold information for many objects and there health and other things?
but I find in many, many times there are errors in the array. Here it is being made.

+ Code Snippet
type  Enemys
ID
Image
imageS
imageN
PosX
PosY
posZ
Anim
Power
HitPoints	
HitPointsObject
InBattle
Selected
Hp
Distance
endtype

dim AllEnemys[] as Enemys
global ThisEnemy as Enemys


And here is when I load in my enemies

+ Code Snippet
	// Load character for our enemies
	for x=0 to 1
	ThisEnemy.ID = LoadObjectWithChildren("models\minos\orc.fbx")
	ThisEnemy.Image = LoadImage("models\minos\minos_1_D2.png")
	ThisEnemy.imageS= LoadImage("models\minos\minos_1_S.png")
	ThisEnemy.HitPointsObject=CreateObjectPlane(5,5)
	setobjectimage(ThisEnemy.ID,ThisEnemy.Image ,0)
	setobjectimage(ThisEnemy.ID,ThisEnemy.ImageS,2)
    SetObjectScalePermanent(ThisEnemy.ID,0.3,0.3,0.3)
    RotateObjectLocalY(ThisEnemy.ID,180)
	FixObjectPivot(ThisEnemy.ID)
    SetObjectLightMode(ThisEnemy.ID,1)
    ThisEnemy.PosX=random(2200,2280)
    ThisEnemy.posZ=random(3600,3680)
    ThisEnemy.PosY=GetObjectHeightMapHeight( terrain,ThisEnemy.PosX,ThisEnemy.PosZ)
	SetObjectPosition(ThisEnemy.ID,ThisEnemy.PosX, ThisEnemy.PosY,ThisEnemy.posZ)
	SetObjectPosition(ThisEnemy.HitPointsObject,ThisEnemy.PosX, ThisEnemy.PosY+24,ThisEnemy.posZ)
    SetObjectImage(ThisEnemy.HitPointsObject,HealthImages,0)
    SetObjectTransparency(ThisEnemy.HitPointsObject, 1)
    PlayObjectAnimation(ThisEnemy.ID, "", 1,160, 1, 0.1 ) // idle
    SetObjectAnimationSpeed(ThisEnemy.ID,30)
    ThisEnemy.HitPoints=100
    ThisEnemy.Power=20
    AllEnemys.Insert(ThisEnemy)
   next x


So I do not know why it will not see my other object in the array, It only addresses the one other loaded object.
Posted: 30th Apr 2023 14:20
How are you calculating the distance? And is there a particular reason you are running the for loop in reverse order? Why not just use for x = 0 to AllEnemys.length?

Also, this is unrelated to your question, but you really shouldn't be loading the same image multiple times. Load the image once and re-use it, or you will be wasting a ton of memory if you have a lot of enemies.

+ Code Snippet
global gImageEnemyDiffuse : gImageEnemyDiffuse = LoadImage("models\minos\minos_1_D2.png")
global gImageEnemySpecular : gImageEnemySpecular = LoadImage("models\minos\minos_1_S.png")


then in your enemy loading loop

+ Code Snippet
ThisEnemy.Image = gImageEnemyDiffuse
ThisEnemy.imageS = gImageEnemySpecular


or you could just cut the Image and ImageS properties and use the globals directly in SetObjectImage.
Posted: 30th Apr 2023 22:32
Hi, I know about the image loading, but this was just a test and never got around to change this, thanks for noticing it.

I will try to run it forward, this could be the problem, Ill let you know.

+ Code Snippet
//*******************************************************************************************   
//gets the distance between two objects passed
//*******************************************************************************************   
function getDistance(objectID as integer,objectID2 as integer)
    distance as float
    vec1=CreateVector3(GetObjectWorldX(objectID),GetObjectWorldY(objectID),GetObjectWorldZ(objectID))
    vec2=CreateVector3(GetObjectWorldX(objectID2),GetObjectWorldY(objectID2),GetObjectWorldZ(objectID2))
    distance=GetVector3Distance(vec1,vec2 ) 
    DeleteVector3(vec1)
    DeleteVector3(vec2)
endfunction distance
Posted: 30th Apr 2023 22:48
i never use DIM but are DIM'd arrays Global by default?

&, why DIM and not set a length?
+ Code Snippet
dim AllEnemys[] as Enemys
Posted: 30th Apr 2023 22:57
are DIM'd arrays Global by default?


Yes sir.

why DIM and not set a length?


It is a open array for now till I figure out what goes where and why, I might keep it this way as i am going to load in objects in game, but not enemies.

I always use a open array for testing issues, it is faster and easy as I do not know the amount yet.

I fill the array And it works.

But if I remember, it was you who showed me this way, So I always start out that way.
Posted: 30th Apr 2023 23:06
the method looks familiar but i never used DIM which i thought required a dimension based on the examples (hence why i never use it) while you provide none (i didnt think that would compile - apparently the parameter is optional).

anyway, i'll still never touch DIM. GL!
Posted: 30th Apr 2023 23:28
Perhaps This is why I am having problems,

No, setting a open dimension is ok and I do it all the time as long as you fill that dimension properly, At least that is what I learned.

Well if you never use DIM how would you put a group of enemies into a array you can use? I always want to code better then I know how.

And I also know I always learn form you.
Posted: 30th Apr 2023 23:54
Without using DIM, this is the way I create n objects.

+ Code Snippet
 type tHoloLaser
  LightPolyID as Integer
  GlintObjID as Integer
  TargetObjID as Integer
  MarkerObjID as Integer
 endtype

 global gHoloLaser as tHoloLaser[]

 function CreateHoloLaser(x#,y#,z#)
  Local th as tHoloLaser
 [set all your element properties here]
  gHoloLaser.Insert(th)  
 endfunction

Posted: 1st May 2023 0:34
nz0

Ok I see, so there is no dimensions in it at all, I will try this and see what happens.
Posted: 1st May 2023 0:51
That works and I guess setting the dim was causing problems.

Thank you guys.