- Home /
It is not possible to invoke an expression of type 'int'.
Im calling a variable from another script and added 50 to my CurrentMoney when i destroy the rigidbody , but this comes up ...
Script :
function Start () {
CurrentHealth = MaxHealth;
}
function ApplyDamage (Damage : float) {
if(CurrentHealth < 0){
return;
}
CurrentHealth -= Damage;
if(CurrentHealth == 0){
Destroy( gameObject );
var MoneyScript: MoneyScript = GetComponent(MoneyScript);
MoneyScript.CurrentMoney + 50();
}
}
ive done alot of research for the past half an hour or hour but still cant find any soloution
This bit will cause problems sooner or later:
var $$anonymous$$oneyScript: $$anonymous$$oneyScript = GetComponent($$anonymous$$oneyScript);
$$anonymous$$oneyScript.Current$$anonymous$$oney + 50();
You should ensure that you keep your variable and class names distinct:
var moneyScript: $$anonymous$$oneyScript = GetComponent($$anonymous$$oneyScript);
moneyScript.Current$$anonymous$$oney + 50();
Will also cause problems because it's trying to access a component of the just destroyed game object...
Tanoshimi,
Since 'Destroy' doesn't actually destroy the object until the end of the current frame, it should still work, but it's an interesting thing to note that, since the GameObject will be destroyed, what is the point of incrementing a value on it.
Good catch.
If the health is less that zero, this method returns.
If greater than zero it applies damage, then checks if health is exactly zero to see if it should call Destroy().
i.e. the object is only destroyed if a hit places it at exactly zero health.
Answer by iwaldrop · Dec 18, 2013 at 06:32 AM
The line that reads
MoneyScript.CurrentMoney + 50();
Should read
MoneyScript.CurrentMoney += 50;
See the difference?
Ok.
The parenthesis indicate to the compiler that we're calling a function. Empty parenthesis mean that this function requires no parameters, where things inside the parenthesis are the parameters that the function needs in order to do it's work. Either way, we still need to let the compiler know what parameters we're supplying when we 'Invoke' (there's that word) the function.
An integer is not a function, it's a value. Values don't do any work. You can't pass parameters to a value. Let me know if you are still confused.
No offense meant but if you do not get it, it means you are not where you should be. Your are trying to make a game when you do not know how to use basic program$$anonymous$$g.
Yea i know , its just this one little thing , i know the rest ... nearly kind of :) ... Oh iwaldrop Thank you for the information
Well, if it works out for you, please accept the answer. If not, let us know what the problem is. We like to keep the board relatively tidy here.