newborn

Scripting quickstart guide

11 posts in this topic

Hopefully, I'll get a chance to write up a more detailed overview of the UI scripting but right now we're in "new update frenzy" mode, collecting bugs and squashing them etc.

 

  • LuaFunctions.txt in the game folder contains a list of the built in Lua functions for things like getting/setting console values, doing input, drawing pretty boxes etc.
  • LuaVariables.txt in the game folder contains a list of variables that are currently passed to the UI system such as maps, game modes, player information, etc.
  • Lua scripts are stored in baseinternalui
    • HUD scripts are in the "widgets" folder.
    • Menu scripts are in the "menus" folder.
    • SVGs are stored in the "icons" folder.
  • If you're creating new scripts, try not to stomp on any official stuff (unless its something you're hoping for us to include in an official update). You should give your custom widgets names that are unlikely to conflict with other peoples work, like "newborn_fancyHealth". You can actually put these scripts in any path so if you're making a full hud, you might want to create a folder such as baseinternaluiyourname and put everything in there.
  • Scripts are all updated live so there's no need to restart Reflex to see the changes. Just save your .lua and you'll see the changes immediately in-game. There is one catch to this -- if you create a new file, you'll need to restart Reflex before the game is able to see it.
  • There are some key console commands you'll want to know. These are also stored in game.cfg:
    • ui_hide_widget WidgetName will hide a widget.
    • ui_set_widget_scale WidgetName <number> will scale a widget.
    • ui_set_widget_anchor WidgetName <x> <y> will set the widgets anchor. For x, -1 is left, 0 is middle, 1 is right. For y, -1 is top, 0 is middle, 1 is bottom.
    • ui_set_widget_offset WidgetName <x> <y> will set the widgets offset relative to the anchor. 
  • All X and Y coordinates in scripts are relative to their anchors.
  • Where possible, design your widgets to use the offset and anchor console commands, instead of hardcoding positions into the lua script. For example, if you want a widget to be 100 from the bottom, don't just anchor it to the bottom and use -100 as the position in the script (use 0 as the position in the script and set the offset cvar to -100). This makes it a lot easier for users to reposition things themselves without delving into intimidating and frequently stomped scripts.
  • The ui_show_axis console command will show the anchor points and offsets for all widgets on the screen. The center of the red cross will be position 0,0 in your lua scripts.
  • Fonts are loaded from base/internal/fonts and can be referred to by filename -- for example, nvgFontFace("comic-sans"). Before distributing fonts with your HUD, keep in mind that most font licenses prohibit redistributing the .TTF source. If you search for fonts licensed under the SIL Open Font License (OFL), this license allows redistribution.
  • The WidgetName:draw function is called every frame. Ideally, do as little work in this as possible -- the sooner you can early out the better. You definitely can kill FPS with complex scripts called every frame.
Gangland, maltek, MnstH and 2 others like this

Share this post


Link to post
Share on other sites

If there is interest this could wander over to the Reflexfiles.com wiki... any coding experts (in theory I am a programmer too) on LUA might then be able to expand the content on the wiki. Just a thought.

Share this post


Link to post
Share on other sites

there isn't really much, the text files contain lots of good information.

 

The only thing missing was some properties of the widgets, which was explain in irc

<Bonuspunkt> oh newborn is there more stuff like canHide (see aliasedfrog script)
<aliasedfrog> yeah bonux, canHide, canPosition
<aliasedfrog> prolly more, canPosition will block moving it & scale atm
<Bonuspunkt> where did you find that stuff?
<aliasedfrog> was in the crosshair.lua
<aliasedfrog> canHide false makes it run all the time basically
<newborn> there's also isMenu

and for building your own huds

<newborn> so ui/newborn_hud/ would be a good place to put my stuff etc
...
<newborn> anything within /base should be found

+ a cfg file to load the widgets

 

if you have an script error in your lua file, you have to `loadconfig game` so it will be rendered again (maybe a bug?)

 

so the only thing leftover is a tutorial how to build a widget / make custom menus?

Share this post


Link to post
Share on other sites

I have added the new UI commands to the wiki... using some of newborns info... they could probably use some more info though. I.e. I need to do some more info reading up. But here they are:

 

Now that the command pages exist, updating them should be much more convenient for those so inclined. :)

 

Update: Formatted newborn's first post on the wiki:

Obviously all this can and will be expanded on.

Share this post


Link to post
Share on other sites

Does anyone know of any good resources to get a start in this stuff as a complete newbie?

​I need some too

Share this post


Link to post
Share on other sites
On 29/11/2015 at 7:16 PM, m0sley said:

Does anyone know of any good resources to get a start in this stuff as a complete newbie?

If u never programmed I guess you could just look up for some good lua programming tutorials on youtube.

after that, you just gotta check the files Luafunctions.txt and Luavariables.txt to understand what kind of wariables and functions you have as a basis to use.

 

Or (if what you wanna do is  relatively simple) you can just check out the .lua files of reflex and learn from that. Lets say you wanted  to make a custom ammo counter or smth, well then u duplicate the regular ammo counter, call it myammocounter.lua and start modifying simple values, like size, color, padding etc, while checking out how it changes in game. this way you kinda discover in a more fun way what different commands do and how they work.

Share this post


Link to post
Share on other sites
On 16/03/2016 at 9:01 AM, Ammazzabanane said:

If u never programmed I guess you could just look up for some good lua programming tutorials on youtube.

after that, you just gotta check the files Luafunctions.txt and Luavariables.txt to understand what kind of wariables and functions you have as a basis to use.

 

Or (if what you wanna do is  relatively simple) you can just check out the .lua files of reflex and learn from that. Lets say you wanted  to make a custom ammo counter or smth, well then u duplicate the regular ammo counter, call it myammocounter.lua and start modifying simple values, like size, color, padding etc, while checking out how it changes in game. this way you kinda discover in a more fun way what different commands do and how they work.

Thanks for the reply.

Funnily enough I'm a few months into a hyper-intensive programming course, graduate and will be looking for work as a junior developer this summer. I'm pretty comfortable with JS and Ruby and Lua seems work similarly to JS, with syntax similar to Ruby, so I'll take another look at making Reflex HUDs when I have more free time.

Thanks to the Turbo Pixel guys for inspiring a career change, I guess, lol.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now