Test Me Please!

Hello everyone. So, I think I’m pretty well off with the basics of Lua. I’m not exactly sure, though. Could someone make a test for me to create that actually does something in Garry’s Mod Singleplayer Sandbox?

The following is what I want to be included with the test:

  1. Hooks (the normal Garry’s Mod hooks)
  2. Functions
  3. Variables
  4. Syntax

I will not be looking at any tutorials while doing this. I will, however, look at the wiki for the Hooks.

I will post the script after I’m finished.

Thanks guys :slight_smile:

How’s your commenting coming along in code? A big part of good coding habits is commenting your work so if others look at it (or even yourself) you know what the goal was/what something does.

Well, honestly, it’s not a habit yet… But I’ll start making it a habit!

local a = false 

concommand.Add("toggleA", function() if a then a = false else a = true end end ) 
hook.Add("Think", "bla", function()
  if a then
end )

What do you want me to do with it? lol

[lua] a = !a [/lua]
A lot less to type.

woah, didn’t think of that. nice

Create a script that draws text in the middle of the screen after you type something in the chatbox, printing what you typed in the chatbox on the screen.

Create a function that accepts a player steamID as the first parameter/argument and returns the player handle. This can double as the variable test, create a variable that points to the player handle and return the variable in the function.

This test is the above 2, use correct tabbing (only tabbing to display a new scope), and only NEEDED functions used correctly. Also, although line terminators are not required in lua, it is good practice to include them for when you move onto new languages. Line terminators (semi-colon’s :wink: are used after function calls, and variable definition/declaration.

Good luck, take your time and produce quality - working code. Also provide screenshot proof of working scripts along with the script you wrote.


I have written both of these scripts (i didn’t test them, but in theory they should work), for you as a cheat sheet in case you get stuck.


Please update us once you’ve completed the task, and ONLY look at my cheat sheet once you completed to compare code or if you’re stuck and can’t get any further.

Best of luck.

Yup, looks like I need to continue working on my Lua! thanks so much for trying to help me! I will save this post in a document so I can try it when I learn more about Lua :slight_smile: