Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 14 15 16 17 18 Next »
A very useful new feature
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear Mode
A very useful new feature
25-04-2015, 06:16 PM,
#1
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
Rainbow  A very useful new feature
I've added a new function that I'm hoping people will find very useful.

You can now extend existing types in Starfall (local to your instance only), which allows you to add any number of new methods to types.

A simple example:
local Player = GetTypeDef( "Player" ) --Gets the "Player" type.
local DonatorGroups = {
donator = true,
donatingmember = true
}
--Add a function to determine if a player is a donator.
function Player:isDonator()
return DonatorGroups[ self:getUserGroup() ] ~= nil
end

print( ents.owner():isDonator() ) --true if you're in either donator group
This can be applied to every type, and obeys inheritance, i.e adding to the entity type makes the method available to all types of entity.

A few things to note:
  • Attempting to add non-function values will throw an error.
  • You cannot override existing methods, only add new ones.
This also means if you want to reimplement a removed method, you can now do so for yourself. Enjoy!
Find
Reply
« Next Oldest | Next Newest »


Messages In This Thread
A very useful new feature - by Person8880 - 25-04-2015, 06:16 PM

  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.