Garry's Mod Wiki

Revision Difference

Updating_Scripts_From_GMod_12_to_GMod_13#511865

# “Why your scripts are now broken” ⤶ ⤶ Several changes to the Lua API were made in the transition between GMod 12 to GMod 13. This page is an attempt to highlight them. It was originally created in the form of a Google Document created by Garry.⤶ The old method of doing things is listed on the left, while the new is on the right side.⤶ ⤶ # Changes ⤶ ⤶ * **The <page>PANEL:Paint</page> hook now receives a width and height parameter.** This shouldn't affect much in itself - but if you're calling a derma.SkinHook you will need to pass the width and height along, as it needs these values too now. You could start doing this now in your code without any negative effects.⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **<page>Entity:SetColor</page> and <page>Entity:GetColor</page> now deal with <page>Color</page>s only.** Not with single variables. This is something that is always mentioned - and since we're breaking stuff anyway now seems to be a good time to make the change. SetColor will set the color to purple if the passed variable isn't a Color.⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **KeyValuesToTable and TableToKeyValues are now in the util library.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **SetMaterialOverride, cam.StartMaterialOverride (which did the same thing) are removed and replaced with <page>render.MaterialOverride</page>.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **IMaterial:SetMaterialTexture is now <page>IMaterial:SetTexture</page>**⤶ ⤶ * **DMultiChoice is replaced by <page>DComboBox</page>.** When I originally made them they were named the wrong way around. DMultiChoice is now removed. This is because <page>DListView</page> was basically recreating all the functionality of DMultiChoice. DListView has extra settings to remove colums and headers - which make it exactly like the old DComboBox. Complicated eh?⤶ <note>SetEditable(boolean) doesn't exist on DComboBox</note>⤶ ⤶ * **DSysButton was removed.** This panel used the Marlett font to create icons such as the "close" button for windows. This isn't needed anymore since we're using GWEN skins. Plus it didn't work properly on Mac anyway.⤶ ⤶ * **Datastream module is removed.** Datastream was less than optimal when it came to networking stuff. We now have the new <page>net</page> - which doesn't work in exactly the same way, but is much more optimized to do this stuff. You should use the net library instead of datastream.⤶ ⤶ * **DBevel is removed.** This panel was purely decorational - so it shouldn't be hard for you to replace.⤶ ⤶ * **utilx no longer exists.** Please replace all ocurances of utilx in your code to the <page>util</page>.⤶ ⤶ * **entity.Classname. Caps is now enforced properly.** Use entity.ClassName instead. (N is upper case)⤶ ⤶ * **TOOL:RenderToolScreen is now <page>TOOL:DrawToolScreen</page>**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **<page>file.Find</page> now returns two tables - files and folders.** The second argument is the search path.⤶ * * "LUA" searches the lua files (in /lua/, in your gamemodes, in all the addons). This replaces file.FindInLua.⤶ * * "GAME" searches all the mounted content (main folder, addons, mounted games etc).⤶ * * "MOD" searches only the garrysmod folder.⤶ * * "DATA" searches in the data folder.⤶ Type "path" in the console to see the paths.⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ | ⤶ ```⤶ file.Find("models/model.mdl")⤶ ```⤶ | ⤶ ```⤶ file.Find("models/model.mdl", "GAME")⤶ ```⤶ |⤶ | ⤶ ```⤶ file.FindDir("exampledir")⤶ ```⤶ | ⤶ ```⤶ file.Find("example", "DATA")⤶ ```⤶ (2nd return) |⤶ | ⤶ ```⤶ file.Read("settings/users.txt", true)⤶ ```⤶ | ⤶ ```⤶ file.Read("settings/users.txt", "GAME")⤶ ```⤶ |⤶ | ⤶ ```⤶ file.Read("example.txt")⤶ ```⤶ | ⤶ ```⤶ file.Read("example.txt", "DATA")⤶ ```⤶ |⤶ | ⤶ ```⤶ file.Exists("example.txt")⤶ ```⤶ | ⤶ ```⤶ file.Exists("example.txt", "DATA")⤶ ```⤶ |⤶ | ⤶ ```⤶ file.Exists("models/models.mdl", true)⤶ ```⤶ | ⤶ ```⤶ file.Exists("models/models.mdl", "GAME")⤶ ```⤶ |⤶ ⤶ ⤶ ⤶ * **file.ReadString removed, use <page>file.Read</page>**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **<page>DColorMixer</page>.RGBBar is now DColorMixer.RGB.** GMod 13 uses Grocel's DColorMixer.⤶ ⤶ * **STool language phrases changed.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **The <page>http</page> has changed**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **<page>timer</page> calls no longer take <page>vararg</page>s to pass to callback.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **Angle functions have been unified.** Before some were Set/GetAngles and some were Set/GetAngle. Now they're all Set/GetAngles()⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **timer.IsTimer is now <page>timer.Exists</page>.** Sounds better, yeah.⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **<page>math</page> duplicate functions removed** (Deg2Rad, Rad2Deg)⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **server_settings module removed, use cvars instead.**⤶ ⤶ * **Renamed Material:[Get|Set]Material* to Material:[Get|Set]*** (ie, :SetVector instead of :SetMaterialVector)⤶ ⤶ * **Moved some functions into the <page>game</page>.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ | ⤶ ```⤶ isDedicatedServer()⤶ ```⤶ | ⤶ ```⤶ game.IsDedicated()⤶ ```⤶ |⤶ | ⤶ ```⤶ SinglePlayer()⤶ ```⤶ | ⤶ ```⤶ game.SinglePlayer()⤶ ```⤶ |⤶ | ⤶ ```⤶ MaxPlayers()⤶ ```⤶ | ⤶ ```⤶ game.MaxPlayers()⤶ ```⤶ |⤶ ⤶ ⤶ ⤶ * **WorldSound has been replaced with <page>sound.Play</page>.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **Player:GetCursorAimVector is now <page>Player:GetAimVector</page>.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **Entity Colour Alpha Changes.** In previous version of GMod setting the Alpha of an entity would also change its render mode. In 13 this behaviour was stopped - as it interfered with other things (like entities showing as invisible in some maps). This means that in 13 you need to change the render mode too - if you want your entity to show as transparent.⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **<page>GM:EntityTakeDamage</page> has been changed.** The arguments ⤶ ```⤶ attacker, inflictor, amount⤶ ```⤶ have been removed as they're available by querying the passed damageinfo.⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **The bitwise operators have been removed.** I know the old way was nicer - but we took a vote - sorry!⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶ * **ValidEntity has been removed. Use <page>Global.IsValid</page> instead.**⤶ ⤶ ⤶ Old | New |⤶ ----|----|⤶ ⤶ ⤶ ⤶ ⤶