daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest Jul 19th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lib myLibA
  2.  
  3.     // public: changes the scope to all things underneath to public until another <scope>: keyword is used
  4.     public:
  5.         func myFunc (string s)
  6.             BJDebugMsg("Called myFunc with a string.")
  7.         end
  8.        
  9.         // using the colon ":" with an "empty" func declaration followed by parameter lists (paramA, paramB) and function definitions to overload the function
  10.         func myFunc:
  11.             (integer i)
  12.                 BJDebugMsg("Called myFunc with an integer")
  13.                
  14.             (player p, string s)
  15.                 DisplayTextToPlayer(p, 0., 0., "Called " + _func_name + " with a player and a string.") // _func_name returns a string containing the name of the func, in this case "myFunc"
  16.            
  17.             ()
  18.                 BJDebugMsg("Called " + _func_name + " with no argument.")
  19.         end
  20.        
  21.         // more public stuff
  22.        
  23.     private:
  24.        
  25.         // you do not need to include empty parentheses if the function takes nothing
  26.         func onInit
  27.             string s
  28.             integer a=5, b=10, c=a+b
  29.        
  30.             if (a<b)
  31.                 s = a + " is less than " + b + "." // implicit typecasting from integer to string
  32.                 BJDebugMsg(s)
  33.                
  34.                 if (c==a+b)
  35.                     BJDebugMsg(c + " equals " + (a+b)) // (a+b) evaluates the expression, then typecasts to string
  36.                 end
  37.             end
  38.            
  39.             BJDebugMsg("This is func " _lib_name + "." + _func_name) // will print "This is func myLibA.onInit"
  40.         end
  41.    
  42.         // more private stuff
  43. end
  44.  
  45. lib myLibB
  46.    
  47.     public:
  48.         func myFunc // takes nothing returns nothing
  49.             BJDebugMsg("takes nothing returns nothing")
  50.         end
  51.        
  52.         func myFunc -> string // takes nothing returns string
  53.             return "a string"
  54.         end
  55.        
  56.         func myFunc (string s, integer i) // takes string, integer returns nothing
  57.             integer counter = 0
  58.            
  59.             func displayString (string s) // nested func (handy if you'd like to define a func that only one func will ever use)
  60.                 BJDebugMsg(s)
  61.                 BJDebugMsg("Displayed by " + _func_name) // would display "Displayed by myFunc__displayString"
  62.             end
  63.            
  64.             while (counter<i)
  65.                 displayString(s)
  66.                 counter += 1
  67.             end
  68.         end
  69.        
  70.     private:
  71.    
  72.         vars
  73.             string a_private_string = "foo", another_private_string = "bar"
  74.             player P = Player(0)
  75.         end
  76.        
  77.         func onInit
  78.             myLibA.myFunc()                        // calls myLibA's myFunc (with no args)
  79.             myLibA.myFunc(P, a_private_string)
  80.             myLibA.myFunc(5)
  81.             myLibA.myFunc(another_private_string)
  82.             myFunc(a_private_string, 10)           // calls this lib's myFunc
  83.            
  84.         end
  85.        
  86. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top