- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
TheEpicGamer909
-
Content Count
3 -
Joined
-
Last visited
Posts posted by TheEpicGamer909
-
-
Hey can you please include the snippet of code that caused the error since I'm not sure my computer format your file correctly.
done
-
Hi, so I'm making a program that draws some buttons and teleports you to specific coordinates when you click on their respective buttons. I'm getting an error of something along the lines of "attempt to compare number with nil" at line 112. I checked the code and there shouldn't be anything wrong. Any help would be appreciated.
component = require("component") gpu = component.gpu term = require("term") command_block = component.command_block event = require("event") local users = {"TheEpicGamer909","Skutten2002"} local authorized = false local places = {} places.station = {} places.station["x"] = 218 places.station["y"] = 151 places.station["z"] = 60 places.library = {} places.library["x"] = 205 places.library["y"] = 112 places.library["z"] = 59 places.roomComputer = {} places.roomComputer["x"] = 206 places.roomComputer["y"] = 106 places.roomComputer["z"] = 71 places.docks = {} places.docks["x"] = 218 places.docks["y"] = 104 places.docks["z"] = 77 places.roomWarLeft = {} places.roomWarLeft["x"] = 221 places.roomWarLeft["y"] = 99 places.roomWarLeft["z"] = 70 places.roomWarRight = {} places.roomWarRight["x"] = 221 places.roomWarRight["y"] = 99 places.roomWarRight["z"] = 79 places.emergency = {} places.emergency["x"] = 227 places.emergency["y"] = 99 places.emergency["z"] = 79 places.projector = {} places.projector["x"] = 207 places.projector["y"] = 99 places.projector["z"] = 76 places.roomBed = {} places.roomBed["x"] = 212 places.roomBed["y"] = 91 places.roomBed["z"] = 72 local function Button (x,y,width,height,colorText,colorBackground,text,isPressed) local button = {} button.x = x button.y = y button.width = width button.height = height button.colorText = colorText button.colorBackground = colorBackground button.text = text function button.draw () gpu.setForeground(button.colorText) gpu.setBackground(button.colorBackground) gpu.fill(x,y,width,height," ") gpu.set(button.x + math.floor((button.width - #text) / 2),button.y + math.floor((button.height-1) / 2),button.text) gpu.setForeground(0xFFFFFF) gpu.setBackground(0x000000) end --[[function button.isClicked(x,y) return (x >= button.x and x < button.x + button.width and y >= button.y and y < button.y + button.height) end]] --the error first appeared in this function, i commented this out and tried putting the code directly into line 112, where the error appears now return button end local function teleport (place,name) for _,user in pairs(users) do if name == user then authorized = true end end if authorized == true then command_block.setCommand("/tp" .. " " .. name .. " " .. places[place["x"]] .. " " .. places[place["y"]] .. " " .. places[place["z"]]) command_block.run() authorized = false command_block.setCommand("") end end command_block.setCommand("") term.clear() --[[gpu.setResolution(17,8)]] --so you can see the errors local buttons = {} buttons.station = Button(1,1,17,1,0x000000,0xFFA500,"Station") buttons.library = Button(1,2,17,1,0x000000,0xFFFF00,"Library") buttons.roomComputer = Button(1,3,17,1,0x000000,0xFFA500,"Computer Room") buttons.docks = Button(1,4,17,1,0x000000,0xFFFF00,"Docks") buttons.roomWarLeft = Button(1,5,9,1,0xFFFFFF,0x404040,"War") buttons.roomWarRight = Button(10,5,8,1,0x000000,0xbfbfbf,"Room") buttons.emergency = Button(1,6,17,1,0x000000,0xFFFF00,"Emergency") buttons.projector = Button(1,7,17,1,0x000000,0xFFA500,"Projector") buttons.roomBed = Button(1,8,17,1,0x000000,0xFFFF00,"Bedroom") buttons.station.draw() buttons.library.draw() buttons.roomComputer.draw() buttons.docks.draw() buttons.roomWarLeft.draw() buttons.roomWarRight.draw() buttons.emergency.draw() buttons.projector.draw() buttons.roomBed.draw() term.setCursor(17,8) while true do local touch = {event.pull("touch")} for buttonName,buttonContent in pairs(buttons) do if ((touch.x >= buttonContent.x and touch.x < buttonContent.x + buttonContent.width) and (y >= buttonContent.y and y < buttonContent.y + buttonContent.height)) == true then --here is the error teleport(buttonName,touch.playerName) end end --[[if touch.y == 1 then teleport("station",touch.playerName) elseif touch.y == 2 then teleport("library",touch.playerName) elseif touch.y == 3 then teleport("roomComputer",touch.playerName) elseif touch.y == 4 then teleport("docks",touch.playerName) elseif (touch.y == 5 and (touch.x >= 1 and touch.x <= 9)) then teleport("roomWarLeft",touch.playerName) elseif (touch.y == 5 and (touch.x >= 10 and touch.x <=17)) then teleport("roomWarRight",touch.playerName) elseif touch.y == 6 then teleport("emergency",touch.playerName) elseif touch.y == 7 then teleport("projector",touch.playerName) elseif touch.y == 8 then teleport("roomBed",touch.playerName) end]] --if i use this (less portable) code instead of the for loop above, it doesn't do anything at all when i click a button end
Attempt to compare number with nil
in Programming
Posted
I followed your advice, but now it says that the same block of code (now at line 86) attempts to compare a number with a string.