User Tools

Site Tools


hpl2:tutorials:script:funcdef

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl2:tutorials:script:funcdef [2011/08/14 20:44]
apjjm Missing spaces, formatting & minor alterations
hpl2:tutorials:script:funcdef [2011/08/15 01:09] (current)
apjjm [Solving a basic problem with function pointers]
Line 153: Line 153:
     AddDebugMessage("​Dawg!",​ false);     AddDebugMessage("​Dawg!",​ false);
  
- 
- 
    
 // The actual stuff that does the descision making // The actual stuff that does the descision making
Line 160: Line 158:
 void bigFunction() { void bigFunction() {
     @outputChoice = @output1; // Initially point to output 1     @outputChoice = @output1; // Initially point to output 1
-    subFunction(); ​   // Call whith 1/4 chance of changing outputChoice ​+    subFunction(); ​   // Call with 1/4 chance of changing outputChoice ​
     outputChoice(); ​  // Call whichever output has been chosen     outputChoice(); ​  // Call whichever output has been chosen
  
Line 171: Line 169:
 } }
    
-void OnStart() {     // Call bigFunction 20 times - notice roughly a 1/4 chance of output2?+void OnStart() {      
 +    ​// Call bigFunction 20 times - notice roughly a 1/4 chance of output2?
     for(int i=0; i<20; i++) bigFunction();  ​     for(int i=0; i<20; i++) bigFunction();  ​
 } }
Line 178: Line 177:
  
 It's time to move onto solving a much bigger problem: Calling a random function. It's time to move onto solving a much bigger problem: Calling a random function.
- 
  
 ==== Arrays, function pointers, and you ==== ==== Arrays, function pointers, and you ====
Line 188: Line 186:
 <code cpp>// This creates a signature called "​SimpleFunction"​ <code cpp>// This creates a signature called "​SimpleFunction"​
 // Which matches functions which take no arguments, and return nothing... // Which matches functions which take no arguments, and return nothing...
-funcdef void fdSimpleFunction(); ​  ​+funcdef void fdSimpleFunction(); ​   
 // ...such as the following sample functions: // ...such as the following sample functions:
 // This function will output "hello world" // This function will output "hello world"
Line 198: Line 196:
     AddLocalVarInt("​DTC_TimesCalled",​ 1);     AddLocalVarInt("​DTC_TimesCalled",​ 1);
     AddDebugMessage("​DisplayTimesCalled,​ called: " + GetLocalVarInt("​DTC_TimesCalled"​) + " times",​ false);     AddDebugMessage("​DisplayTimesCalled,​ called: " + GetLocalVarInt("​DTC_TimesCalled"​) + " times",​ false);
-} //This function will play the sound of an angry brute! ​+ 
 +//This function will play the sound of an angry brute! ​
 void sfPlayScarySound() { void sfPlayScarySound() {
     PlayGuiSound("​enemy\\brute\\notice.snt",​ 1.0f);     PlayGuiSound("​enemy\\brute\\notice.snt",​ 1.0f);
Line 250: Line 249:
 <code cpp>// This creates a signature called "​SimpleFunction"​ <code cpp>// This creates a signature called "​SimpleFunction"​
 // Which matches functions which take no arguments, and return nothing. // Which matches functions which take no arguments, and return nothing.
-funcdef void fdSimpleFunction();​ // Such as these example ​functions+funcdef void fdSimpleFunction(); ​ 
 + // Such as these sample ​functions:
 void sfHelloWorld() { void sfHelloWorld() {
     AddDebugMessage("​Hello World!",​ false); ​   // Output hello world     AddDebugMessage("​Hello World!",​ false); ​   // Output hello world
 }    }   
-// This function will output how many times it has been called ​ 
 void sfDisplayTimesCalled() { void sfDisplayTimesCalled() {
-    AddLocalVarInt("​DTC_TimesCalled",​ 1);+    AddLocalVarInt("​DTC_TimesCalled",​ 1); //Display how many times function was called:
     AddDebugMessage("​DisplayTimesCalled,​ called: " + GetLocalVarInt("​DTC_TimesCalled"​) + " times",​ false);     AddDebugMessage("​DisplayTimesCalled,​ called: " + GetLocalVarInt("​DTC_TimesCalled"​) + " times",​ false);
 } }
hpl2/tutorials/script/funcdef.1313354684.txt.gz · Last modified: 2011/08/14 20:44 by apjjm