Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. SuperStrict
  3.  
  4. Framework brl.blitz
  5. Import brl.standardio
  6.  
  7. Type TWaffle
  8.    
  9.     Field m_delishushness:Int
  10.    
  11.     Method GetDelishushness:Int()
  12.         Return m_delishushness
  13.     End Method
  14.    
  15.     Method SetDelishushness(delishushness:Int)
  16.         m_delishushness = delishushness
  17.     End Method
  18.    
  19.     ' This is a sort-of wacky way to create objects, but it is quite useful
  20.     Method Create:TWaffle(delishushness:Int)
  21.         SetDelishushness(delishushness) ' We don't have to do 'Self.SetDelishushness' here because we are already in the 'Self' scope; though you could do that if you so wished
  22.         Return Self ' 'Self' refers to the actual instance of the type, so in this case we are just returning the object that you created with 'New'
  23.     End Method
  24.    
  25.     ' This function is only related to the TWaffle type in that it exists within the type's defined space
  26.     ' It does not have any access to any member of the type which is non-static (static being: global, const, other functions)
  27.     Function StaticFunction:Int()
  28.         Print("ohai!")
  29.         Return 42
  30.     End Function
  31.    
  32.     Function CreateWaffle:TWaffle(delishushness:Int)
  33.         Local zewaffle:TWaffle = New TWaffle
  34.         zewaffle.SetDelishushness(delishushness)
  35.         Return zewaffle
  36.     End Function
  37.    
  38. End Type
  39.  
  40. Local mywaffle:TWaffle
  41. mywaffle = TWaffle.CreateWaffle(9) ' I don't particularly like this way of creating objects, as saying 'TWaffle.CreateWaffle' is a bit redundant
  42. mywaffle = New TWaffle.Create(9) ' This is a more OO approach (note that you could call the above static function 'Create' instead of using the method, but this is how I would do it)
  43.  
  44. mywaffle.SetDelishushness(10000) ' Calling a method of the object
  45. Print(mywaffle.GetDelishushness()) ' Calling a method of the object
  46. Print(mywaffle.m_delishushness) ' Accessing the field directly
  47.  
  48. Print(TWaffle.StaticFunction()) ' You do not need to create a new instance of the type to call functions..
  49. Print(mywaffle.StaticFunction()) ' .. But you can if you want to. Note that the static function has no knowledge of the instance's members.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement