--Environment Code F.error = function(set) local error_indicator = POS(-4025,13,-2671) if set ~= nil then setstate(error_indicator,(set and "on") or "off") end return (getstate(error_indicator) == "on") or false end F.yard_active = function(set) --if set == true then yard = active local yard_indicator = POS(-4025,14,-2659) if set ~= nil then setstate(yard_indicator,(set and "on") or "off") end return (getstate(yard_indicator) == "on") or false end F.dir = function(set) -- if set == true then dir = pointing north local dir_indicator = POS(-4025,13,-2665) if set ~= nil then setstate(dir_indicator,(set and "on") or "off") end return (getstate(dir_indicator) == "on") or false end F.get_rc_safe = function() return get_rc() or "" end F.has_rc = function(query,rc_list) -- query eg: "rc1" if rc_list == "" or query == nil or query=="" then return false end if not rc_list then rc_list = F.get_rc_safe() end for word in rc_list:gmatch("[^%s]+") do if word == query then return true end end print(F.get_rc_safe()) return false end F.remove_rc = function(rc_list,arrow_mode) -- rc_list eg: {"rc1","rc2"} -- rc_list MUST be a table of rc codes to remove -- eg: {"rc1","rc2"} -- Arrow Modes: -- true: with arrow direction -- false: against arrow direction -- nil: ignores arrow direction if not atc_id then return false end if (arrow_mode == nil) or (atc_arrow == arrow_mode) then local rc = F.get_rc_safe() rc_list = rc_list or {} local rc_remove = {} for _,v in pairs(rc_list) do rc_remove[v] = true end -- remove codes from train's rc local reinsert = {} for token in rc:gmatch("[^%s]+") do if not rc_remove[token] then table.insert(reinsert,token) end end -- insert new string to train's rc set_rc(table.concat(reinsert," ")) end print(F.get_rc_safe()) return reinsert end F.remove_rc_match = function(rc_list) -- rc_list eg: "rc_%d+" local rm = {} for v in F.get_rc_safe():gmatch("("..rc_list..")") do table.insert(rm,v) end F.remove_rc(rm) print(F.get_rc_safe()) return rm end F.add_rc = function(rc_list) -- rc_list eg {"rc1","rc2"} OR "rc1 rc2" if not atc_id then return false end if type(rc_list) == "table" then rc_list = table.concat(rc_list," ") end set_rc(F.get_rc_safe().." "..rc_list) print(F.get_rc_safe()) return true end