Error CS1501 (No overload for method)

Good Evening everyone,

I’m having some trouble with this lecture on establishing the currency generation of the Star Trophy.
Following the final stage of the lecture, when we are linking both the Defender scripts and the StarDisplay scripts I received the above error code, which highlighted line 15 of the Defender script below:

Below is the StarDisplay script which is also giving CS0103 errors (Though these are not being displayed on the console) for both uses of “amount” and also for the use of “StarText” on line 13:

I believe the problems on the StarDisplay script are the source of the error as previously the Defender script was unable to find the StarDisplay script at all, hence the CS1501 error code. After a few different attempts I think the Defender script is now finding the StarDisplay script after a fashion, but this is not solving the problem and I’m really not even sure what’s gone wrong.

Any help given would be appreciated!

Thanks!

You’re passing the int “amount” to the method AddStars but AddStars in the StarDisplay script doesn’t take in any parameters. In the two uses of “amount” you have in the StarDisplay script there’s no reference to what “amount” is which is why they’re red. You need to declare amount in the method similar to what you’ve done with AddStars in the defenders script.

1 Like

Ok, so I cut away the StarDisplay script and reduced the Defender script to its basic state at the start of the lecture, as shown below:

I have also tested that it is receiving input from the Key frame where the Addstars function is applied. As you can see in the below screenshot below, the amount given by the key frame equals the amount printed in the console. I’m going to try rewriting the StarDisplay script from complete scratch.

I have now followed through the entire lecture again and have not had any problems raise their heads, everything has run smoothly.
If anyone has any insight as to the problems I experienced I would love to hear your thoughts!

Thanks!

1 Like

As per Martyn’s response above. Your method signature wasn’t quite right.

Glad you have it sorted now, good spot @martyn_Stewart.

Your keyframe was fine. This is possibly a little confusing due to having the same method name twice so I’ll reference the class as well.

Your keyframe calls Defender.AddStars and passes it the int, in this case 10. Your Defender.AddStars then calls starDisplay.AddStars(amount) so passes that 10 to it. However StarDisplay.AddStars isn’t expecting to be given a variable so your amount is confusing it, it also doesn’t know what amount is so stars += amount means nothing to it. StarDisplay.AddStars needs a parameter so what you need to have is:

public void AddStars(int amount){
    stars += amount;
    UpdateDisplay();
}

and similarly with StarDisplay.UseStars it also needs the amount as a parameter.

1 Like

Gotcha!
I can see exactly what you mean. I don’t know how I managed to miss that the first time, let alone not spot it when I was trying to figure it out. I guess I got so hung up on the lines that were upset that I developed tunnel vision.

Thanks for helping me get to the bottom of this!

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms