Delicious Lua questions

Status
Not open for further replies.

amperbee

thunderdome denizen
I wanted to ask some stuff so I can clear my mind. And some miscellaneous questions, the which some resulted interesting.

1) What happens if I made a giant, but with giant I mean GIANT, file with functioning code, and I were to use that on a netgame?
2) Only if the previous question got a negative answer, is there a way I can split the code in different files and somehow join them together? Or the netgame would get the same fate as if I used the entire file?
3) I can accidentally cause a memory leak?
4) How do I make the screen go pitch black, while retaining the HUD elements, along with custom HUD elements?
5) It would be okay if I made a (for example) 9x9 matrix, then make 81 hud elements for every single content on every "cell"?
5.1) If not, then I can just make 9 and concatenate them?
5.1.1) If not, concatenate all and add a line breaker after every row?
6) How does the "consvar_t" thing work? Something like "respawnitemtime.value"?
7) "players[0]" always targets the server player on a normal in-game server, or the first player that joined on a dedicated server?
8) SRB2 Lua can read files?
9) I can edit sectors mid-game? With that I mean editing the floor Z and ceiling Z, and possibly the sector type and texture, not creating new sectors, because that's only possible on Doom Builder IIRC. I already read the variables for the sector, but I want to confirm they can be changed mid-game and not just at map load.
10) I can refer to the sector a player is standing on?
11) If I made a map and created a polyobject, I can make the polyobject thing teleport under the player at command?
11.1) And rotate it?
12) Some variables are read-only because they're hardcoded to be like that, for security, because thre is no possible way to even remotely edit them if even allowed, or for any other reason? I'm asking that because there are a few interesting variables that are read-only.
13) Is it possible to make 4 team CTF/Match?

I hope I'm not being annoying with my questions, I just want to understand more how does Lua work in SRB2, and know the answers of some things I might run into.
 
These are the answers I know off the top of my head:

4) You can use Linedef Type 422 to make the player's camera stare straight at a wall with the ~PIT texture, but that requires setting up the linedef and associated elements in a specific level. If you need to make the screen go black in any level with just one system, I'm not sure.

8) I don't think it can.

10) You can do this for any mobj with mobj.subsector.sector.
 
1) It would work fine.

2) This used to be an issue because of the old C overflow bug which has since been patched. Terminal avoided the bug by being split into multiple files and interacting between them using global functions.

3) What?

6) local testvar = CV_RegisterVar({"testvar", "Yes", 0, CV_YesNo})
testvar.value = 0

This will create a boolean variable named testvar that defaults to yes, or 1. Check the wiki for more information.

7) Node 0 is always the server, even on dedicated servers. 2.1.14 currently contains a bug with dedicated server handling in Lua however (my mistake), and it likely won't be patched until 2.2. Until then, keep in mind that the server variable will not work properly in dedicated servers.

8) Nope. SRB2's Lua implementation lacks an io library entirely so it can't interface with files. There have been talks of adding this in, preferably with limitations for security reasons, but nothing has happened yet.

9) Yes. Check here for more info.

12) I get the feeling it would be possible but some of those variables definitely don't need to be edited. The only ones I can really think of that might be of some use are variables like emeralds.

13) Lua doesn't have hooks into gametypes, so the short answer is no.
 
6) local testvar = CV_RegisterVar({"testvar", "Yes", 0, CV_YesNo})
testvar.value = 0

This will create a boolean variable named testvar that defaults to yes, or 1. Check the wiki for more information.

Try THIS link instead, it should take you to the right place unlike Wolfy's link. I changed the formatting of the page completely somewhat recently, so the above link doesn't do what it used to anymore.
 
2) The game loads multiple files just fine. If you need to access a script value between multiple scripts, you can use rawset(_G, "varname", value) to make varname a global value. If you're going to use a bunch of those, I'd recommend rawsetting a global table to hold everything you're gonna use, to avoid cluttering the global namespace. Also, make sure not to override a default variable!

3) It shouldn't be possible to cause a memory leak. Lua's garbage collector runs periodically (almost too often as of right now, which kills performance in some cases lol) and cleans out any variables that scripts can't access any more. The most you could do is create a huge table that you store somewhere and never access, which might eventually cause an out-of-memory error. We're talking somewhere in the high millions of variable counts, though.

4) You'd have to re-render the HUD elements you want over the black screen. If you're doing that, my advice would be to hide the default elements altogether and just re-render them with custom settings at all times; the default HUD uses some attributes that can't be accurately replicated in Lua for all resolutions.

5) I don't quite understand the question, but it's probably possible.

7) players[n] returns the player on node n. Usually node 0 is the host, at least outside of dedicated servers. Nodes aren't guaranteed to be filled lowest-first; if a player joins on node 1, then a player joins on node 2, then the player on node 1 leaves, then node 1 will stay empty until someone joins and fills the spot while node 2 is still occupied.

10) player.mo.subsector.sector

11) Not directly, but https://wiki.srb2.org/wiki/Linedef_type_31 and some sector height manipulation can get a similar effect. You'd probably need to apply two copies of the special on different control sectors, one for each axis. Then the rest shouldn't be too complex to make. There's no similar special for rotation, though, although you can use https://wiki.srb2.org/wiki/Linedef_type_485 and https://wiki.srb2.org/wiki/Linedef_type_487 to rig up something adequate if you'd like.

12) It depends on the variables. Some of them aren't netgame-synced, some of them would be pointless to make writeable, and some of them we just never got around to making writeable.

13) Yes, though your best option would probably be basing it on normal Match and recreating all of the team-based parts of the mode yourself.
 
Thanks for the reply, RedEnchilada.

5) I don't quite understand the question, but it's probably possible.

I tried to ask that if it would be okay, that is, no apparent problems, if a 9x9 grid was created (two arrays, or at least something made with arrays to simulate a 2D 9x9 grid) and every single "cell" is to be updated every tick and synchronized with every player. Then displayed on the screen, concatenated, as an example.
 
Yeah, that'd be possible. local matrix = {} for i=1,9 do matrix = {} end should initialize it well enough to just do matrix[position][position] when you need it.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top