Click to See Complete Forum and Search --> : Changing Variables.


Burrow
02-08-2003, 06:08 PM
Okay, I am creating a battle system for a friends website, and I have figured out the majority of everything that I need, but I decided about half way into it, that I wanted to reload the variables so that it would be an instantaneous thing rather than a reload of the page further down.

As an example:

<script language="javascript">

(In the head of the document)
var Hit_points: 10
var Max_HP: 10

</script>



Then into the body of the document.

<script language="javascript">

document.writeln("Hit Points:" + Hit_points + "/" + Max_HP);

</script>



Now what I want that to do, is every time he get's hit I want the variable Hit_points to lower without input from my friend.

Is there any way that I can possibly do this, or will I just have to continually reload the page?

Any help is appreciated. Thanks.

BilEde
02-08-2003, 06:40 PM
Quick suggestion.
In the body have the following
<div id="Scores"></div>
in your script have a function you can call
<script>
var score1=10; //for example
var score2=10;

function change scores(num1,num2){
score1+=num1;
score2-=num2;
document.all.Scores.innerHTML="<h2 style='color=red'><b>Your Scores Are 1: " + score1 + " 2: " * score2;
}
This is for Internet Explorer, for netscape 4 will neeed modification, for newer netscape I'm not sure.
The div tag can be places within a table cell if that helps the layout.
This gives the general idea. You should be able to adapt htis to suit your needs.

BilEde
02-08-2003, 06:42 PM
before everyone jumps on me I just noticed I missed the end tag off the script.
here it is: </script>

Burrow
02-08-2003, 06:43 PM
:),

Thanks, That is what I needed. Thanks again.
*runs off to go work*