Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Left over healthbar visible #469445
11/16/17 14:18
11/16/17 14:18
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
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);
		}
		
		
	}
}



Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Left over healthbar visible [Re: Realspawn] #469448
11/16/17 17:18
11/16/17 17:18
Joined: Jul 2014
Posts: 72
D
DriftWood Offline
Junior Member
DriftWood  Offline
Junior Member
D

Joined: Jul 2014
Posts: 72
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.

Re: Left over healthbar visible [Re: DriftWood] #469449
11/16/17 18:00
11/16/17 18:00
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
@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.

Re: Left over healthbar visible [Re: txesmi] #469454
11/16/17 20:21
11/16/17 20:21
Joined: Jul 2014
Posts: 72
D
DriftWood Offline
Junior Member
DriftWood  Offline
Junior Member
D

Joined: Jul 2014
Posts: 72
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.

Last edited by DriftWood; 11/16/17 20:34.
Re: Left over healthbar visible [Re: DriftWood] #469456
11/17/17 00:41
11/17/17 00:41
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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

Re: Left over healthbar visible [Re: txesmi] #469457
11/17/17 02:13
11/17/17 02:13
Joined: Jul 2014
Posts: 72
D
DriftWood Offline
Junior Member
DriftWood  Offline
Junior Member
D

Joined: Jul 2014
Posts: 72
@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.

Re: Left over healthbar visible [Re: DriftWood] #469489
11/18/17 07:40
11/18/17 07:40
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
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;
		}
		
		
	}
}


Last edited by Realspawn; 11/18/17 08:49.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Left over healthbar visible [Re: Realspawn] #469493
11/18/17 12:40
11/18/17 12:40
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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.

Re: Left over healthbar visible [Re: txesmi] #469494
11/18/17 13:23
11/18/17 13:23
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
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.








Last edited by Realspawn; 11/18/17 13:24.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Left over healthbar visible [Re: Realspawn] #469495
11/18/17 13:56
11/18/17 13:56
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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.

Page 1 of 2 1 2

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