Besiege

Besiege

103 ratings
Logic extensions mod
3
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
6.316 MB
24 Feb, 2020 @ 2:42pm
15 Jun, 2024 @ 1:36pm
39 Change Notes ( view )

Subscribe to download
Logic extensions mod

Description
Update 2024
It seems that the latest game update brings some breaking changes, making this mod impossible in multiplayer mode. Unfortunately it can now work in single-player mode only.

[BIG UPDATE]
Mod was reworked to support new besiege 'message' keys:
1) Once old machine, built with this mod, is loaded, it's keys will be silently converted to new Besiege keys with message support. Before overwriting saved machine you may back-up it just in case something goes wrong with conversion.
2) All numeric ExtKey values will be converted to messages and will be editable in corresponding menu. External text input is removed.
3) ExtKey (ones in automation blocks and CPU) simulates BOTH selected normal keys AND message keys at the same time. No matter what position of corresponding switch in mapper is set.
4) Besiege keys (in all blocks except automation blocks) in contrast react ONLY the mode you selected (key OR message).
5) If ExtKey generates LERP [0..1] value output, it can be accepted by modified blocks, listed in mod description, not only by key, but by message also.

[Notice]
2021-12-19 - mod was updated because of a serious bug found in ExtKey toggle mechanism. All machines I tested worked fine, but there still is a small possibility this is a breaking change.

[Warning!!!!11]
This mod is fragile. This means it can be ruined (with machines depending on it!) if a game is updated, and it can take a time to fix it.

Features
This mod brings new automation possibilities into Besiege.

ExtKey
Logic extensions mod is useful when you need to make a complicated automation logic for your machine. For this purpose Sensor, Altimeter, LogicGate, Anglometer and Speedometer blocks (actually all except timer) get extended keys (ExtKeys) support.

ExtKeys can emulate non-binary output. This means, you can emulate not only "pressed" and "released" states, but any kind of "slightly pressed", "practically released" and so on. This is acheived by generating a floating point output in a range of [0..1] for each ExtKey emulator.

Sensor
Sensor block gets 'Lerp' toggle, which switches it to detecting distance to the closest object in range. The distance is calculated as linear interpolated (LERP) argument for the sensor's range. For example: if you select 'Distance' to be 10, and the object is detected at the distance of 4, you will get 0.4 to ouput ExtKey.

Execute 'sensordbg true' in console you will see points that were found by sensor in Lerp mode.

Sensor now detects object type in front of it. You can get object info using CPU block by calling api readSensor(pio) on a PIO, that is emulated by sensor now.

Anglometer
Anglometer block gets 'Lerp' toggle, which switches it to output Lerp value between the selected angles. Note that at 0 degrees it has 0 output, and at 360 it has 1. This means if you make a full circle rotation, output will be climing from 0 to 1 and then immediately drop to 0 after passing the start position of anglometer.

Altimeter
Altimeter block gets a second slider, meaning MAX height. The first one becomes MIN height. If selected MAX is below MIN, altimeter behaves in a vanilla way. If MAX is above MIN, emulated ExtKey's value will be height LERP between these two sliders.

Speedometer
Speedometer block gets a second slider, meaning MAX speed. The first one becomes MIN speed. If selected MAX is below MIN, Speedometer behaves in a vanilla way. If MAX is above MIN, emulated ExtKey's value will be speed LERP between these two sliders.

