whole number to decimil conversion
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.
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.
whole number to decimil conversion
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)?
- Ultraviolet
- Posts: 1152
- Joined: Tue Jul 15, 2003 9:08 pm
- Location: PROJECT DETAILS CLASSIFIED.
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.Enjay wrote:How do you mean "convert"? Under what circumstances? Where are you trying to do this?
50
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);
}
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.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
- Ultraviolet
- Posts: 1152
- Joined: Tue Jul 15, 2003 9:08 pm
- Location: PROJECT DETAILS CLASSIFIED.
AFAIK
(1.0 = 65536)
Code: Select all
fixednum = intnum * 1.0
- Galaxy_Stranger
- Posts: 1326
- Joined: Sat Aug 16, 2003 11:42 pm
- Location: Shropshire
- Contact:
- Bio Hazard
- Posts: 4019
- Joined: Fri Aug 15, 2003 8:15 pm
- Location: ferret ~/C/ZDL $
- Contact:
- Galaxy_Stranger
- Posts: 1326
- Joined: Sat Aug 16, 2003 11:42 pm
- Location: Shropshire
- Contact:
a;ldsjf;lasjf;lasjfd
Can someone confirm whether or not ACS takes Floats or Doubles?
Is ACS completely compatible with C or is it stripped-down?
Is ACS completely compatible with C or is it stripped-down?