ULX

Author Topic: Getting into gmod lua  (Read 5445 times)

0 Members and 2 Guests are viewing this topic.

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Getting into gmod lua
« on: December 14, 2012, 03:36:56 PM »
About me, I'm extremely right brained: a ton of ideas, always! Hard to manifest them in the code world.
I understand CSS/HTML, and limp through PHP/JavaScript, but can still produce nice things.

I know how code works for the most part, I understand functions and things like that, but I don't ever remember syntax or don't know where to find the right hooks etc. I basically see the big picture and hack away until it works, it may not look pretty, but I have gotten a lot of visually pleasing results over the years (front end)!

What exactly is the advantage to designing a plugin for ULX/ Ulib, rather than just working on something stand alone?
Is Ulib a library for lua, like jquery is to JavaScript? Could designing for ULX/ Ulib be called any easier?
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Getting into gmod lua
« Reply #1 on: December 14, 2012, 04:55:04 PM »
ULib is indeed a library for lua, and in this case, Gmod, yes, like jquery is to Javascript.
It includes lots of tools for Gmod that just weren't included in Gmod or lua to begin with.
Later revisions were actually designed to carry across multiple lua games.
Before Megiddo had to invest in "real" life, he even planned on a 'ULX' equivalent for another steam game that uses lua (that for life of me can't remember it's name at the moment).
I think the site/domain and project were pretty much put on hold once he got buried in school.

ULib or ULX vs stand-alone;
Standalone
- not everyone uses ULib. Some dislike ULX so much, they think if your mod requires ULib, it means ULX (It doesn't) and therefore might not try your code.
- Self Dependency - you learn to code without cheating relying on nice already well tested code.
ULib;
- Library - When coding, I just kept finding features in it that helped keep me from re-inventing the wheel. I can't count how many times I asked myself 'ok, i want this, how do I do it in lua. Oh look, 10 lines of code can do it. Wait...darn...ULib has a function that does it in 2.
- Compatibility - We DO override some Gmod functions, but, we allow priorities in chain. Have a hook you don't want to be broken by other badly coded hooks? Features in ULib allow you to set a priority. Other code (normally) will run as whatever default. Set a certain parameter, yours can always run first. (This doesn't guarantee hooks won't break, but..can help)
(Hook = Gmod functions that look for game events in Gmod and can be used to run your code for the event)

Overall, I've always found using ULib library easier than straight figuring out (or coding if I already knew) how to do something raw in lua.
BUT...I started with coding my own stuff in Lua before I stumbled across ULib and the wonderful original team surrounding it. (Spbogie....where are you?!??)
I'm not sure my skill would be at the level it is now if I'd started out in ULib to begin with. It really did help me stop re-inventing the wheel when using stuff.
« Last Edit: December 14, 2012, 04:57:40 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Getting into gmod lua
« Reply #2 on: December 14, 2012, 07:57:55 PM »
JamminR's right, ULib tries to simplify things for you as the developer. Some people use it and love it, some people prefer to do it from scratch either because they don't trust us to maintain compatibility or just because they enjoy the challenge of going bare-bones. There's really no "right" or "wrong" way to do it, just like anything else in the programming world.

The other game's name is Natural Selection 2, JamminR. Someday it would be great to get back to it! I actually had someone ask me recently about the SQL/flatfile abstraction I created, which made me want to continue working on it. :P
Experiencing God's grace one day at a time.

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Getting into gmod lua
« Reply #3 on: December 16, 2012, 10:32:21 AM »
Awesome thanks for the detailed replies.
Being the way that I am, someone who struggles a bit through this sort of thing, I'd rather use a library. I'm more interested in the result than the experience. I don't plan to sell my work etc, I just want to be able to make small changes here and there, so it sounds right up my ally.

Also, if I created something nice enough to give out to the community, I'd rather the traffic come here than say FP.

Besides the doc's here, are there other places you recommend I go to find answers to my questions before asking extremely noob questions? I'm thinking something like a wiki or other documentation?

My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Getting into gmod lua
« Reply #4 on: December 16, 2012, 04:53:35 PM »
The developers corner forum section has lots of pinned posts at the top, that contain links to our and other sites.

We've nothing against noob questions if the 'noob' at least tries to find answers first, and then phrases the question intelligibly.

As you know, 'it doesn't work' isn't a favorite topic post here.
:)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Getting into gmod lua
« Reply #5 on: December 17, 2012, 09:27:07 AM »
The developers corner forum section has lots of pinned posts at the top, that contain links to our and other sites.

We've nothing against noob questions if the 'noob' at least tries to find answers first, and then phrases the question intelligibly.

As you know, 'it doesn't work' isn't a favorite topic post here.
:)
haha for sure, well cool. I'm excited to get started on this, we'll see how it works out given my spare time etc.  ;D

# EDIT #
My first question, what is going to be the best way for me to edit server-side lua?
Is there some way of going about it without having to restart the server every time I edit something in say ..lua/autorun/server?
« Last Edit: December 17, 2012, 09:56:57 AM by krooks »
My TTT server. Join the fun!

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Getting into gmod lua
« Reply #6 on: December 17, 2012, 12:22:34 PM »
Usually you can just reload the script using the lua_openscript and lua_openscript_cl commands.

Garry supposedly implemented a new system where if you make edits to lua files, it will automatically update in-game. I have not yet looked in how to get that set up, though. All I know is that anytime I make a small change to XGUI, I have to restart :-[ So many restarts! *shudder*

.. And for the worst case, make sure your development server has as few addons installed as possible-- that always helps the load times :P
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Getting into gmod lua
« Reply #7 on: December 17, 2012, 02:15:41 PM »
Thanks Stickly, as a report on the new auto refresh after lua change, it seems to be functional with the small script I've been working on!
My TTT server. Join the fun!