Advertisement
BullyATWiiplaza

Functions Array Example

Nov 21st, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. init()
  2. {
  3.     setupFunctionsArray();
  4. }
  5.  
  6. setupFunctionsArray()
  7. {
  8.     level.rollTheDiceFunctions = []; // Make an empty array
  9.     level.rollTheDiceFunctions[level.rollTheDiceFunctions.size] = ::print; // Add the function reference to the array
  10.     level.rollTheDiceFunctions[level.rollTheDiceFunctions.size] = ::print2; // Add the function reference to the array
  11.     // Keep adding...
  12. }
  13.  
  14. executeRandomFunction()
  15. {
  16.     randomIndex = randomInt(level.rollTheDiceFunctions.size); // Get a random index of the array
  17.     function = level.rollTheDiceFunctions[randomIndex]; // Get the random function
  18.     self [[function]](); // Call the function with no parameters
  19. }
  20.  
  21. print()
  22. {
  23.     self iPrintln("Test");
  24. }
  25.  
  26. print2()
  27. {
  28.     self iPrintlnBold("Test");
  29. }
  30.  
  31. keepingRollingTheDice()
  32. {
  33.     level endon("game_ended");
  34.     self endon("disconnect");
  35.    
  36.     while(true)
  37.     {
  38.         self executeRandomFunction();
  39.        
  40.         wait 0.05;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement