• How to open LUA programs.
    26 replies, posted
As you would start with any coding language you should start out with a program that prints the words "Hello world". So I wrote this beautiful line of code: Print("Hello world") Now all I need is for some way to open programs to test if they work. I would love to start coding Lua for Gmod, but I guess it's best if I start with common LUA like making basic programs. So my question is as follows: What program do I need to open Lua files?
Since Lua is plain text, you can use notepad. But I'd recommend Notepad++.
I am writing the code in Notepad++, I am just wondering which program I need to use to execute my code.
Here you go : [url]http://luabinaries.luaforge.net/[/url]
It's 'Lua' not 'LUA'. Lua means moon, it's not an abbreviation.
[QUOTE=nicatronTg;22763327]It's 'Lua' not 'LUA'. Lua means moon, it's not an abbreviation.[/QUOTE] Nobody cares. I swear. Let people call it however they want and just live on. For sakes even this section's title doesn't spell it the "right" way and we're still using it. People need to stop using such a stupid pretense to boost their post count. It doesn't contribute anything, and so does this rant, so I am sorry for that.
Well from what you said about other languages, Am i right in saying you know a bit about the other languages? If so , just go to gmod wiki, go to the gamemodes tutorials and get started. Its what I did.. As long as you know about the following in general, youll be fine for now xD. --functions/subroutines -- If / then statements --for loops --2dArrays (or are they 3d in lua? can't remember the definitions)
I just went through a very well written Lua tutorial and learned quite a lot about it. One thing I need to ask though is: What is a hook and how is it used? It was not described in the tutorial and yet I see it everywhere.
[QUOTE=Zeraux;22772248]I just went through a very well written Lua tutorial and learned quite a lot about it. One thing I need to ask though is: What is a hook and how is it used? It was not described in the tutorial and yet I see it everywhere.[/QUOTE] A hook in a sense "Adds" to a predefined function, for instance. [lua] function GM:PlayerSpawn(p) -- Happens when the player spawns print("ello ol'chaps"); end [/lua] Returns: [code] ello ol'chaps [/code] Now if we were to use a hook for playerspawn it would be like this. [lua] local function HookUsage(p) print("Hello world"); end hook.Add("PlayerSpawn", "UniqueNameHere", HookUsage) [/lua] This would return what was originally in GM:PlayerSpawn() as well as HookUsage [code] ello ol'chaps Hello World [/code] This is the easiest way i can explain it simply. Hope it makes sense.
[QUOTE=Zeraux;22772248]I just went through a very well written Lua tutorial and learned quite a lot about it. One thing I need to ask though is: What is a hook and how is it used? It was not described in the tutorial and yet I see it everywhere.[/QUOTE] You have to understand that Gmod doesn't run linearly like the programs you write and run with the Lua binaries. Basically, hooks are functions which are automatically called when a particular event occurs in the game. When a given event occurs, all the functions which are "hooked" to it will run in an arbitrary order. That's why you can "add" and "remove" hooks, and why they need to have a unique name. [editline]02:39PM[/editline] Well, fuck. :saddowns:
So what you are doing is simply making a list basicly. First it runs the "ello ol'chaps" then it check if anything is hooked to it and then runs that.
[QUOTE=Zeraux;22772952]So what you are doing is simply making a list basicly. First it runs the "ello ol'chaps" then it check if anything is hooked to it and then runs that.[/QUOTE] Pretty much. What i posted above is the same as doing this. [lua] function GM:PlayerSpawn(p) print("ello ol'chaps"); print("Hellow world"); end [/lua] Hooks are generally used in Addons and other non-gamemode related scripts as they don't have direct access to the GM table( As far as i know? ).
How will I know to write GM before the PlayerSpawn? Is it something I'll learn by time or should I look it up on the Wiki everytime I want to make something like that? Also any good guides to get into weapon making in Gmod? I understand the basic things like if statements, functions, variables, tables etc.
[QUOTE=Zeraux;22773101]How will I know to write GM before the PlayerSpawn? Is it something I'll learn by time or should I look it up on the Wiki everytime I want to make something like that? Also any good guides to get into weapon making in Gmod? I understand the basic things like if statements, functions, variables, tables etc.[/QUOTE] GM stands for game mode so you should be able to tell what need it and what doesn't. E.g player spawn, initial spawn, playerdeath etc. And to learn about how to make sweps I would advise reading through existing ones and go from there.
These are the functions when making a gamemode that should have [b]GM[/b] infront of them: [b][url=http://wiki.garrysmod.com/?title=Gamemode_Hooks]Gamemode Hooks[img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] And here is an SWEP Example. [b][url=http://wiki.garrysmod.com/?title=Garry%27s_Example_SWEP]Example Swep by Garry [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] Here are the SWEP Hooks. [b][url=http://wiki.garrysmod.com/?title=Weapon_Hooks]SWEP Hooks[img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
To put it shortly, a hook lets you run code when a certain event happens. You could hook to PlayerSpray, and it would happen every time the player used their spray.
[QUOTE=nicatronTg;22763327]It's 'Lua' not 'LUA'. Lua means moon, it's not an abbreviation.[/QUOTE] [img]http://img691.imageshack.us/img691/6405/ownedws.jpg[/img] Tell garry that
[QUOTE=|King Flawless|;22773420][img]http://img691.imageshack.us/img691/6405/ownedws.jpg[/img] Tell garry that[/QUOTE] Garry did it on purpose.
It's me letting him know nicely before we get tons of help threads about LUA, then the rest of the bunch that notice will start to get testy.
[QUOTE=Crazy Quebec;22761902]Here you go : [url]http://luabinaries.luaforge.net/[/url][/QUOTE] If you want to run some Lua which requires more processing power, you can use my LuaJIT interpreter: [url]http://dl.dropbox.com/u/2399384/lua_interpreter.zip[/url]
I use this [url]http://doris.sourceforge.net/lua/weblua.php[/url] to test syntax mechanics when I'm not sure how to write things. It's an online script runner with basic output. Great for testing metatables you don't understand or designing them.
I created a little SWEP where I basicly wrote everything Garry did in his "Garry's Example SWEP" but changed a few things. Where do I put the files so that I can test it out in-game?
lua/weapons?
It's just that I didn't have that folder already. But I'll just create it then. Thank you.
[QUOTE=Zeraux;22785974]It's just that I didn't have that folder already. But I'll just create it then. Thank you.[/QUOTE] Glad to be of help.
Sorry, you need to Log In to post a reply to this thread.