You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docfx_project/articles/tutorials/connect-nightly/index.md
+13-23Lines changed: 13 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ title: "Connect to nightly builds"
8
8
9
9
10
10
# Connect to the nightly builds and use it in your project
11
-
Connect to the latest version of Gmod.NET to use the newest features and work with the `.NET 5.0`.
11
+
Connect to the latest version of Gmod.NET to use the newest features (`main` for `.NET 5.0`) or to test the `.NET 6.0 Preview` version on the `net6` branch.
12
12
13
13
We'll create a project to test if we've got the latest version.
14
14
@@ -18,30 +18,21 @@ We'll create a project to test if we've got the latest version.
18
18
* Ensure at least these individual components are installed:
19
19
* .NET SDK
20
20
* NuGet Package manager
21
+
*`.NET 5.0` if you want to use the nightly `main` branch
22
+
* The `.NET 6.0 Preview`[(link)](https://dotnet.microsoft.com/download/dotnet/6.0) if you want to use the nightly `net6` branch.
21
23
* Windows 10 (For more see the [Visual Studio requirements](https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements#visual-studio-2019-system-requirements))
22
24
* An internet connection
23
25
24
-
## Preparations
25
-
26
-
The current nightly builds require at least .NET 5.0.
27
-
28
-
**Install the `.NET 5.0 Runtime` component for Visual Studio 2019:**
29
-
* Start the Visual Studio Installer through `[Start Menu] > [All Programs] > Visual Studio 2019 > Visual Studio Installer`
4. You have copied `gmod-dot-net-lua-server.X.Y.Z.lua` to `garrysmod/lua/autorun/server/`
61
-
62
-
5. You have copied `gmod-dot-net-lua-client.X.Y.Z.lua` to `garrysmod/lua/autorun/client/`
63
-
64
-
65
60
66
61
## Tutorial Overview
67
62
68
-
In this tutorial we'll take you through the process of creating a simple 'Hello World!' module. It will simply print 'Hello World!' to the console. The great thing about that is that you will have learnt the basics of creating a Gmod.NET module. We'll use **Visual Studio 2019**, **C#** (pronounce: C-Sharp) and the **.NET Core** (pronounce: dot net core) framework.
63
+
In this tutorial we'll take you through the process of creating a simple 'Hello World!' module. It will simply print 'Hello World!' to the console. The great thing about that is that you will have learnt the basics of creating a Gmod.NET module. We'll use **Visual Studio 2019**, **C#** (pronounce: C-Sharp) and the **.NET 5.0** (pronounce: dot net 5) framework.
69
64
70
65
These are the subjects we will be discussing:
71
66
@@ -111,9 +106,7 @@ Let's make sure we really have ALL required components.
**IModule is an "interface". An interface forces us to add certain functionalities to our class.** IModule forces us to add functionalities explaining how the module must start and stop.
260
252
@@ -300,16 +292,18 @@ If we skim the rest of the code we see (amongst a lot of other code) the words L
300
292
301
293
Methods sometimes get input and they sometimes return output. We can see that the Load and Unload methods don't return any output from the keyword `void` in front of the Method name.
302
294
303
-
We can see from the () behind the Unload method that it does not expect any arguments and therefor has no input.
295
+
We can see from the `(ILua lua)` behind the Unload method that it only expects a single argument/input.
304
296
305
-
**Load is called when our module is loaded.** We will fill it with code in the next chapter.
297
+
**Load is called by Gmod.NET when our module is loaded.** We will fill it with code in the next chapter.
306
298
307
-
**Unload is called when our module needs to clean up after itself.** Unload is irrelevant for our Hello World example.
299
+
**Unload is called by Gmod.NET when our module needs to clean up after itself.** Unload is irrelevant for our Hello World example.
308
300
309
301
13. Remove `throw new NotImplementedException();` from both the Load and Unload methods:
`NotImplementedException` is a runtime error that helps us programmers remember to write some code. In C# we call runtime errors `Exceptions`. The `throw` keyword helps us raise such errors.
306
+
313
307
**To summarize what we've learnt:**
314
308
315
309
* Errors help us identify problems
@@ -319,13 +313,11 @@ We can see from the () behind the Unload method that it does not expect any argu
319
313
* Visual Studio can help us generate the functionalities IModule requires: implementing the IModule interface
320
314
* Properties describe a class
321
315
* Methods explain in what sequence code needs to be executed
322
-
323
-
316
+
* Runtime errors in C# are called Exceptions
324
317
325
318
**That's it! We've setup our code and are ready to get to the main subject of today: making our module print 'Hello World!'.**
326
319
327
320
328
-
329
321
## 4. Writing module code
330
322
331
323
After all those instructions we finally get to the most important part of this module: actually printing 'Hello World!' to the Garry's Mod console. Hilariously this will be the shortest chapter of all.
@@ -374,7 +366,6 @@ We can see that the Load method receives a few arguments of input:
374
366
* A bool is short for boolean. It can contain only `true` or `false`.
375
367
* We often use booleans for yes/no or on/off questions.
376
368
* This argument is true if the module was loaded serverside.
377
-
*`GetILuaFromLuaStatePointer lua_extructor` - Irrelevant for beginners, ignore it for now.
378
369
*`ModuleAssemblyLoadContext assembly_context` - Irrelevant for beginners, ignore it for now.
379
370
380
371
@@ -442,7 +433,7 @@ We've written the code to explain what our module wants to happen: *when loading
4. Inside your solution navigate to where the module was built: `<your solution location>\GmodHelloWorld\bin\Debug\netcoreapp3.1\`
436
+
4. Inside your solution navigate to where the module was built: `<your solution location>\GmodHelloWorld\bin\Debug\net5.0\`
446
437
447
438
5. If your module built successfully you'll have the following files. We'll call these "*the built module files*".
448
439
@@ -464,21 +455,25 @@ We've written the code to explain what our module wants to happen: *when loading
464
455
465
456
466
457
467
-
### Testing
458
+
### Running & Testing
468
459
469
460
1. Start Garry's Mod
470
461
471
462
2. Start a singleplayer game
472
463
473
-
3. Check the console. Because we're loading the module in Singleplayer it's loaded clientside, our "Hello World!" message will appear in a yellow color:
464
+
3. Open the Developer Console
465
+
466
+
4. In order to load our module execute this Lua function: `dotnet.load` for example: `lua_run dotnet.load("GmodHelloWorld")`
467
+
468
+
5. Check the console. Because we're loading the module on the server (using `lua_run`), our "Hello World!" message will appear in a blue color:
* To unload the module use `gmod_net_unload_all` for the server
491
-
* In our case we yse `gmod_net_unload_all_cl` to unload the module clientside (because we're in singleplayer)
485
+
* To unload the module execute this lua function: `dotnet.unload("GmodHelloWorld")`
486
+
* In our case we use `lua_run dotnet.unload("GmodHelloWorld")` to unload the module serverside (because we loaded it with `lua_run` on the server before)
0 commit comments