Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
killmetohell

Draconic tool tier code Improvement

Question

I need some help in improving my code in my Draconic tool tier i have five out that the recipes for the each tier is the same other then different key upgrades using it.

I'm new to coding thing in lua and i hoping posting would help in learning how to improve my code.

Heres my code.

local component = require("component")
local sides = require("sides")
local colors = require("colors")
local rs = component.redstone
local tier = 0
local c = 15 --color also using enderio cables

while true do
if rs.getBundledInput(sides.top,colors.red) > 0 then -- this part of ther code changes what tier it using redstone signals
  tier = tier + 1
  ptier = tier -1
  c = c - 1
  pc = c + 1
  print("Tier",tier)
  os.sleep(1)
end
if rs.getBundledInput(sides.top,colors.green) > 0 then
 tier = tier - 1
 ptier = tier + 1
  c = c + 1
  pc = c - 1
 print("Tier",tier)
  os.sleep(1)
end

-- ignore this part of the code it old code i plan it reuse later if my new code doesn't work for what i'm using it for.
--[[if ptier ~= tier and tier ~= 0 and rs.getInput(sides.top) then
--if rs.getBundledInput(sides.top,colors.red) > 0 or rs.getBundledInput(sides.top,colors.green) > 0 and ptier ~= tier and tier ~= < 1 then
  print("color",c)
  print("prev. color",c) 
    rs.setBundledOutput(sides.back,pc,0)
    rs.setBundledOutput(sides.back,colors.black,15)
    os.sleep(1)
    rs.setBundledOutput(sides.back,colors.black,0)
end--]]

if tier > 0 then --this checks if tier greater than 0 also makes my tier system works
  print("color",c) --these print stuff are debug code to check if what my current color and before color and tier
  print("pcolor",pc)
  print("ptier",ptier)
  rs.setBundledOutput(sides.back,c,15) --this turns what on c is for what tier is it for making so i shift what tiers i want extracting items to the injectors
  if rs.getInput(sides.front) == 1 then
    rs.setBundledOutput(sides.back,c,0)
    os.sleep(1)
  end
  --ignore this i was wondering if this will fix my last tiers being left on
  --[[os.sleep(1)
  if ptier == 1 and rs.getInput(sides.front) ~= 1 then
  rs.setBundledOutput(sides.back,pc,0)
  rs.setBundledOutput(sides.back,colors.black,15)
  os.sleep(2)
  rs.setBundledOutput(sides.back,colors.black,0)
  elseif ptier == 2 and rs.getInput(sides.front) ~= 1 then
   rs.setBundledOutput(sides.back,pc,0)
  rs.setBundledOutput(sides.back,colors.black,15)
  os.sleep(2)
  rs.setBundledOutput(sides.back,colors.black,0)
  elseif ptier == 3 and rs.getInput(sides.front) ~= 1 then
  rs.setBundledOutput(sides.back,pc,0)
  rs.setBundledOutput(sides.back,colors.black,15)
  os.sleep(2)
  rs.setBundledOutput(sides.back,colors.black,0)
 end--]]
 
  if rs.getInput(sides.front) == 0 then --this part code i had hard time figuring out due i had no idea how to fix my past tiers being left on so suppect there some or lot of code needs to be fixed.
  rs.setBundledOutput(sides.back,pc,0)
  rs.setBundledOutput(sides.back,colors.black,15)
  os.sleep(5)
  rs.setBundledOutput(sides.back,colors.black,0)
  os.sleep(5)
  elseif ptier ~= 0 and ptier ~= tier then
  rs.setBundledOutput(sides.back,pc,0)
  rs.setBundledOutput(sides.back,colors.black,15)
  os.sleep(5)
  rs.setBundledOutput(sides.back,colors.black,0)
  os.sleep(1)
  ptier = tier
end

end
if tier == 0 then --i need to figure out how fix this one. this part of the code makes so if its on tier 0 it would make sure all redstone signals are off but i need to figure how make the code stop once its done i think make need change how this works.
  for i = 0,15 do
  print("color cont.",i)
  os.sleep(1)
  if rs.getBundledOutput(sides.back,i) > 0 then
  rs.setBundledOutput(sides.back,colors.black,15)
  os.sleep(1)
  rs.setBundledOutput(sides.back,i,0)
end
end
end
os.sleep(1)--this is there so i can break my loop
end

got any ideas or good way make this code better can please tell me.

oh i am using a modpack called sky factory 3 on 3.0.13 so i hope help you give idea on what mods i have.

 

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.