Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Hey all, you may remember me asking a question regarding a snake game I was creating about two weeks ago.

Well I'm quite far now into making the game (thanks to a brilliant tutorial I found). But I've come across the error described named above.

So heres my problem;

I have a SnakeFood class that has a method called "Reposition". In the game1 class I have a method called "UpdateInGame" which calls the reposition method to load an orange that spawns in a random place every second.

My latest piece of code changed the reposition method to allow the snake I have on the screen to not be overlapped by the orange that randomly spawns.

Now I get the error (in full):

Error 1 Inconsistent accessibility: parameter type 'TheMathsSnakeGame.Snake' is less accessible than method 'TheMathsSnakeGame.SnakeFood.Reposition(TheMathsSnakeGame.Snake)' C:\Users\Tom\Documents\Visual Studio 2008\Projects\TheMathsSnakeGame\TheMathsSnakeGame\SnakeFood.cs 33 21 TheMathsSnakeGame

I understand what the errors trying to tell me but having changed the accessiblity of the methods, I still can't get it to work.

Sorry about the longwinded question.

Thanks in advance :)

Edit: Code I'm using

 (Game1 Class)
private void UpdateInGame(GameTime gameTime)
    {
        //Calls the oranges "reposition" method every second
        if (gameTime.TotalGameTime.Milliseconds % 1000 == 0)
            orange.Reposition(sidney);
        sidney.Update(gameTime);
    }

(SnakeFood Class)
 public void Reposition(Snake snake)
    {
        do
        {
            position = new Point(rand.Next(Grid.maxHeight),     rand.Next(Grid.maxWidth));
        } while (snake.IsBodyOnPoint(position));
    }
share|improve this question
    
Some example code will help. –  Ray Dey Feb 19 '11 at 14:06
    
Theres too much code to copy and paste, would you like me to copy and paste the code spoken of above? –  user5141 Feb 19 '11 at 14:11
    
You don't have to copy and paste everything, just the appropriate code that you're having issues with. –  Ray Dey Feb 19 '11 at 14:20

1 Answer 1

The accessibility levels of C# are public > protected > internal > protected internal > private. Your class' accessibility must by >= to the accessibility of the methods it contains.

share|improve this answer
2  
+1. meaning you have a variable: TheMathsSnakeGame.Snake. This is an instantiation of some class. Make that class a public class so it's ok to pass any instantiated objects of that class as params to other class' public methods (i.e. .Reposition()) –  Steve H Feb 19 '11 at 14:38
    
Thank you Steve, I've just made the Snake class public instead of its default (which is private?) and it has worked :D Thank you! :) –  user5141 Feb 19 '11 at 14:49
1  
internal is the default access modifier, when none is specified (msdn.microsoft.com/en-us/library/ms173121.aspx) –  Ray Dey Feb 19 '11 at 17:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.