Search Unity

error CS1513: } expected. (Line 17)

Discussion in 'Scripting' started by GamerV4, Jul 10, 2021.

Thread Status:
Not open for further replies.
  1. GamerV4

    GamerV4

    Joined:
    Jul 9, 2021
    Posts:
    9
    I've tried everything to solve this error. But I can't figure out why this issue is happening, I think it's a bug. (I selected the void where this happens)

    Code (CSharp):
    1.  
    2.  private void Reload()
    3.     {
    4.         if (outOfAmmo == true && !isAiming && !shootAudioSource.Play()) ;
    5.         {
    6.             anim.Play("Reload Out Of Ammo", 0, 0f);
    7.  
    8.             mainAudioSource.clip = SoundClips.reloadSoundOutOfAmmo;
    9.             mainAudioSource.Play();
    10.            
    11.             if (bulletInMagRenderer != null)
    12.             {
    13.                 bulletInMagRenderer.GetComponent
    14.                 <SkinnedMeshRenderer>().enabled = false;
    15.                 StartCoroutine(ShowBulletInMag());
    16.             }
    17.         }
    18.         else
    19.         {
    20.  
    21.             anim.Play("Reload Ammo Left", 0, 0f);
    22.  
    23.             mainAudioSource.clip = SoundClips.reloadSoundAmmoLeft;
    24.             mainAudioSource.Play();
    25.        inspector
    26.  
    27.             if (bulletInMagRenderer != null)
    28.             {
    29.                 bulletInMagRenderer.GetComponent
    30.                 <SkinnedMeshRenderer>().enabled = true;
    31.             }
    32.         }
    33.         currentAmmo = ammo;
    34.         outOfAmmo = false;
    35.     }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Line 4 shouldn't end with a semicolon. Lines 13 and 14 shouldn't be separate lines. I have no idea what "inspector" is there for on line 25. You didn't mention what line number the error occurs at that you're talking about, so I don't know if there is another issue here or if the issue is somewhere else in the script. The error has a specific line number, which is the most important part of the error message.

    Your script editor, such as Visual Studio, should be pointing these kinds of basic C# syntax issues out for you though. So you shouldn't need to be searching for them. They should be shown with red.
     
    Last edited: Jul 10, 2021
    Mauri likes this.
  3. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    you have a ; on line 4 after the if
    This is almost never a bug

    Edit: because of that ;, you {} block after the if is not actually part of the if, but just a block, and therefore else is invalid after it
     
    Joe-Censored likes this.
  4. GamerV4

    GamerV4

    Joined:
    Jul 9, 2021
    Posts:
    9
    [QUOTE = "Joe-Censurado, post: 7314130, membro: 234917"] A linha 4 não deve terminar com um ponto e vírgula. As linhas 13 e 14 não devem ser linhas separadas. Não tenho ideia do que é "inspetor" na linha 25. Você não mencionou em qual número da linha o erro ocorre e de que está falando, então não sei se há outro problema aqui ou se o problema está em outro lugar no script. O erro possui um número de linha específico, que é a parte mais importante da mensagem de erro.

    No entanto, seu editor de script, como o Visual Studio, deve apontar esses tipos de problemas básicos de sintaxe C # para você. Portanto, você não precisa estar procurando por eles. Eles devem ser considerados em vermelho. [/ CITAR]
    LINE 17. can you read the tlitle? Visual studio told me nothing.
     
    Last edited: Jul 10, 2021
  5. GamerV4

    GamerV4

    Joined:
    Jul 9, 2021
    Posts:
    9
    if I don't use ; unity says i can't use !
     
  6. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    ? What does it say exactly? Don't try to appease your compiler, think about the logic you are writing. Putting a ; after the if closes that if, so it's definitely not a solution.
     
    Bunny83 likes this.
  7. GamerV4

    GamerV4

    Joined:
    Jul 9, 2021
    Posts:
    9
    error CS0023: Operator '!' cannot be applied to operand of type 'void'
    I know, but with this ! I have no escape bro. I started coding half a week ago, I don't know other ways of doing it
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    Fortunately I do... I want you to succeed and I know that you can!

    First, here's my blurb on how to do tutorials properly.

    How to do tutorials properly:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly. Fortunately this is the easiest part to get right. Be a robot. Don't make any mistakes. BE PERFECT IN EVERYTHING YOU DO HERE.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

    Second, here are some GREAT tutorial makers. Take your time work through these, and your brain will be much larger at the end of it all.

    Imphenzia / imphenzia - super-basic Unity tutorial:



    Jason Weimann:



    Brackeys super-basic Unity Tutorial series:



    Sebastian Lague Intro to Game Development with Unity and C#:



    Imphenzia: How Did I Learn To Make Games:
     
  9. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Tbh, I wouldn't suggest starting with unity as your first step into programming, because you are greatly overwhelming yourself there. You won't go and run a marathon to learn to walk, right? Same thing here. Learn the basics, there are tons and tons of tutorials online. Brackeys has one, I'm sure it's good, you will get used to the voice you will be hearing most of the time you want to search for a unity tutorial afterwards too, so doubly good.
    That series seems to go over enough to start using unity more efficiently. But you will still suffer at the beginning, because of lack of inexperience, which will go away after some time.
    My recommendation as above is to not go and appease your compiler because it's shouting at you. It's not your friend, it's your teacher grading you for the work you did. If it spits out an error, that probably has a reason (don't blame the compiler either, it's probably not bugs at the stage you are at). You need to think about what that reason could be. You learned the basics at that point, so you can actually think about it.
    tldr, watch this:
     
  10. GamerV4

    GamerV4

    Joined:
    Jul 9, 2021
    Posts:
    9
    [QUOTE = "Kurt-Dekker, post: 7314217, membro: 225647"] Felizmente eu quero ... Eu quero que você tenha sucesso e eu sei que você pode!

    Primeiro, aqui está minha sinopse sobre como fazer tutoriais corretamente.

    Como fazer os tutoriais corretamente:

    Os tutoriais são uma ótima ideia. Os tutoriais devem ser usados da seguinte maneira:

    Etapa 1. Siga o tutorial e execute cada uma das etapas do tutorial 100% exatamente da forma como é mostrado. Mesmo o menor desvio (mesmo um único caractere!) Geralmente termina em desastre. É assim que a engenharia de software funciona. Cada letra deve ser soletrada, maiúscula, pontuada e espaçada (ou não espaçada) corretamente. Felizmente, essa é a parte mais fácil de acertar. Seja um robô. Não cometa erros. SEJA PERFEITO EM TUDO O QUE VOCÊ FAZ AQUI.

    Etapa 2. Volte e trabalhe em todas as partes do tutorial novamente e, desta vez, explique-o ao seu cachorrinho. Vê como estou fazendo isso na imagem do meu avatar? Se você não tem cachorro, explique para a planta da sua casa. Se você não conseguir explicar qualquer parte disso, PARE. NÃO PROSSEGUE. Agora vá aprender como essa parte funciona. Leia a documentação sobre as funções envolvidas. Volte para o tutorial e tente descobrir POR QUE eles fizeram isso. Esta é a parte que leva MUITO tempo quando você é novo. Pode levar dias ou semanas para trabalhar em um único tutorial de 5 minutos. Fique com isso. Você vai aprender.

    A etapa 2 é a parte que todo mundo parece perder. Sem o Passo 2, você é simplesmente um macaco digitador de código e fora do tutorial específico que você fez, você estará completamente perdido.

    Claro, tudo isso pressupõe nenhum erro no tutorial. Para certos criadores de tutoriais (como Unity, Brackeys, Imphenzia, Sebastian Lague), esse geralmente é o caso. Para alguns outros criadores de conteúdo menos conhecidos, isso é menos verdadeiro. Leia os comentários no vídeo: alguém teve problemas como você? Se houver um erro, você NUNCA será a primeira pessoa a encontrá-lo.

    Além disso, as etapas 3, 4, 5 e 6 se tornam fáceis porque você já entendeu!

    Em segundo lugar, aqui estão alguns GRANDES criadores de tutoriais. Leve o seu tempo trabalhando com isso, e seu cérebro ficará muito maior no final de tudo.

    Imphenzia / imphenzia - tutorial super-básico do Unity:

    [MEDIA = youtube] pwZpJzpE2lQ [/ MEDIA]

    Jason Weimann:

    [MEDIA = youtube] OR0e-1UBEOU [/ MEDIA]

    Série de tutoriais super básicos do Unity da Brackeys:

    [MEDIA = youtube] IlKaB1etrik [/ MEDIA]

    Sebastian Lague - Introdução ao desenvolvimento de jogos com Unity e C #:

    [MEDIA = youtube] _cCGBMmMOFw [/ MEDIA]

    Imphenzia: Como aprendi a fazer jogos: [/ QUOTE]
    Não quero uma resposta, não uma mercadoria. Desculpe se você tem problemas emocionais e não consegue lidar com nenhuma ideia que não seja a sua. Eu preciso de uma resposta. Se você quiser fazer um merchandising sobre minha pergunta, vá para o inferno, não me importo, preciso das respostas de alguém que realmente tente me ajudar, não de alguém que não queira fazer um merchandising ou de alguém que se pareça com um robô que pensa que tem algoritmo perfeito quando as pessoas precisam de ajuda. Todo o script é PERFEITO, mas UM VAZIO (e tem 700 linhas) e você diz: HAY OLHE ESTE TUTORIAL, ONDE VAI DIZER TUDO QUE VOCÊ JÁ SABE CAUSA VIU 2108392361278336 DELES. HALF AN WEEK (little more), 5 days of videos of tutorials, I'm making this project half an week ago, but I'm progamming Csharps half an year, and that is the first time when something like this(no answer) happens, and then when I ask someone they say: HERE IS A FUKCKING TUTORIAl
     
  11. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    This is where your assessment is incorrect.

    I wish you all the best in your pursuits!
     
  12. GamerV4

    GamerV4

    Joined:
    Jul 9, 2021
    Posts:
    9
    yeah, and I need help, can you help me.

    yeah, I'm out, I'm not even american. I accept a tutorial, one that answer my question
     
  13. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,664
    A bad attitude is like a flat tire, you won't go anywhere until you change it. None of us are obliged to help you.

    Truth is: You just have learned coding half a week ago. It will be better for you if you learn and understand why this line doesn't work instead of asking us for a quick fix. I'm sure there will be tutorials in your language on YouTube or other platforms.

    P.S.: It doesn't matter what nationality you have.

    Instead of "!shootAudioSource.Play()", try "!shootAudioSource.isPlaying"? https://docs.unity3d.com/ScriptReference/AudioSource-isPlaying.html
     
    Last edited: Jul 10, 2021
    Bunny83 likes this.
  14. GamerV4

    GamerV4

    Joined:
    Jul 9, 2021
    Posts:
    9
    no, there are no tutorials in Portuguese (I think not even in English, with all due respect) I need a "quick fix" because I didn't FIND it on youtube, unity etc. I'm angry 'cause I'm trying to find a answer in hours. Sorry, but if you don't like my opnion. I'm not obliged to make a project, I'm not in a school project. But here I am. I will describe it for ya: Unity says that my script needs }, and unity does not recognize him because of the ; (4 line). But, when I remove the ; I cant use ! (bulletInMagRenderer != null) My best explication
     
    Last edited: Jul 10, 2021
  15. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    There is so much mistyped in the first code you posted, it's barely even readable. Uncle Joe graciously pointed out five or six errors to try to get you started. I added some helpful tutorials.

    I don't speak Portugese but imagine if I came to your country and listened to people talk for a week and then just started saying words that sounded like what I had heard. That's not going to make much sense and that is pretty much what the code you posted above looks like to the computer.

    Again, start with some basic coding tutorials, as Gorbit99 suggested above. Take a deep breath, it takes a while to get all this into your brain and being angry about it is only going to slow you down, as Mauri points out above.
     
    Joe-Censored likes this.
  16. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    As pointed out, please take some time and go through the basic tutorials. Your code is so broken and wrong that helping you fix it isn't going to help, you are just going to keep breaking things until you understand the basics. Start in the Learn section of this site, or follow some of the links provided above.
    Closing.
     
Thread Status:
Not open for further replies.