- Home /
Using a variable for decreasing health?
Hello,
I've been programming for a few months in GML and a bit in Actionscript 2, but I haven't figured out how to use the amount of damage as a variable in JavaScript.
It would be really appreciated if someone could help me with this.
var otherobject : String = "something";
var Damage : String = "10";
function OnCollisionEnter(theCollision : Collision)
{
if (theCollision.gameObject.name == otherobject)
{
var Health = - Damage;
}
}
Thanks,
~MoC
Your variable damage is a string, you need an integer. You cannot subtract a value from a word can you? Well same with computer. On the other hand your otherobject should be in " " because there, it is the string na$$anonymous$$g the object. Lastly, var Health = - Damage; is going to store the value of damage in health. I guess you want to subtract the damage from the health and it health-=damage;
Answer by ckfinite · Mar 03, 2012 at 06:49 PM
Try this code:
var otherobject : String = "something";
var Damage : int = 10;
function OnCollisionEnter(theCollision : Collision)
{
if (theCollision.gameObject.name == otherobject)
{
var Health -= Damage;
}
}
Your answer
Follow this Question
Related Questions
Input Field Text string to string variable. (const string) 0 Answers
Variable from String 0 Answers
Set a String Global variable value 2 Answers
Changing a text equal to a string variable 1 Answer
variables as GUI 1 Answer