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
#15
RE: Sounds don't play

So, about using funcdefs instead - first you'd define a function handle type, like this:
funcdef void WindFunc();

This should be a global declaration (outside of any function).

Here, WindFunc is a function pointer type which can point to any function wich has the signature:
void SomeFuncName();

==> and your functions do, so they qualify:
void windysound_1 ()

Then you can declare (globally) an array of these function handles (function pointers):
WindFunc@[] functions(3); // declares an array of size 3

Next, in OnEnter(), you can assign the appropriate function to each member of the array:
@functions[0] = @windysound_1;
@functions[1] = @windysound_2;
@functions[2] = @windysound_3;


Finally, when the time comes, you can pick one randomly, and make the call, like this:
WindFunc@ f = functions[RandInt(0, functions.length() - 1)];
f();


In the first line, RandInt(0, functions.length() - 1) randomly picks an index to some array member ( indices range from 0 to length-1). The resulting array member is assigned to the local variable f, and then in the next line, f is used to make the call to whichever of your windysound_#() functions got picked.

BTW, if it's easier to undersand, you can also write the same thing like this:

int maxValue = functions.length() - 1;
int index = RandInt(0, maxValue);
WindFunc@ f = functions[index];
f();
(This post was last modified: 12-19-2012, 10:49 PM by TheGreatCthulhu.)
12-19-2012, 08:07 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)