Barotrauma

Barotrauma

MicroLua
59 Comments
whosyourdaddy 24 Apr @ 7:59am 
Hi, I've made some performance optimizations to your Micro Lua (primarily focusing on caching techniques and stack access), and also added a few other features.

RuyiLuaComponent
Matheus  [author] 28 Nov, 2024 @ 4:24pm 
Of course, it is my intention to not break existing setups with any updates, going forward.
1465114862 28 Nov, 2024 @ 11:38am 
Just a suggestion.
For compatibility, please keep the 32 nodes version existing.
So that I don't need to refactor my code. :steamsad:
Matheus  [author] 27 Nov, 2024 @ 2:50pm 
Nick I agree the mod isnt well balanced. Though Id rather fix this mod, than create an alternate one.

I will take this into consideration to the next update. I think it needs to be way harder to craft than a circuit box.
Nick Molliger 26 Nov, 2024 @ 1:48pm 
How about second (alternative) mod with a some of these balancing features?
1. Input and output nodes are limited to 8/16
2. Can't be used in Circuit Boxes
3. A bit harder to craft. May be the same recipie as vanilla Circuit Box
4. Crafting depends on one of the top engineer's perks
5. Rare and expensive to buy in outposts

I mean, with this thing everyone can handle whole submarine's automatization (even by copying code from internet), save many copper and tin and collect great bunch of FPGAs by disassembling old components. This ability should be deserved by making decisions and having a real engineer game experience
Nick Molliger 26 Nov, 2024 @ 1:48pm 
This mod is a game-changer! You're damn genious! 🔥👏
Matheus  [author] 11 Oct, 2024 @ 2:39pm 
FYI I have published a submarine which showcases MicroLua: https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?edit=true&id=3347044949
Matheus  [author] 9 Oct, 2024 @ 11:37pm 
I meant to give an example of table indexing: foo\[i\]
Matheus  [author] 9 Oct, 2024 @ 11:36pm 
The error about indexing method not implemented is important.
It means somewhere in the code, we are applying table indexing, for example foo , to an object which does not support it.

The console error should say which line and column have a problem.
Can you double check and paste here?
dhdoctor 9 Oct, 2024 @ 5:04pm 
polarity is correct going into the componet 1 for presence 0 for none. input 1 is door state out 2 is motion sensor 3-6 room state inputs out 1 door set state. tried it with both polarities and rewiring a new door. console is saying index method is not implemented. no output at all
dhdoctor 9 Oct, 2024 @ 4:47pm 
sorry got home from work late yesterday can check the connections tonight
Matheus  [author] 7 Oct, 2024 @ 6:28pm 
Okay, one thing to keep in mind is that some time ago I edited the polarity of the motion sensor in the example.
Before, the door controller example assumed the motion sensor would be in reversed polarity, relative to the default it gets from placement.
I did not explain that previously in the comments, so that caused a bit of confusion for some users.
I have since edited the code so that it works with the normal polarity (0: no presence, 1: presence)
Can you double check your build for that mistake?
dhdoctor 7 Oct, 2024 @ 5:12pm 
thanks for taking a look!
dhdoctor 7 Oct, 2024 @ 5:11pm 
inp = {}
function upd ()
out[1] = inp[1]
end

that wired to a button with hello world as output passes through to the screen. i have other lua componets running too. ive gone over my wiring again on the door but still not working for some reason. It's weird cos when i first got this mod it worked and i picked the code apart to learn how to use lua a bit.
Matheus  [author] 7 Oct, 2024 @ 1:39pm 
Can you test something simpler? Just write a single string to a text display.

I’ll have another look tomorrow in any case.
dhdoctor 3 Oct, 2024 @ 6:31pm 
it seems the door controller no longer works or something on my end is broken
Matheus  [author] 5 Jul, 2024 @ 1:17pm 
Great, nice to hear that it works.
Белочка 5 Jul, 2024 @ 12:44pm 
And now it works. Thank you
Белочка 5 Jul, 2024 @ 12:30pm 
I'm an idiot. I delete microlua component freeing that id, then i create microlua taking that id, thus not changing update order
Белочка 5 Jul, 2024 @ 12:28pm 
It still does not gets inputs on first upd call, after microlua component reset (updating source code)
Белочка 5 Jul, 2024 @ 12:21pm 
I thinking about replacing mems with something more ease to work. Like 'OR' component.
Белочка 5 Jul, 2024 @ 12:14pm 
Well, i place microlua after mems and it not work out.
Well it because
"A memory component does not send outputs every frame, it only does when the memorized value changes and some other corner cases, like the first frame."

So I confused. If mem does not produce output, how vanilla components gets its output?
Белочка 5 Jul, 2024 @ 12:01pm 
Thank you very much. Yes, I place mems after microlua.
Matheus  [author] 5 Jul, 2024 @ 11:44am 
Oh I see what you mean.

You only get an input if the component connected to that input produces an output.

A memory component does not send outputs every frame, it only does when the memorized value changes and some other corner cases, like the first frame.

I suspect you are suffering from an update order issue: The game will first process components which have a lower numerical ID, and I suspect your memory component was placed after the microlua component, hence it has a higher ID, and hence it sends its first update too late.

