whole number to decimil conversion

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

whole number to decimil conversion

Post by skadoomer »

Is there any way to convert a whole number (like 32 or 12) to have a decimil place with a 0? (like 32.0 or 12.0)?
User avatar
Ultraviolet
Posts: 1152
Joined: Tue Jul 15, 2003 9:08 pm
Location: PROJECT DETAILS CLASSIFIED.

Post by Ultraviolet »

Seems to me that this shouldn't really be an issue, as all integers are already reals. Do you have a script that is choking where you are trying to use an integer where it wants a real or something like that?
User avatar
Enjay
 
 
Posts: 26936
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Post by Enjay »

How do you mean "convert"? Under what circumstances? Where are you trying to do this?

50
blender81
Posts: 49
Joined: Fri Feb 20, 2004 6:13 pm
Contact:

Post by blender81 »

hudmessage coordinates use the decimal place for format purposes. Here is one way to convert whole numbers to decimals:

variable setup:
int my_variable
my_variable = 16


and in the hudmessage coordinate field:
(my_variable << 16) + 0.1
will result in 16.1

edit: instead of adding 0.1, add 0.0
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Post by skadoomer »

Enjay wrote:How do you mean "convert"? Under what circumstances? Where are you trying to do this?

50
i have setup a healthbar system that measures your health level with a single colored bar, composed of a single pixel in height and 8 pixels in width. It operates similairly to that of megaman, where when you loose health, it removes a corresponding number of "bars" and adds them back in when you obtain health.

i've laid the foundation code, but see this as a potential problem.

This system operates on a sethudsize(640, 480, 0). I'm having a loop draw in, from screenpixels 8-108, (screenheight measurements) the bar along the y axis. Because the healthbar works on the same 100-0 health scale, it uses the diffference in the players health to tell the hudmessage printer how many bars are added/removed. Since this number, gotten from GetActorProperty is a whole number, it will break the hudmesssage printer when trying to derive how large the change to the healthbar will be. Being able to compensate for this by shifting the decimil place will hopefully make this problem just another small hurdle jumped.

I did a rough write up this afternoon, but it hasn't been tested yet so there's no guarentee this will work. Here is what i have so far:

Code: Select all

Script Health_Meter (void)
{
	SetHudSize(640, 480, 0);
	
       int minhealth = 108.0;
       int maxhealth = 8.0;

       int x;
	int diff;
	
	int hud_idmarker;
	int hud_iddiff;

	int healthcomp;
	int lasthealth;

	Setfont("health");
	for(x = minhealth; x > maxhealth - 1; x--)
	HudMessage(s:"A"; 0, x, -1, 16.0, x, 1);

	// Cycle check
	if(!lasthealth)
		 { 
			lasthealth = GetActorProperty(player_tid, APROP_Health);
		 }
	While(healthmod > 0) // the player is still alive
	{
		
		healthcomp = GetActorProperty(player_tid, APROP_Health);
		
		if(healthcomp < lasthealth) // player lost some health, this will be called first since we staart with maximum health in-game
		 {
			diff = lasthealth - healthcomp;
			if(!hud_idmarker)
			 {
				hud_idmarker =  maxhealth;
			 }
			else
			 {
				hud_idmarker = lasthud_marker;
			 }
			hud_iddiff = lastmarker - diff;
			for(x = lasthud_marker; x > hud_iddiff + 1; x--)
			HudMessage(s:" "; 1, x, -1, 16.0, x, 0, 0.1);
			
			lasthealth = GetActorProperty(player_tid, APROP_Health);
			lasthud_marker = hud_idmarker - diff;
	
		 }
	
		else if(healthcomp > lasthealth) //player gained health
		 {
			diff = lasthealth - healthcomp;
			hud_idmarker = lasthud_marker;
			hud_iddiff = lastmarker + diff;
			
			Setfont("health");
			for(x = lasthud_marker; x < hud_iddiff + 1; x++)
			 {
				HudMessage(s:"A"; 0, x, -1, 16.0, x, 1);
				delay(1);
			 }
			lasthealth = GetActorProperty(player_tid, APROP_Health);
			lasthud_marker = hud_idmarker + diff;
		else if(healthcomp == lasthealth)
		 {
			//print(s"health ", d:healthcomp); //debugging message
		 }
		Delay(1);
	}
HudMessage(s:" "; 0, 4, -1, 0.0, 0.0, 1);
Sethudsize(0,0,0);
}
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Post by skadoomer »

blender81 wrote:hudmessage coordinates use the decimal place for format purposes. Here is one way to convert whole numbers to decimals:

variable setup:
int my_variable
my_variable = 16


and in the hudmessage coordinate field:
(my_variable << 16) + 0.1
will result in 16.1

edit: instead of adding 0.1, add 0.0
Can this be used outside of the hudmessage as well? Given the sceneario above, i'd ideally need them to be situated within the for loop that spits off the coordinate locations.
User avatar
Ultraviolet
Posts: 1152
Joined: Tue Jul 15, 2003 9:08 pm
Location: PROJECT DETAILS CLASSIFIED.

Post by Ultraviolet »

Enjay already has a working hudmessage health bar implementation, if you'd like. :P Just click his "WWW" button.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Post by skadoomer »

Ultraviolet wrote:Enjay already has a working hudmessage health bar implementation, if you'd like. :P Just click his "WWW" button.
I'm aware, but i don't like the way that one works. It relies too heavily on blocking the health of the character into incriments of 10 to print a change.
Costja
Posts: 188
Joined: Mon Oct 18, 2004 3:58 pm
Location: Russia, Moscow
Contact:

Post by Costja »

AFAIK

Code: Select all

fixednum = intnum * 1.0
(1.0 = 65536)
User avatar
Galaxy_Stranger
Posts: 1326
Joined: Sat Aug 16, 2003 11:42 pm
Location: Shropshire
Contact:

Post by Galaxy_Stranger »

Can't ACS use Floats or Doubles?

Hmmm, I guess you can't - but you CAN use Modulus: %, which returns a remainder, (ie: .1 or whatever). You could prolly play with that and come up with something.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Post by skadoomer »

HEALTH BAR MOTHERBITCHES!!!!!
User avatar
Bio Hazard
Posts: 4019
Joined: Fri Aug 15, 2003 8:15 pm
Location: ferret ~/C/ZDL $
Contact:

Post by Bio Hazard »

I had a smooth bar script at one time that was accurate down to 1%

I wonder where it went. Evryone seems to still be using these funky section based ones
User avatar
Risen
Posts: 5263
Joined: Thu Jan 08, 2004 1:02 pm
Location: N44°30' W073°05'

Post by Risen »

Bio, I know where it went...

Okay, so I actually rewrote it, and I used it differently... but I might have your demo around somewhere...
User avatar
Galaxy_Stranger
Posts: 1326
Joined: Sat Aug 16, 2003 11:42 pm
Location: Shropshire
Contact:

a;ldsjf;lasjf;lasjfd

Post by Galaxy_Stranger »

Can someone confirm whether or not ACS takes Floats or Doubles?

Is ACS completely compatible with C or is it stripped-down?
User avatar
Grubber
Posts: 1031
Joined: Wed Oct 15, 2003 12:19 am
Location: Czech Republic
Contact:

Post by Grubber »

ACS takes Fixeds :P.
Locked

Return to “Editing (Archive)”