Keyword `void' cannot be used in this context

Why would I be getting this error in C#??

Keyword `void’ cannot be used in this context

show us the context in which its being used, might be able to help ya.

You are using void in the wrong context would be my guess - post the script for more info.

The bottom void Reload() is throwing it-

Looks like you need one more left curly-brace before the “void reload()”

The “if” above it isn’t closed.

-JFFM

1 Like

Already did it-

you are creating a reload function inside of your update function. I don’t think you can do that.

also, put up the visibility of the reload function. public or private.

Changed it no effect-

I count 17 ‘{’ and 13 ‘}’ in your update function.

So I need 4 more }'s…??

No, you need to go through your code and correct the syntax. For example you’ve written:

if (Input.GetButtonDown("Fire1") RoundsLeft > 0){
		{
			Instantiate(SabotRounds, transform.position, transform.rotation);
		}

Yeah I cleaned that one up-

Not sure exactly how its suppose to go-

For every void function there needs to be an open and close…correct- then the calls in side need to have an open and close…correct??

Every ‘{’ must have a corresponding ‘}’ to create a statement block. The order of these brackets is important.

ok so like this

public class AbramsPlayer : MonoBehaviour {

void Start()
{
blah blah blah
}
if blah blah blah
}
}
void blah bloh
{
blah bleh
}
}
void BLAH
{
BLOH
}
}
}

no, all if statements must be within a function statement, such as Start() and Update(), or one you have created yourself. so…

void Start(){
blah blah blah

if(blah blah blah){
//do do do
}

}
}

Putting 4 } at the end of the update function solved it-

Thank very much for explaining it further with me-

Just don’t complain when your Update() function exhibits abnormal behaviors/errors due to incorrect logic flow.

I’m sure in time I know what that even means…lol

Thanks for the help- mate-

Same probleme:

  • void Start () {*

  • }*

  • // Update is called once per frame*

  • void Update () {*

  • switch(currentAnimationType)*

  • {*

  • case AnimationType.stayRight:*

  • setTexture(animationStayRight);*

  • break;*

  • case AnimationType.stayLeft:*

  • setTexture(animationStayLeft);*

  • break;*

  • }*

_ void SetTexture(List animationSprite)_

  • {*
    _ int index = (int)(Time.time * speed);_
  • index = index % animationSprite.Count;*
  • renderer.material.mainTexture = animationSprite[index];*
  • }*
    the error: Keyword ´void’ can not be used i this context

You miss a closing curly brace in the update function. Furthermore I’d like to suggest to use tags when posting code it makes it a lot easier to read.