I Suck at Lua Scripting

Hi there,

Now, before people are spamming me to death with comments like;

“You haven’t searched Facepunch for your problem.”
“You just don’t know how to search.”

I have looked over Facepunch for a while now to find a situation similar to mine. I think however that i am just don’t getting how the script is supposed to look. In my search to find anyone who could have helped me; i failed. Players on garrysmod are either to cocky and arrogant or they pretend to know.

I posted my thread regarding my problem in scripting. I’ve been experimenting with small things just to get familiar with Lua. However, i bumped.

This is my problem. I was trying to make a derma menu and had it in my first Lua file. It loaded just fine when i started gmod and tested it. Now, it seemed interesting to me to load the menu out of another file. Since both files where already on the client i just included one file into another. However, now i tried launching the menu ingame and it failed.

I just used the include() to make this happen. Can anyone explain me properly on how to run functions from another file in my main Lua script.

Thanks in Advance,
SilverMagics.

You also ‘suck’ at asking for help.

See JSharpe’s excellent article on the matter.

You haven’t given enough information for anyone to help you well.

I am just asking if anyone could explain me how to call functions from another lua script. Like JSharpe explained read all of the post.

I am not asking anyone to fix my problem, i am asking anyone to explain to how to call a function from another file. If my problem gets fixed without me knowing what to do the next time its kinda useless. So, all i am asking is how to call a function from another file.

Deco, not cool.

Anyhow, Thanks in Advance,
SilverMagics

Since nobody seems to feel like helping this guy, I’ll do so.

To call a function from another file you’ll first need to include the file which contains the function you’d like to call. To do so you need to use include(). The syntax is:
[lua]include(“name.lua”)[/lua] The syntax can also be found at http://wiki.garrysmod.com/?title=Include

Now, to call the function from the included file just call it like any other function. Like so:
[lua]name()
– Example: my_Function()[/lua]
More information about functions and how they work can be found here: http://wiki.garrysmod.com/?title=Functions

Here you go:

Edit: Damn you, ColtoM :ninja:

Thanks both for taking time in showing this. I looked on wiki as for that much i tried, i followed the example but i guess i was just stupid… xD

Anyhow many thanks

Unless I’m mistaken functions declared globally can be called from any other script.

In one file:
[lua]function der() print(“derp”) end[/lua]

In another:
[lua]der()[/lua]

should print derp. I’ve tried global functions and they work fine.

Only if those files have actually been loaded.