If you select any block(s) in build mode and hold ` button, you will see it's IO connections. Green lines come from emulators to selected consumer block, red ones - from selected emulator to consumers.

Control block extensions
Steering hinge, steering, powered wheels, cogs and flying block now can use non-binary output of ExtKeys, mapped to real keyboard. To enable this functionality, you should toggle new "FPIO" button on a corresponding block.

Steering hinge
For this block behavior changes only in Auto-Return + Limit Angle mode. Incoming FPIO difference on left and right emulated keys becomes a LERP parameter for the rotation angle.

Steering, Wheels, Cogs
Incoming FPIO difference on left and right emulated keys becomes speed of rotation.

Flying Block, Water Cannon
Incoming FPIO becomes power.

Piston
Incoming FPIO becomes extend length.

CPU block (Experimental)
Requires a basic programming knowlege.
This is an extensible block, that has up to 100 general IO ExtKeys and JavaScript language interpreter. It can read/write values to it's IO ports (PIO, = ExtKeys) with the code and supports interrupts mechanism.

Don't forget to press 'Save' button in CPU window after you finished editing!
Please note that this block is experimental. It can contain random bugs. If you find a bug in CPU you can write about it in the comments.

Gas
This value means (roughly) a maximum number of code lines that can be executed during one game frame. Typically you don't need to touch it. You should avoid executing too much lines per frame, and use asleep() api in long loops.

PIO
Add PIO by pressing "+" button near PIO label and then assign it to a real or virtual key by typing it's code. If you want to lookup code of a real key, check it by mapping via any other block having ExtKeys (you'll see code in text field).

Code
CPU key mapper has a code window with JS-code. Code syntax errors are printed at the bottom. Runtime errors will be printed to console, or they can be caught using try/catch. Open besiege console (ctrl+K by default) and type 'cpuapi' to get cpu API help or check it online at https://github.com/Bargest/LogicExtensions/wiki.

You can find several code examples in mod folder at
<path_to_Steam>\steamapps\workshop\content\346010\2006662730\logic_mod\Resources\examples

readSensor API
Automation blocks (sensor, altimeter, anglometer, speedometer) can now generate additional data (position, velocity, object info, etc) and transmit it to CPU. This data is accessible via readSensor API, described here:
https://github.com/Bargest/LogicExtensions/wiki.

Limitations
1) Machine with keys remapped to virtual IDs can be loaded only with this mod. Loading/resaving this machine without this mod will break all these virtual-space mappings.
2) "Break" (pause break key) is used by this mod as kind of a "gate" to virtual key space. Avoid usage of this key in your machine.

Source
Mod code can be found on github: https://github.com/Bargest/LogicExtensions
Popular Discussions View All (6)
3
15 Jun, 2024 @ 1:37pm
Steering, Wheels FPIO Bug?
憨憨
1
31 Aug, 2024 @ 10:51am
ANGLOMETER's LERP missed ,is it a bug ?
thomasrolling
4
21 May, 2021 @ 12:51pm
Steering Hinge FPIO bug?
Dark
188 Comments
66866806 18 Apr @ 6:19pm 
Why can't I see the "LERP" button any where
氿柒NinetySeven 9 Jul, 2024 @ 5:35am 
伟大,无需多言。
thomasrolling 7 Jul, 2024 @ 6:18am 
Great MOD,but the LERP function in ANGLOMETER stop work in LEVEL EDITOR, the option of
LERP is missed. I dont know why
Lambda  [author] 19 Jun, 2024 @ 2:18pm 
@憨憨, in JS everything is an object. So just
var obj = { field1: 123, field2: 'text1' };
obj.field2 = 'text2';
is ok.
憨憨 17 Jun, 2024 @ 9:41pm 
Great MOD !!! is there a way for me to implement data structures like array or class?
Lambda  [author] 18 May, 2024 @ 11:55am 
@Jinges, unfortunately it works only in single-player mode now. 1.26 update have broken multiplayer support for this mod and I see no way to fix it, like stated in first lines of mod description.
You can run modded machines in default sandboxes and game levels, but cannot run them in multiverse.
Lambda  [author] 18 May, 2024 @ 11:51am 
@No_Lives_Matter, maybe some IDs for workshop have changed. Try open steamapps folder in windows exprorer and search for "00-helloworld.js" in top-right corner. Explorer should find this example. Then just go to file location, it will be mod's folder with example scripts.
No_Lives_Matter 13 May, 2024 @ 11:08pm 
The link to the example js codes is not working for me :/
where could a lad find some codes?
Jinges 13 May, 2024 @ 7:27am 
Does this mod still work in v1.26? either i installed it wrong or something is broken?
Lambda  [author] 10 May, 2024 @ 12:24pm 
@Cay, I didn't understand what do you mean by playing maps offline and why it could break. This whole game is not online.