Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lib myLibA
- // public: changes the scope to all things underneath to public until another <scope>: keyword is used
- public:
- func myFunc (string s)
- BJDebugMsg("Called myFunc with a string.")
- end
- // using the colon ":" with an "empty" func declaration followed by parameter lists (paramA, paramB) and function definitions to overload the function
- func myFunc:
- (integer i)
- BJDebugMsg("Called myFunc with an integer")
- (player p, string s)
- 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"
- ()
- BJDebugMsg("Called " + _func_name + " with no argument.")
- end
- // more public stuff
- private:
- // you do not need to include empty parentheses if the function takes nothing
- func onInit
- string s
- integer a=5, b=10, c=a+b
- if (a<b)
- s = a + " is less than " + b + "." // implicit typecasting from integer to string
- BJDebugMsg(s)
- if (c==a+b)
- BJDebugMsg(c + " equals " + (a+b)) // (a+b) evaluates the expression, then typecasts to string
- end
- end
- BJDebugMsg("This is func " _lib_name + "." + _func_name) // will print "This is func myLibA.onInit"
- end
- // more private stuff
- end
- lib myLibB
- public:
- func myFunc // takes nothing returns nothing
- BJDebugMsg("takes nothing returns nothing")
- end
- func myFunc -> string // takes nothing returns string
- return "a string"
- end
- func myFunc (string s, integer i) // takes string, integer returns nothing
- integer counter = 0
- func displayString (string s) // nested func (handy if you'd like to define a func that only one func will ever use)
- BJDebugMsg(s)
- BJDebugMsg("Displayed by " + _func_name) // would display "Displayed by myFunc__displayString"
- end
- while (counter<i)
- displayString(s)
- counter += 1
- end
- end
- private:
- vars
- string a_private_string = "foo", another_private_string = "bar"
- player P = Player(0)
- end
- func onInit
- myLibA.myFunc() // calls myLibA's myFunc (with no args)
- myLibA.myFunc(P, a_private_string)
- myLibA.myFunc(5)
- myLibA.myFunc(another_private_string)
- myFunc(a_private_string, 10) // calls this lib's myFunc
- end
- end
Add Comment
Please, Sign In to add comment