For large circuits where just replacing the components is difficult, you can try using: https://github.com/Jlobblet/Barotrauma-Circuit-Resolver/blob/master/README.md
Белочка 5 Jul, 2024 @ 10:14am 
i think i found a workaround
Белочка 5 Jul, 2024 @ 10:07am 
If i read the inp[] in body it gives nil. And on the first upd call, inp[] in upd function also nil.

I want to read inputs from memory components not give them values myself
Matheus  [author] 5 Jul, 2024 @ 9:12am 
Белочка: Everything on the body of the script executes before the first game update, so there you can initialize your input table with the values you need.

For example:





inp = {}

for i = 1, 32 do
inp[i] = 0
end

function upd()

end
Белочка 3 Jul, 2024 @ 11:55pm 
Tried make a firstTick condition. Where on first upd call function will do nothing, but then on second tick there are nil inputs so i confused how inputs are updated
Белочка 3 Jul, 2024 @ 11:48pm 
Is there a way to initialize inputs before program starts?
Белочка 3 Jul, 2024 @ 11:35pm 
I wanted to save data across rounds. Thought I can use a default memory component by reading and writing data to it. But on the first tick all inputs are nil, triggering fail-safe mechanism in case wire is disconnected
Matheus  [author] 22 Jun, 2024 @ 12:00pm 
Try something simple first, just write some string to a text display, for example.
Undead 22 Jun, 2024 @ 11:43am 
i followed the steps and cant seem to get it to work im not sure why i will try to mess with it more when i get more time
Undead 20 Jun, 2024 @ 3:03pm 
sorry i haven't had a chance to yet soon as i can i will let you know
Matheus  [author] 20 Jun, 2024 @ 12:21pm 
@Undead did that help, or are you still stuck?
Matheus  [author] 15 Jun, 2024 @ 9:13pm 
FYI I just modified the example in the description so it is now correct regarding motion sensor polarity.
Matheus  [author] 15 Jun, 2024 @ 8:42pm 
I just tested. Everything is working.

However I just remembered the door controller example is expecting the motion sensor output to be inverted, and this is not mentioned in the document.

Sorry about that!

Either modify Motion Sensor properties so 'Output' is 0 and 'False Output' is 1, or modify the example source code such that this line:

local isDoorwayObstructed = inp[2] ~= 1

is replaced with:

local isDoorwayObstructed = inp[2] ~= 0
Undead 14 Jun, 2024 @ 10:06pm 
sounds good boss sorry for bugging but this in my opinion could be the best mod for the game
Matheus  [author] 14 Jun, 2024 @ 10:01pm 
ok, I will double check everything tomorrow, haven’t had time to play in quite a while…
Undead 14 Jun, 2024 @ 4:15pm 
i for sure have it i need it for a few other mods
Matheus  [author] 14 Jun, 2024 @ 12:33pm 
Thats fine. I think the only thing that would make the mod not work, but not give any errors, is if you didnt do the client side lua installation, which is still required.
Undead 14 Jun, 2024 @ 11:51am 
the c's for lua is no longer used. the lua mod added c sharp support
Matheus  [author] 14 Jun, 2024 @ 9:32am 
Do you have all the prerequisite modules installed and loaded?

After that, did you follow https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2940324793
in order to get client-side lua working with Lua for Barotrauma?

If you followed all that, if there were any problems with the mod, I would expect there to be errors on the console. Did you get any?

In any case, I will double check everything this weekend.
Undead 13 Jun, 2024 @ 9:22pm 
Cant seem to get it working*
Undead 13 Jun, 2024 @ 9:21pm 
i can seem to get it to work using the auto door code. i even had a buddy who is familiar with this version of lua try it and no luck
Matheus  [author] 11 Jun, 2024 @ 6:44pm 
Undead, It should, the mod is very simple, I dont expect having to change it every game update.
If it doesnt work, please report here and I will have it fixed.
Undead 11 Jun, 2024 @ 12:33am 
Does this still work?
Matheus  [author] 7 May, 2024 @ 3:32pm 
Glothia: Sure, I will try to include it next release.

Note that while this is fine for experimentation and running on small servers and fast networks, please consider that JSON is very space inefficient, even if you use no objects / only arrays.

Even so, numbers will be represented in decimal ascii, instead of just packed in few bytes.

This space inefficiency will translate into more lag and less FPS for your users.

Also note that Barotrauma imposes limits on message sizes, if your message becomes too big, you might need to split it into multiple messages, which might increase lag further.

If I have some time, I will try to implement string.pack and string.unpack, which are lua 5.3 features MoonSharp lacks. This will allow implementing much more space efficient struct packing than possible with JSON.
Glothia 6 May, 2024 @ 8:08pm 
Can you make the json module available? It will make syncing more than one state easier.
Matheus  [author] 2 Feb, 2024 @ 4:53pm 
That works as well, but in lua you don't need to declare a parameter you won't use.
Functions are untyped, and there is no runtime enforcement of arguments passed versus parameters taken.
If you pass more arguments than parameters, extra arguments are discarded.
If you pass less arguments than parameters, then unfilled arguments will just have 'nil' value.
Ɑ͞ ̶͞ ̶͞ ﻝﮞ 2 Feb, 2024 @ 1:00pm 
Complete example should be for that
inp = {}
function upd(deltaTime)
if inp[1] < 80 then
out[1] = "text"
end
end