diff options
author | Maverick2797 <git.maverick2797@gmail.com> | 2024-08-17 11:43:35 +0800 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2024-09-02 22:22:38 +0200 |
commit | 55108ae38e467e190abd6f9bf087a9a73f953a08 (patch) | |
tree | 691ccfb1d31621033067f3f9dd4f86c16f1a6dbc /advtrains_luaautomation | |
parent | 3b83580faccfbe5b23cea04bd3e6e0810572c7c0 (diff) | |
download | advtrains-55108ae38e467e190abd6f9bf087a9a73f953a08.tar.gz advtrains-55108ae38e467e190abd6f9bf087a9a73f953a08.tar.bz2 advtrains-55108ae38e467e190abd6f9bf087a9a73f953a08.zip |
LuaATC set_fc(): add argument to reset fc index to 1
Diffstat (limited to 'advtrains_luaautomation')
-rw-r--r-- | advtrains_luaautomation/README.md | 6 | ||||
-rw-r--r-- | advtrains_luaautomation/atc_rail.lua | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index a885075..0bf56bb 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -274,9 +274,11 @@ Each wagon has a current FC, indicating its next destination. Command: `get_fc()` Result: `{"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"}` - - `set_fc(fc_list)` + - `set_fc(fc_list, reset_index)` Overwrites the FC list according to a table `fc_list`. A false or nil entry will leave the wagon unaffected, however all others will be overwritten. - Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually. + Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually. If the new FC entry for a wagon is shorter than the old entry, the index will clip to the last FC in the new entry. + If `reset_index` is true, all Current FC values will reset to the first entry in the list, instead of remaining at the current index. + Example: train has FC lists: `"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"` Command: `set_fc({"", "foo!turtle", nil, "4tehlulz", false})` Result: `""` `"foo!turtle"` `"testing"` `"4tehlulz"` `"hello_world"` diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua index ead1031..b98648e 100644 --- a/advtrains_luaautomation/atc_rail.lua +++ b/advtrains_luaautomation/atc_rail.lua @@ -99,7 +99,7 @@ function r.fire_event(pos, evtdata, appr_internal) end return fc_list end, - set_fc = function(fc_list) + set_fc = function(fc_list,reset_index) assertt(fc_list, "table") if not train_id then return false end -- safety type-check for entered values @@ -113,9 +113,9 @@ function r.fire_event(pos, evtdata, appr_internal) if fc_list[index] then -- has FC to enter to this wagon local data = advtrains.wagons[wagon_id] if data then -- wagon actually exists - --direct copy from wagons.lua, allowing for the :split function + --effectively copyied from wagons.lua, allowing for the :split function and reset_index data.fc = fc_list[index]:split("!") - if not data.fcind then + if reset_index or not data.fcind then data.fcind = 1 elseif data.fcind > #data.fc then data.fcind = #data.fc |