- Home /
Calling a function from another script issue
Here's the error I've been getting:
Assets/newstuff/Scripts/Player.js(64,32): BCE0017: The best overload for the method 'Heal.HealHp(Item)' is not compatible with the argument list '()'.
I've looked all around the forum for a solution and none that I've found have worked. Any ideas? An explanation would be great too, thank you :)
Player Script that references the script:
function UseItem(i:Item,slot:int,autoequip:boolean){ if(i.isPotion){ if(autoequip){ findHeal = GameObject.FindWithTag("potion").GetComponent(Heal); findHeal.HealHp(); } } }
and the Heal script being referenced:
var healAmount:int; var maxHealth=400; var curHealth=50; var health=curHealth;
function HealHp(i:Item){ if(i.isPotion){ health=curHealth+healAmount; Destroy(this.GameObject); Debug.Log("Your health is now "+health+" 1 potion has been removed from inventory"); } }
my problem is it isn't calling my other script. almost every other method of writing this I've tried has given me a 'Null Reference Exception'
Answer by KiraSensei · Nov 11, 2012 at 11:56 AM
Your function HealHp needs one argument i. In your function UseItem you call HealHp without argument, you need to add an item in it. You should have :
findHeal.HealHp(i);
instead of :
findHeal.HealHp();
oh wow thank you :) of course it'd be something so simple.