Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Sounds don't play
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#17
RE: Sounds don't play

OK. Using your original script as a starting point, it would look something like this:
PHP Code: (Select All)
funcdef void WindFunc();
WindFunc@[] functions(3);

void OnEnter()
{
    
AddTimer(""1"Wind");

    
// Note that the indices start from 0, not 1!
    
@functions[0] = @windysound_1;
    @
functions[1] = @windysound_2;
    @
functions[2] = @windysound_3;

}


void Wind (string &in asTimer)
{
    
AddTimer(""0.1"Windy");
    
PlaySoundAtEntity("wind_amb""wind_amb.snt"""1.ffalse);
}

void Windy (string &in asTimer)
{
    
CreateParticleSystemAtEntity("""ps_dust_whirl""Windy_"+RandInt(17), false);

    
int index RandInt(0functions.length() - 1);   // in this case same as RandInt(0,  2)
    
WindFuncfunctions[index];
    
f();

    
AddTimer(""RandInt(1.07.0), "Windy");
}

void windysound_1()
{
    
PlaySoundAtEntity("""scare_wind.snt""Windy_"+RandInt(17), 0.ffalse);
}

void windysound_2()
{
    
PlaySoundAtEntity("""scare_wind_reverse.snt","Windy_"+RandInt(17), 0.ffalse);
}

void windysound_3()
{
    
PlaySoundAtEntity("""general_wind_whirl_rand.snt""Windy_"+RandInt(17), 0.ffalse);


The only difference to your original code is that here I declared the funcdef at the top, and the function pointer array right after it. Then all the function pointers inside the array are set to point to windysound_#() functions.

And then, in place of your
"windysound_"+RandInt(1, 3);

line, there's this instead:
int index = RandInt(0, functions.length() - 1); // in this case same as RandInt(0, 2)
WindFunc@ f = functions[index];
f();


P.S. I just noticed I made an accidental mistake in my previous post; wherever it says Action it should say WindFunc instead. In my test code I named it Action, but then decided to change it to WindFunc in order for it to make more sense in your map. Gonna edit the post to correct.

The timer based alternative would go like this:
PHP Code: (Select All)
void OnEnter()
{
    
AddTimer(""1"Wind");
}


void Wind (string &in asTimer)
{
    
AddTimer(""0.1"Windy");
    
PlaySoundAtEntity("wind_amb""wind_amb.snt"""1.ffalse);
}

void Windy (string &in asTimer)
{
    
CreateParticleSystemAtEntity("""ps_dust_whirl""Windy_"+RandInt(17), false);
    
    
AddTimer(""0.0f"windysound_" RandInt(13));     // <--------- here

    
AddTimer(""RandInt(1.07.0), "Windy");    // <--- BTW, you probably wanted RandFloat() here?
}

void windysound_1(string &in asTimer)
{
    
AddDebugMessage("wnd_1"false);
    
PlaySoundAtEntity("""scare_wind.snt""Windy_"+RandInt(17), 0.ffalse);
}

void windysound_2(string &in asTimer)
{
    
AddDebugMessage("wnd_2"false);
    
PlaySoundAtEntity("""scare_wind_reverse.snt","Windy_"+RandInt(17), 0.ffalse);


If using timers, make sure that you change the parameter lists for windysound_#() functions to match those required for timer callbacks.

With funcdefs you don't need to do that - funcdef can be defined to point to a function with arbitrary parameter list and return type (see the tutorial from a few posts above), so they offer more flexibility.
(This post was last modified: 12-19-2012, 11:04 PM by TheGreatCthulhu.)
12-19-2012, 10:45 PM
Find


Messages In This Thread
Sounds don't play - by The chaser - 12-12-2012, 09:38 PM
RE: Sounds don't play - by Juby - 12-12-2012, 09:57 PM
RE: Sounds don't play - by The chaser - 12-12-2012, 10:15 PM
RE: Sounds don't play - by FlawlessHappiness - 12-12-2012, 10:45 PM
RE: Sounds don't play - by The chaser - 12-12-2012, 10:58 PM
RE: Sounds don't play - by FlawlessHappiness - 12-13-2012, 07:02 AM
RE: Sounds don't play - by The chaser - 12-13-2012, 07:48 AM
RE: Sounds don't play - by JMFStorm - 12-13-2012, 07:56 AM
RE: Sounds don't play - by The chaser - 12-13-2012, 10:17 AM
RE: Sounds don't play - by FlawlessHappiness - 12-13-2012, 10:50 AM
RE: Sounds don't play - by The chaser - 12-13-2012, 02:50 PM
RE: Sounds don't play - by TheGreatCthulhu - 12-17-2012, 01:40 PM
RE: Sounds don't play - by The chaser - 12-17-2012, 08:34 PM
RE: Sounds don't play - by TheGreatCthulhu - 12-19-2012, 10:02 AM
RE: Sounds don't play - by TheGreatCthulhu - 12-19-2012, 08:07 PM
RE: Sounds don't play - by The chaser - 12-19-2012, 09:33 PM
RE: Sounds don't play - by TheGreatCthulhu - 12-19-2012, 10:45 PM



Users browsing this thread: 1 Guest(s)