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

Question

Ah, yes. I am a noob when it comes to Lua, so if there is a very simple and obvious solution to this problem let me apologize in advance.

Alright, here is the problem: I have this mod Thut's Elevators installed so you can make realistically working elevators in Minecraft. I have this program to control the elevator through buttons on a tier 2 screen. But due to how the mod is made you can't have a screen on board in the elevator, so I need to have a screen on each new elevator destination. The buttons are working and can send the elevator from one screen, but I can't switch it to another screen and re-draw the buttons when arriving.

Here is the code:

local component = require("component")
local tty = require("tty")
local event = require("event")
local gpu = component.gpu
local lift = component.lift
local screen = component.screen

local bkgrdColor = gpu.getBackground()

local buttons = {}


local screens = {
"a4bd2de3-cbaf-4a4b-ac3b-acf2dbd62bc1",
"f48c1033-81ea-432d-ae91-73bfaca47334",
"2bb63258-c785-42be-8598-573e457a38d7",
"c07ce065-ac3a-4877-9802-ee381036d1a1",
"cc5570bc-cbb1-4966-9586-171938103bcd",
"ef89a0c1-615a-4998-a6e2-d701a22260cf",
"acce1910-793e-4668-81a0-8ddac3f26bab",
}

local floors = { --The Y-coordinates the elevator stops by 1-7.
"67",
"72",
"78",
"83",
"88",
"93",
"98",
}

local currentScreen = screens[1]

local function newButton(x,y,number)
  gpu.setBackground(0x990000)
  gpu.fill(x,y,3,3," ")
  gpu.set(x+1,y+1,number)
  gpu.setBackground(bkgrdColor)
  buttons[number] = {x,y}
end

local function doButtons()
  newButton(2,2,"1")
  newButton(6,2,"2")
  newButton(10,2,"3")
  newButton(14,2,"4")
  newButton(18,2,"5")
  newButton(22,2,"6")
  newButton(26,2,"7")
end

gpu.setResolution(29,15)
tty.clear()


doButtons()


while true do
  local _,_,x,y = event.pull("touch")
  
  
  
  for i in pairs(buttons) do
    
	
	
	
    if x >= buttons[i][1] and x <= buttons[i][1]+3 and y >= buttons[i][2] and y <= buttons[i][2]+3 then
	  
	  currentScreen = screens[i]
	  
      gpu.setBackground(0x008153)
	  gpu.fill(buttons[i][1],buttons[i][2],3,3," ")
	  os.sleep(0.05)
	  lift.callFloor(tonumber(i))
	  gpu.setBackground(0x990000)
	  gpu.fill(buttons[i][1],buttons[i][2],3,3," ")
	  gpu.set(buttons[i][1]+1,buttons[i][2]+1,i)
	  gpu.setBackground(bkgrdColor)
    end
  end
end

The elevators API:

 

2017-10-19_20.03.58.png

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Alright, thanks.

I did try to add this part to the click function:

if gpu.getScreen() ~= screens[i] then
    gpu.bind(tostring(screens[i]))
    doButtons()
end

But for some reason it won't switch to that screen. When I do it manually in the Lua interpreter it works fine. You know what the problem is?

Link to post
Share on other sites
  • 0

Ok, I solved it.

if tostring(gpu.getScreen()) ~= tostring(screens[i]) then
	gpu.bind(tostring(screens[tonumber(i)]))
	gpu.setResolution(29,15)
	tty.clear()
	doButtons()
end

It seems like Lua doesn't convert the variables sometimes. So it searched for example "1" instead of 1.

Link to post
Share on other sites

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.