Announcement

Collapse
No announcement yet.

Adding extra sounds

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding extra sounds

    Hey, I know it's been a long time since I've been at the fourms, I might have asked this before, but I want to give the enemies additional sounds. Like have the soldier have more than one death sound.

    but here is the prob;em: I did this:

    // regular death
    sound (self, CHAN_VOICE, "soldier/death1.wav", 1, ATTN_NORM);
    else
    sound (self, CHAN_VOICE, "soldier/death2.wav", 2, ATTN_NORM);
    if (random() < 0.5)
    army_die1 ();
    else
    army_cdie1 ();
    };

    but in the compiler, what's this:

    compiling soldier.qc
    in function army_die (line 221),
    soldier.qc:237: error: Unknown value "else".
    soldier.qc:237: warning: Expected punctuation
    soldier.qc:237: warning: Expected punctuation
    soldier.qc:237: warning: Expected punctuation
    soldier.qc:237: warning: Expected punctuation
    soldier.qc:237: warning: Expected punctuation
    soldier.qc:237: warning: Expected punctuation
    soldier.qc:237: warning: Expected punctuation
    soldier.qc:237: error: expected ;, found sound

    also in soldier: Error in soldier.qc on line 286

    line 286, this:
    };

  • #2
    you have an "else" without an "if", it seems

    Comment


    • #3
      You should have posted the entire function in a code box with proper tabbing/nesting. It would be a lot easier to fix your error.

      Without the rest of the function how can I be sure that final curly bracket is necessary... or if you have an "if" for the first "else" in your paste... or any other mistake you may have made before the pasted part?

      I can't be sure cause you didn't supply the top of the function but, it looks like you might be writing the same condition over and over. Why not combine them?

      Code:
      	if (random() < 0.5) {	
      		sound (self, CHAN_VOICE, "soldier/death1.wav", 1, ATTN_NORM);
      		army_die1 ();
      	} else {
      		sound (self, CHAN_VOICE, "soldier/death2.wav", 2, ATTN_NORM);
      		army_cdie1 ();
      	}
      Last edited by MadGypsy; 08-10-2016, 04:41 PM.
      http://www.nextgenquake.com

      Comment


      • #4
        Hello Hiro-Hamada,

        First of all, why dont you use your previous thread (as it contains the exact same question) ?
        Now we have to start from scratch again linking to all the sources and stuff.

        But I will skip that.
        Here are some words that might help you:

        First of all, the compilers output (that you copied into your post) is very helpful. It looks like you are using fteqcc.

        This line:
        in function army_die (line 221),
        tells you in which function (and the line where that functions starts) it detected an error/warning.

        This line:
        soldier.qc:237: error: Unknown value "else".
        tells you that the compiler does not know the value "else". Well, you might think that it *should* know what "else" means as it is a standard phrase but without an "if" there cannot be an "else".
        So, what you need to declare is the "if-check" before you can set an "else" line.
        An "if-check" must compare or check something. You cannot simple write "if" in front of a "sound" call for example. You have to use the correct form:
        if ( blah )
        In your case you want to write this line in front of the 1st sound() call:
        if (random() < 0.5)
        It means that if a randomly generated number between 0 and 1 is smaller than 0.5. And that means again that it has a 50% chance to happen.
        You can of course use any value between 0 and 1 to set that percentage to happen...

        These lines:
        soldier.qc:237: warning: Expected punctuation
        soldier.qc:237: error: expected ;, found sound

        tell you that the compiler expects an ending of a line, usually it is an ";"
        It cannot find it but it sees "sound" from the next line so there is something wrong/missing. As every line of code needs to have an ending to tell the compiler that it actually ended here and the next character will be the beginning of a new line.




        Now let us see what else you added into the code.
        Look at this line:
        sound (self, CHAN_VOICE, "soldier/death2.wav", 2, ATTN_NORM);
        This line will crash many engines. Some will crash to console and some will crash completely. Only FTE will accept it
        The reason is: The value marked in red is out of its range !
        It declares the volume of the sound. Only values between 0 and 1 are allowed.
        Please see what each of the sound() function values mean in defs.qc:
        void(entity e, float chan, string samp, float vol, float atten) sound = #8;


        Last point: precaching
        Every asset/file you want to use in-game must be precached, so that the engine is ready to use it.
        If you do not precache them, some engines will crash, some engines will ignore it but give an error message on top of the screen in-game.

        There are 2 possibilities for using an external file:
        - Only monster dependend (like in your case)
        - Independent from anything. Means you can use it anytime in-game.
        For option 1 it is enough to precache it in the individual monster qc file (in its spawn function).
        For option 2 you should (to be able to use any engine) precache assets at map start. That means you have to precache them in worldspawn().

        So, in your case you only need to add this line into monster_army() function, which is fortunately directly beneath the death function your are already editing:
        precache_sound ("soldier/death2.wav");
        Be sure to have your file named like it and placed in that directory of your mod.



        Ok, that is it. If you will fix the above mentioned issues you will be able to compile your mod and use it in any engine.


        Last but not least, lets take a look at MadGypsys post:
        While looking at the compilers output of your post would have answered all of his questions, he made an interesting quote:
        Why not combine them?
        Combining both if-checks into one will lead to a different result.
        It depends what you want to have in your mod:
        Should "death2.wav" ONLY be played when the soldiers second death animation happens ?
        Or should "death1.wav" or "death2.wav" randomly played, independent to the soldiers death animation.

        Based on your answer you must have 2 different if-checks or you can combine them into one. IŽd personally use 2 different ones to keep the variation high, which is in my opinion always good.


        Please do not wait another 4 months to proceed with your mod and do not start another thread again

        Have fun coding and experimenting...
        Seven

        Comment


        • #5
          Originally posted by Seven View Post
          Please do not wait another 4 months to proceed with your mod and do not start another thread again

          Have fun coding and experimenting...
          Seven
          Thanks. During the whole moths I have practically been ignoring quake, and busy with homework, and Doom.

          Comment

          Working...
          X