Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --==========
- --this is lazy API
- --it's shit, made by adsmz (adsmz.com)
- --I don't know lua worth shit
- --it basically just has a few
- --functions I don't wanna type a million times
- --it's licensed with a Creative Commons Attribution-ShareAlike 4.0 license
- --the full text of which can be found at
- -- creativecommons.org/licenses/by-sa/4.0/legalcode
- --with a summary of your rights at
- -- creativecommons.org/licenses/by-sa/4.0
- --==========
- -- Maths
- -- mathy functions that are useful for mathy things
- -- round - round your floats!
- --Takes two arguments, value and places
- --value is the value to round
- --places is the number of decimal places to round to
- function round(value,places)
- if places then
- return math.floor((value * 10^places) + 0.5) / (10^places)
- else
- return math.floor(value + 0.5)
- end
- end
- -- percent - find your percents!
- --Takes two arguments, value and maxValue
- --value is the number that's a percentage of maxValue
- --that makes sense, right? You'll figure it out
- function percent(value,maxValue)
- return (value / maxValue) * 100
- end
- -- roundPercent - round your percents!
- --takes three arguments, value, maxValue, and place
- --value is the number that's a percentage of maxValue
- --place is how many places to round to
- --this is just a combination of roundomatic and percentomatic
- --since I use the two together like this all the time
- function roundPercent(value,maxValue,place)
- return round(percent(value,maxValue),place)
- end
- --==========
- -- Others
- -- functions that aren't mathy
- -- find - find peripherals on any side!
- --Takes one argument, peripheralName
- --peripheralName is the peripheral to look for
- --It finds and wraps the desired peripheral
- function find(peripheralName)
- local sides = {"top","bottom","left","right","front","back"}
- for i = 1, #sides do --I put on my robe and wizard hat
- if peripheral.isPresent(sides[i]) then
- local type = peripheral.getType(sides[i])
- if type == peripheralName then
- return sides[i]
- end
- end
- end
- end
- -- wait - waits for an event!
- --Takes two arguments, eventType and timeout
- --eventType is the type of event to listen for
- --timeout is how long to listen
- --if timeout is nil, it will wait indefinitely
- --it returns a table of the event's parameters
- --it returns "timeout" if the timeout is reached without an input
- --for now, it doesn't look for specific messages, just event types
- function wait(eventType,timeout)
- if timeout then
- os.startTimer(timeout)
- local event,p1,p2,p3,p4,p5 = os.pullEvent(eventType)
- if event ~= eventType then
- return "timeout"
- else
- return {event,p1,p2,p3,p4,p5}
- end
- else
- local event,p1,p2,p3,p4,p5 = os.pullEvent(eventType)
- return {event,p1,p2,p3,p4,p5}
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement