Left over healthbar visible

Posted By: Realspawn

Left over healthbar visible - 11/16/17 14:18

Working on a new template simple game. My enemy model uses the healthbar code from aum so the healthbar stays with each enemy.
When the skill =0 the enemy gets removed but it seems tiny pieces of the healht bar keep floating around. Any ideas ?

Code:
#define health skill20
function health_indicator()
{
	ENTITY* ent_owner = you;
	
	set (my, BRIGHT | PASSABLE);
	my.lightrange =60;
	my.ambient = 60;

	while(1)
	{
		
		if (ent_owner)
		{
			vec_set (my.x, ent_owner.x);
			my.z += 15;
			
			my.scale_x = ent_owner.health * 0.2; // skill20 aka "health" stores the health for each entity
			wait (1);
		}
		
		
	}
}

Posted By: DriftWood

Re: Left over healthbar visible - 11/16/17 17:18

Remove bar too..
Code:
while(1)
	{
		
		if (ent_owner)
		{
			vec_set (my.x, ent_owner.x);
			my.z += 15;
			
			my.scale_x = ent_owner.health * 0.2; // skill20 aka "health" stores the health for each entity
			
		}
		else
                 { ent_remove(me); // remove bar 
                 }
		wait (1); // move "while - wait " here

	}
}



Post from mobile check for errors ok.
Posted By: txesmi

Re: Left over healthbar visible - 11/16/17 18:00

@DriftWood
So, certainly, you have to remove entities from the scene in order to remove entities from the scene. I never would have imagined! grin
Unfortunately, your example crashes the same because ent_owner will point to a removed object the same. Engine handles are the way to go with beginners, or the best, no bar action at all.
Posted By: DriftWood

Re: Left over healthbar visible - 11/16/17 20:21

Well, if ent_owner has been removed than it's pointer should be set to NULL.

So simply changing the first if(ent_owner) to if(ent_owner != NULL) , Should fix a crash.
If the local pointer is still set to a value, than ent_remove/ptr_remove has failed as the engine should set it to NULL.

A pointer should not be used as a Boolean anyway.

Unless I'm wrong in something.

Edit - Using the safe_remove macro to remove the owner should fix an error if one still exist because a pointer is still valid.

But can agree that if a beginner doesn't understand pointers they should use handles. Also yes, I would wrap the health bar code right into the owner's action. But Spawn is following the AUM.

I'm am not a beginner lol, I actually forget most the stuff I've learned.
Posted By: txesmi

Re: Left over healthbar visible - 11/17/17 00:41

Originally Posted By: DriftWood
So simply changing the first if(ent_owner) to if(ent_owner != NULL) , Should fix a crash.
If the local pointer is still set to a value, than ent_remove/ptr_remove has failed as the engine should set it to NULL.

I am afraid you are wrong. The engine has no responsability about the variables of your own. It will never change them, as spected. When you declare a pointer in your code it is yours. The object where the pointer points to is another story. ent_owner is a ENTITY* type variable of his own allocated in the stack that contains the address of an entity, no more relation between the pointer and the entity. In fact you can make the pointer point to other entity at any time if desired. When you save the address of an object in a pointer of your own and the object is removed somewhere else, the pointer of your own remains unchanged. In other words, it will never be NULL unless you fill it yourself. It can not be other way. So since the pointer continues pointing to the same address but the object has been removed, it crashes when trying to access to it.

When refered to beginners I was speaking about the target of his template xP
Posted By: DriftWood

Re: Left over healthbar visible - 11/17/17 02:13

@txesmi - Yes indeed. I'm super rusty. You are totally correct. It's the me/you pointers that are set to NULL. I Apologise.

@Spawn wrap it into the owner action like.
Code:
Action owner()
{
 // Owner Stuff 
 stuff ;
 // Hbar stuff
 Entity* ent_hbar = Ent_create(//healhbar modle);
 set (ent_hbar, BRIGHT | PASSABLE);
	ent_hbar.lightrange =60;
	ent_hbar.ambient = 60;
 
 while(my.health > 0)
 {
   // Owner Stuff 
   stuff;
   // Hbar stuff
   if (my.health > 0)
		{
			vec_set (ent_hbar.x, my.x);
			ent_hbar.z += 15;
			
			ent_hbar.scale_x =  my.health *0.2; // skill20 aka "health" stores the health for each entity
		
		}
               
                  
                    
                   
          Wait(1);
         }
ent_remove(ent_hbar);
ent_remove(me);
  }



From mobile, check for errors.
Posted By: Realspawn

Re: Left over healthbar visible - 11/18/17 07:40

thank you guys i will dive into this and see if i can solve it so i can wrap this little game up. I encounter this many times. AUM has scripts that work but clearly sometimes are not the best ways to do things or I am missing stuff to use it the right way laugh



Fixed it changed the script a bit and now when healht is <=0 it is removed completely without errors. a clip can be seen here :

https://youtu.be/--y93hLTipE

Code:
function health_indicator()
{
	ENTITY* ent_owner = you;
	
	set (my, BRIGHT | PASSABLE);
	my.lightrange =60;
	my.ambient = 60;

	while(1)
	{
		
		if (ent_owner)
		{
			vec_set (my.x, ent_owner.x);
			my.z += 15;
			
			my.scale_x = ent_owner.health * 0.2; // skill20 aka "health" stores the health for each entity
			wait (1);
		}
		if(ent_owner.health <=0){
			ent_remove(me);
			break;
		}
		
		
	}
}

Posted By: txesmi

Re: Left over healthbar visible - 11/18/17 12:40

It works lucky of you... but please, for the sake of the candid souls who might take your code as a reliable source of knowledge, don't call it template. I am seriously worried about them. Your code is terribly wrong. Don't you realize that you complain about AUMs free resources while you distribute a pseudo-template thousands of magnitudes worst? Seen is believing. Sincerelly, learn what an engine handle is and stop holding your responsabilities on others.
Posted By: Realspawn

Re: Left over healthbar visible - 11/18/17 13:23

As I always state i am no pro coder and do this purely for the fun of it.
When something works problem free it works isn't that the purpose ?
The solution i have works and has less rescripting then the stuff mentioned laugh


What i ment is that i find it often that people telling a script
from aum is wrong or should be scripted in an otherway so i don't complain about aum but at the remarks in this forum about scripts used from it. The word template does not say it is scripted perfect it says its a working
game without errors that can easy be adapted and changed. And that
is what i aim for.







Posted By: txesmi

Re: Left over healthbar visible - 11/18/17 13:56

Quote:

When something works PROBLEM FREE it works isn't that the purpose ? ... it says its a working game WITHOUT ERRORS that can easy be adapted and changed ...


That is a perfect description of what your code is not. It runs circumstantially because the engine does not overwrite the parents entitys address, not because it is problem free or without errors.
Posted By: Realspawn

Re: Left over healthbar visible - 11/18/17 14:09

Lets hope more people are willing and freely spread actually good SCRIPTED Games then laugh
Posted By: txesmi

Re: Left over healthbar visible - 11/18/17 14:40

More? What for? Sometimes less is more because the average or third parties suffer. But as always, you will continue ignoring honest advices by going through the tangent. In your way.
Posted By: Realspawn

Re: Left over healthbar visible - 11/18/17 16:06

No need to go in defence mode thats what the smilys are for. And for me no need to explain myself over and over again as it seems you have your opinion ready. Were not all the same thank god for that right ? laugh

Although we could use some better then avarage third party givers wink
Posted By: txesmi

Re: Left over healthbar visible - 11/18/17 21:37

Can you see it? You went through the tangent again. I was not as far as you suggested. [smiling facepalm]

I can see you did not get it: The average (subject 1) or (disjunctive conjunction) third parties (subject 2) suffer (verb for both subjects). Suffer because your code is not neither correct, obviously. Don't you mind the hurt you can do by your stubborn unconsciousness? That is my point. Because you sound like a missionary telling the goodness of its acts... grin

A song as my last word.
https://www.youtube.com/watch?v=EEgpPb0DGxM
© 2024 lite-C Forums