Duplicate function definitions issue - pretty urgent


(Tentafool) #1

In the code here I’m currently having a few issues in regards to error 23: duplicate function definitions.

The lines that are the problems 81 and 86, where it says: ‘public function get score():gameScore’ and  ‘public function get score():int’

This is code for a score display in the world, for a game I am making for a college project. I need help on this soon as possible, since it is to be in a week today. Any help appreciated. Thanks in advance!


(David Williams) #2
"public function get score():..."

That’s the problem, you can’t have two functions with the same name. When you call something like

this.x = className.score();

It is unsure which one you’re trying to get due to the duplicate variable names.


(Tentafool) #3

Unfortunately, it hasn’t helped me much.

G:\FLASH\2D GAME DESIGN - Project folder\src\World1.as(81): col: 3 Error: The this keyword can not be used in static methods. It can only be used in instance methods, function closures, and global code.         this.x = className.score();

G:\FLASH\2D GAME DESIGN - Project folder\src\World1.as(83): col: 17 Error: The return statement cannot be used in static initialization code.             return _score;

I have ended up with these two errors as a result of attempting to fix the issue.

EDIT: Hang on. Was I meant to use that code or not? I may or may not have confused myself further as a result…


(David Williams) #4

I was just trying to explain why it was returning the error, not providing code to fix it. Try renaming one of your get-functions.


(Tentafool) #5

I’ll try that now and see what happens. Thanks so far.


(Ultima2876) #6

As a further tip, in the code above you’re getting mixed up with where to put _score and score. It should look something like this

public function get score(): gameScore
{
  return _score;
}

For the get score returning as int; do you need both getters? How do you convert a gameScore object into an int; does that have a function for returning an int? Would it be better to just have the one getter that returns an int? :slight_smile: