Jump to content

Photo

SFX-Script


  • Please log in to reply
6 replies to this topic

#1 Rastael

Rastael

    Wizard

  • Members
  • Real Name:Raphael
  • Location:Austria

Posted 05 January 2015 - 04:22 PM

Heyho :)

 

I need a special SFX-Script:

 

The SFX (D0) should play. After a few tics (D1) it should play again (and again and again ...).

And if it's possible: The script should stop playing the soundeffects, after it is looped "D2" times.

 

I hope, you understand, what I mean and can help me. :D



#2 Jamian

Jamian

    ZC enthusiast

  • Members

Posted 05 January 2015 - 04:32 PM

This is untested but should work:

 

ffc script LoopSFX{
   void run(int sfx, int delay, int max){
      int playcounter;
      while(true){
         Game->PlaySound(sfx);
         playcounter++;
         if(playcounter>=max)Quit();
         Waitframes(delay);
      }
   }
}


#3 ywkls

ywkls

    Master

  • Members

Posted 05 January 2015 - 05:02 PM

Spoiler

 

I tried your script and it works for repeating sounds. I was wondering how to modify this to play a repeating sound, a sound that occurs once whenever you enter the screen either immediately or after a short delay and a sound that occurs every time you enter the screen either immediately or after a short delay. I wrote a script of my own which plays a sound either at once or after a delay and can be set either to occur just once or every time you enter an area but my efforts to combine them froze the game when I made the frequency of a sound that is supposed to repeat every few seconds zero.

 

Here's the code I wrote. 

Spoiler

 

I'd been trying to modify it to do just what yours does as an optional setting, but so far I hadn't come up with anything. Any help would be appreciated.



#4 Rastael

Rastael

    Wizard

  • Members
  • Real Name:Raphael
  • Location:Austria

Posted 05 January 2015 - 05:05 PM

thanks a lot, it works perfectly! :D



#5 Jamian

Jamian

    ZC enthusiast

  • Members

Posted 05 January 2015 - 05:08 PM

Glad I could help.

 

ywkls:

You should use Quit(); instead of return. That's probably what froze ZC.



#6 ywkls

ywkls

    Master

  • Members

Posted 05 January 2015 - 11:22 PM

Glad I could help.

 

ywkls:

You should use Quit(); instead of return. That's probably what froze ZC.

 

Okay, I'll give it a try... although that code works currently. Perhaps instead I should place everything within the while loop since that part apparently works independently of everything else. My combining attempt had the while loop first, with conditionals to only do what your code said if the SFXRepeats, SoundDelay and max variable weren't zero. When set up to play a sound every sixty frames, it did just that. But when I set the max to zero, it froze. I even tried adding an extra Waitframe() at the end of the while loop but that didn't work either. Obviously, my knowledge of Zscript still needs some more work.



#7 ywkls

ywkls

    Master

  • Members

Posted 06 January 2015 - 01:49 PM

If anyone else is interested, here's the combined version of my script and Jamian's.

 

Spoiler

 

This does what I was trying to accomplish. Here are the possible settings.

 

1. Play a sound at once and only once on a screen. Leave all setting but the top at zero.

2. Play a sound after a delay only once on a screen. Set sound on the first line and how long to wait on the second. Leave everything else at zero.

3. Play a sound either at once or after a delay every time you enter a screen. Set D3 to anything other than zero, use D1 to set the sound and D2 for any delay.

4. Play a sound repeatedly while on a screen, but only on that screen. Have that sound play at once or after a delay. Set D5 to anything other than zero. Be sure to set frequency and max to anything above zero.

5. Play a sound repeatedly while on a screen, every time you visit that screen. Set SFXRepeats and SFXLoops to anything other than zero. Make frequency and max positive numbers.

 

All times used for how long to wait and how often to repeat are measured in frames.

 

I'm only guessing that frequency and max should be set to the same thing every time, but it seems to make sense. I've been trying to develop this on my own without asking for a script that does this, but since the topic existed I thought I'd try and see if I could learn anything by trying to combine what I'd invented and what was posted here. This only puts me one step closer to my goal of learning to script far more complex things. Please note that with current setup you can only have one of these on a screen, but then again; who'd need more than one? I'm planning to use it to add timed sounds to future cutscenes, myself.


Edited by ywkls, 06 January 2015 - 01:51 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users