Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function string:split(delimiter)
- local result = { }
- local from = 1
- local delim_from, delim_to = string.find( self, delimiter, from )
- while delim_from do
- table.insert( result, string.sub( self, from , delim_from-1 ) )
- from = delim_to + 1
- delim_from, delim_to = string.find( self, delimiter, from )
- end
- table.insert( result, string.sub( self, from ) )
- return result
- end
- function increment(variable, value)
- return variable + value
- end
- function decrement(variable, value)
- return variable - value
- end
- --Now uses "aspects.color" instead, defined at line 35 which translate to the corresponding number according to the table below, this is included by computronics
- --Aspects:
- --1 Green
- --2 Blink Yellow
- --3 Yellow
- --4 Blink Red
- --5 Red
- local c = require("component")
- local event = require("event")
- local rec = c.digital_receiver_box
- local con = c.digital_controller_box
- local aspects = c.digital_controller_box.aspects
- local tokens = {}
- tokens[1] = {2, 2}
- tokens[2] = {1, 1}
- for k,v in pairs(tokens) do
- con.setAspect(k .. "-ctrl", aspects.green)
- end
- local running = true
- while running do
- local myEvent, address, origin, aspect, player = event.pull()
- -- print(myEvent, address, origin, aspect, player)
- if (myEvent == "interrupted") then
- running = false
- for k,v in pairs(tokens) do
- con.setAspect(k .. "-ctrl", 5)
- end
- elseif (myEvent == "aspect_changed") then
- local data = string.split(origin, "-")
- local group = tonumber(data[1])
- local mode = data[2]
- if (aspect == aspects.green) then
- -- print("Group: " .. group, "Mode: " .. mode)
- -- print("Group currently has " .. tokens[group][1] .. "/" .. tokens[group][2] .. " tokens.")
- if (mode == "in") then
- if (tokens[group][1] > 0) then
- tokens[group][1] = decrement(tokens[group][1], 1)
- print("Group " .. group .. " now has " .. tokens[group][1] .. "/" .. tokens[group][2] .. " tokens")
- end
- elseif (mode == "out") then
- if (tokens[group][1] < tokens[group][2]) then
- tokens[group][1] = increment(tokens[group][1], 1)
- print("Group " .. group .. " now has " .. tokens[group][1] .. "/" .. tokens[group][2] .. " tokens")
- end
- end
- if (tokens[group][1] == 0) then
- con.setAspect(group .. "-ctrl", aspects.red)
- else
- con.setAspect(group .. "-ctrl", aspects.green)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement