Health Progress Issue [RESOLVED]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Health Progress Issue [RESOLVED]

Post by Epiales »

Hey all,

I've began working on my game again. Actually, just starting completely from scratch. Things have come back to me quickly, but I'm having an issue with the progress bar that shows the health of the player. I have the exact same as the older tutorials, and it works there, but doesn't work on my script. Below is my code.... anyone see anything wrong?

Code: Select all

<?php
$sql = "SELECT * FROM users WHERE id = '$_SESSION[userid]'";
$user_query2 = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query2);
$row = mysqli_fetch_array($user_query2, MYSQLI_ASSOC);
?>
<link rel="stylesheet" href="style/style.css">

<div id="hpointsback">
<?php
echo "<img src='images/hitpoints2.png'>";
?>
</div>
<div id="hpointsfront">
<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
echo "<img src='images/hitpoints1.png' width='$width' height='15' >";
?>
</div>

Code: Select all

#hpointsfront {
	position:absolute;
	left:1500px;
	top:300px;
	width:100px;
	height:15px;
	z-index:1;
}
#hpointsback {
	position:absolute;
	left:1500px;
	top:300px;
	width:100px;
	height:15px;
	z-index:2;
	text-align:left;
}
So you know, this is all it shows in my Google Chrome:
http://gyazo.com/4b0f2cdc6e10c35043a8171cbe57b63a

This is what it shows in Firefox:
http://gyazo.com/44e74f9314bb96f650c12aad3c266222
Last edited by Epiales on Thu Sep 25, 2014 11:29 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 395
Joined: Thu Aug 08, 2013 8:57 am

Re: Health Progress Issue

Post by MikuzA »

The code looks fine so I'm thinking there might be some issues with the data.

Can you
echo $row['hpoints'];
echo $row['maxhp'];
echo $width;

at the end?
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Health Progress Issue

Post by Epiales »

MikuzA wrote:The code looks fine so I'm thinking there might be some issues with the data.

Can you
echo $row['hpoints'];
echo $row['maxhp'];
echo $width;

at the end?
I get 10, 25, and 40....

10 is the hitpoints currently
25 is the max hitpoints
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Health Progress Issue

Post by Epiales »

Okay, I think my problem is that the Green bar that goes up and down with the users Hitpoints is BEHIND the red bar. It's not letting me switch it for whatever reason. grrr :oops:
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 395
Joined: Thu Aug 08, 2013 8:57 am

Re: Health Progress Issue

Post by MikuzA »

Ah, ok I see what you are trying..
What about setting the div-background as the 'back' and just displaying the image aligned left on it?

So that the <div id="hpointsback"><img></div>
And set the div width/height to the exactly same as the image, would that do any good? :-)

Also, I see it kinda wierd it's trying to divide with zero in Firefox :P That's why I thought the data was off..
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Health Progress Issue

Post by Epiales »

MikuzA wrote:Ah, ok I see what you are trying..
What about setting the div-background as the 'back' and just displaying the image aligned left on it?

So that the <div id="hpointsback"><img></div>
And set the div width/height to the exactly same as the image, would that do any good? :-)

Also, I see it kinda wierd it's trying to divide with zero in Firefox :P That's why I thought the data was off..
Yeah, I think the url isn't updating quickly enough lol.... okay, here is what I have and no reason it should be off

Code: Select all

#hpointsback {
	position:absolute;
	margin:5px;
	top:300px;
	width:100px;
	height:15px;
	z-index:1;
}
#hpoints {
	position:absolute;
	margin:5px;
	top:300px;
	width:100px;
	height:15px;
	z-index:2;
	text-align:left;
}
Notice: They should be RIGHT ON TOP OF ONE ANOTHER based on the above css....

here's the php

Code: Select all

<div id= "hpointsback">
<?php
echo "<img src='images/barback.png'>";
?>
</div>
<div id= "hpoints">
<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
echo "<img src='images/hpoints.png' width='$width' height='15' >";
?>
</div>
What it looks like:

Image
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Health Progress Issue

Post by Epiales »

Okay, so it finally udpates lol...

Image

That sure doesn't look like 50/50 to me????
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Health Progress Issue

Post by Epiales »

YAY YIPPEEEEEEEEEEEEEEE!!!

:roll: :roll: :roll: After 50 hours it finally works right LMAO! So frustrating...forgot how frustrating coding was lmao! Thanks for u're help m8 :)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”