Keyword 'void' cannot be used in this context

I have tried a lot of things, but still i can not solve the problem.
The error is "Keyword ‘void’ cannot be used in this context (37,28) "

I apologize for keeping you busy.

here is my code

Hi Derin,

Your methods are missing closing } characters.

For each opening ( or { you must ensure that you have a corresponding closing ) or }.

There are two good ways to help you spot these;

  • indent your code in a consistent and helpful manner
  • use a built-in tool within the IDE to help locate them

Note: If you use a built-in tool, there’s still no excuse for not having clean / consistant code.

Example;

Your current Update() method;

	// Update is called once per frame
	void Update () {
	
		 print (myState);
		 if (myState == States.devam_0){
		    States_devam_0 ();
		 } else if (myState == States.sokak) {
		 	States_sokak ();
		 	} else if (myState == States.kv_0){
		 	 States_kv_0 ();
		 	} else if (myState == States.cv_0){
		 	States_cv_0 (); }
		 	  else if (myState == States.devam_1){
		 	  States_devam_1 ();
		 }

A tidier version of your Update() method, with the opening curly braces at the end of each opening statement;

// Update is called once per frame
void Update () {	// opening method curly brace

	print (myState);
	 
	if (myState == States.devam_0) {
		States_devam_0 ();
	} else if (myState == States.sokak) {
		States_sokak ();
	} else if (myState == States.kv_0) {
		 States_kv_0 ();
	} else if (myState == States.cv_0) {
		States_cv_0 (); 
	} else if (myState == States.devam_1) {
		States_devam_1 ();
	}
}		// missing closing curly brace 

or, with the opening and closing braces on new lines;

// Update is called once per frame
void Update () 
{	// opening method curly brace
	print (myState);
	 
	if (myState == States.devam_0)
	{
		States_devam_0 ();
	} 
	else if (myState == States.sokak)
	{
		States_sokak ();
	} 
	else if (myState == States.kv_0)
	{
		 States_kv_0 ();
	} 
	else if (myState == States.cv_0)
	{
		States_cv_0 (); 
	} 
	else if (myState == States.devam_1)
	{
		States_devam_1 ();
	}
}		// missing closing curly brace 

So, go through your code and look for the missing curly braces / brackets, and then keep you code tidy so that you can spot these things more easily :slight_smile:

Also, you can just paste your code into your posts which may make it easier for people to help you, see the User Guide below on formatting.


See also;

Thanks, again :slight_smile:

1 Like

No problem at all :slight_smile:

Privacy & Terms