Main Menu

242 error help

Started by MarsOdin, Mar 26, 2019, 01:29 AM

Previous topic - Next topic

MarsOdin

What is this 242 error?
[attach name=2.png type=image/png]68[/attach]

I don't know exactly when it happens, but it has to do with the interaction of these two programs:

term.clear()

-----------------------------------------------------------------------------
-- LOAD DATA
-----------------------------------------------------------------------------
local tempData, inventory = {},{}

function loadAll()

    local file = fs.open("SpaceAdventure/data/tempData.lua","r")
    local data = file.readAll()
    file.close()
    tempData = textutils.unserialize(data)

end
loadAll()

function loadAll2()

    for i = 1, #tempData.inventoryId do
        local file = fs.open("SpaceAdventure/inventories/"..tostring(tempData.inventoryId[i])..".lua","r")
        local data = file.readAll()
        file.close()
        inventory[i] = textutils.unserialize(data)
    end

end
loadAll2()

-----------------------------------------------------------------------------
-- SAVE DATA FUNCTIONS
-----------------------------------------------------------------------------
function saveTempData(tempDataTable)
    local file = fs.open("SpaceAdventure/data/tempData.lua","w")
    file.write(textutils.serialize(tempDataTable))
    file.close()
end

-----------------------------------------------------------------------------
-- SCREEN TITLE & DESIGN
-----------------------------------------------------------------------------
function ScreenTitle(PosX,title,additional)
    term.setCursorPos(1,1)
    term.setBackgroundColor(2048)
    for i = 1,52 do
        term.write(" ")
    end
    term.setCursorPos(PosX,1)
    term.setTextColor(16)
    term.write(title.." "..additional)
end
ScreenTitle(21,"SHIP MENU"," ")

local forScreenDesign = {
    [1] = {text="Crew members: ", pullData=#tempData.crewMember, PosY=3};
    [2] = {text="Sector: ", pullData=tempData.sector.." - "..tempData.sectorType, PosY=5};
}

function ScreenDesign()
    term.setBackgroundColor(2^11)
    for i = 2,19 do
        term.setCursorPos(25,i)   
        term.write(" ")
    end
    term.setBackgroundColor(2^15)
   
    for i = 1,#forScreenDesign do
        term.setCursorPos(27,forScreenDesign[i].PosY)
        term.setTextColor(2^9)
        term.write(forScreenDesign[i].text)
        term.setTextColor(2^0)
        term.write(forScreenDesign[i].pullData)
    end
 
end
ScreenDesign()

-----------------------------------------------------------------------------
-- MENU
-----------------------------------------------------------------------------
local sId = 1
local runMenu = true
local lastScreen = "/SpaceAdventure/screens/MainMenu.lua"

function printMenu(menu,textColor,textBackgroundColor,selectionColor)
    term.setTextColor(textColor)
    for i=1,#menu do
        term.setCursorPos(menu[i].PosX,menu[i].PosY)
        if i == sId then
            term.setBackgroundColor(selectionColor)
            print(menu[i].text)
        else
            term.setBackgroundColor(textBackgroundColor)
            print(menu[i].text)
        end
    end
    term.setBackgroundColor(textBackgroundColor)
end
function onKeyPressedVertical(key,menu)
    if key == keys.w then
        if sId > 1 then
            sId = sId-1
        end
    elseif key == keys.s then
        if sId < #menu then
            sId = sId+1
        end
    elseif key == keys.d then
        tempData.lastScreen = lastScreen
        saveTempData(tempData)
        menu[sId].handler()
        sId = 1
    elseif key == keys.a then
        runMenu = false
        if tempData.lastScreen ~= lastScreen then
            shell.run(tempData.lastScreen)
        else
            shell.run("/SpaceAdventure/screens/MainMenu.lua")
        end
    end
end

function handlerMap()
    runMenu = false
    shell.run("/SpaceAdventure/screens/Map.lua")
end
function handlerCrew()
    runMenu = false
    shell.run("/SpaceAdventure/screens/Crew.lua")
end
function handlerInspectInventory()
    tempData.selectedInventoryId = tempData.shipId
    saveTempData(tempData)
    runMenu = false
    shell.run("/SpaceAdventure/screens/InspectInventory.lua")
end
function handlerTasks()
    runMenu = false
    shell.run("/SpaceAdventure/screens/Tasks.lua")
end
function handlerExitGame()
    runMenu = false
    term.clear()
    term.setCursorPos(1,1)
    term.setTextColor(1)
    print("Game Exited")
end

local newMenu = {}
while runMenu == true do
    newMenu = {
        [1] = {text=" MAP  ", handler=handlerMap, PosX=5, PosY=5},
        [2] = {text=" CREW  ", handler=handlerCrew, PosX=5, PosY=6},
        [3] = {text=" CARGO BAY ", handler=handlerInspectInventory, PosX=5, PosY=7},
        [4] = {text=" EXIT ", handler=handlerExitGame, PosX=5, PosY=17}
    }
    printMenu(newMenu,32,32768,2048)
    event, key = os.pullEvent("key")
    onKeyPressedVertical(key,newMenu)
end


term.clear()

-----------------------------------------------------------------------------
-- LOAD DATA
-----------------------------------------------------------------------------
local tempData, sectorObjects, sectorObject, crewMember = {}, {}, {}, {}

function loadAll()

    local file = fs.open("SpaceAdventure/data/tempData.lua","r")
    local data = file.readAll()
    file.close()
    tempData = textutils.unserialize(data)

    local file = fs.open("SpaceAdventure/world/sectorObjects.lua","r")
    local data = file.readAll()
    file.close()
    sectorObjects = textutils.unserialize(data)

end
loadAll()

function loadAll2()

    for i = 1, #sectorObjects do
        local file = fs.open("SpaceAdventure/world/"..tostring(sectorObjects[i])..".lua","r")
        local data = file.readAll()
        file.close()
        sectorObject[i] = textutils.unserialize(data)
    end

    for i = 1, #tempData.crewMember do
        local file = fs.open("SpaceAdventure/people/"..tostring(tempData.crewMember[i])..".lua","r")
        local data = file.readAll()
        file.close()
        crewMember[i] = textutils.unserialize(data)
    end

end
loadAll2()

-----------------------------------------------------------------------------
-- SAVE DATA FUNCTIONS
-----------------------------------------------------------------------------
function saveTempData(tempDataTable)
    local file = fs.open("SpaceAdventure/data/tempData.lua","w")
    file.write(textutils.serialize(tempDataTable))
    file.close()
end

-----------------------------------------------------------------------------
-- SCREEN TITLE
-----------------------------------------------------------------------------
function ScreenTitle(PosX,title,additional)
    term.setCursorPos(1,1)
    term.setBackgroundColor(2048)
    for i = 1,52 do
        term.write(" ")
    end
    term.setCursorPos(PosX,1)
    term.setTextColor(16)
    term.write(title.." "..additional)
end
ScreenTitle(23,"MAP"," ")

-----------------------------------------------------------------------------
-- MAP
-----------------------------------------------------------------------------
local coord = 1
local coordPosition = {
    [1] = {text="01", PosX=2 ,PosY=3},
    [2] = {text="02", PosX=5 ,PosY=3},
    [3] = {text="03", PosX=8 ,PosY=3},
    [4] = {text="04", PosX=11 ,PosY=3},
    [5] = {text="05", PosX=14 ,PosY=3},
    [6] = {text="06", PosX=17 ,PosY=3},
    [7] = {text="07", PosX=20 ,PosY=3},
    [8] = {text="08", PosX=2 ,PosY=5},
    [9] = {text="09", PosX=5 ,PosY=5},
    [10] = {text="10", PosX=8 ,PosY=5},
    [11] = {text="11", PosX=11 ,PosY=5},
    [12] = {text="12", PosX=14 ,PosY=5},
    [13] = {text="13", PosX=17 ,PosY=5},
    [14] = {text="14", PosX=20 ,PosY=5},
    [15] = {text="15", PosX=2 ,PosY=7},
    [16] = {text="16", PosX=5 ,PosY=7},
    [17] = {text="17", PosX=8 ,PosY=7},
    [18] = {text="18", PosX=11 ,PosY=7},
    [19] = {text="19", PosX=14 ,PosY=7},
    [20] = {text="20", PosX=17 ,PosY=7},
    [21] = {text="21", PosX=20 ,PosY=7},
    [22] = {text="22", PosX=2 ,PosY=9},
    [23] = {text="23", PosX=5 ,PosY=9},
    [24] = {text="24", PosX=8 ,PosY=9},
    [25] = {text="25", PosX=11 ,PosY=9},
    [26] = {text="26", PosX=14 ,PosY=9},
    [27] = {text="27", PosX=17 ,PosY=9},
    [28] = {text="28", PosX=20 ,PosY=9},
    [29] = {text="29", PosX=2 ,PosY=11},
    [30] = {text="30", PosX=5 ,PosY=11},
    [31] = {text="31", PosX=8 ,PosY=11},
    [32] = {text="32", PosX=11 ,PosY=11},
    [33] = {text="33", PosX=14 ,PosY=11},
    [34] = {text="34", PosX=17 ,PosY=11},
    [35] = {text="35", PosX=20 ,PosY=11},
    [36] = {text="36", PosX=2 ,PosY=13},
    [37] = {text="37", PosX=5 ,PosY=13},
    [38] = {text="38", PosX=8 ,PosY=13},
    [39] = {text="39", PosX=11 ,PosY=13},
    [40] = {text="40", PosX=14 ,PosY=13},
    [41] = {text="41", PosX=17 ,PosY=13},
    [42] = {text="42", PosX=20 ,PosY=13},
    [43] = {text="43", PosX=2 ,PosY=15},
    [44] = {text="44", PosX=5 ,PosY=15},
    [45] = {text="45", PosX=8 ,PosY=15},
    [46] = {text="46", PosX=11 ,PosY=15},
    [47] = {text="47", PosX=14 ,PosY=15},
    [48] = {text="48", PosX=17 ,PosY=15},
    [49] = {text="49", PosX=20 ,PosY=15}
}

term.setTextColor(128)
for i = 1,49 do
    term.setBackgroundColor(32768)
    term.setCursorPos(coordPosition[i].PosX,coordPosition[i].PosY)
    print(coordPosition[i].text)
end

-- SYSTEM OBJECTS -----------------------------------------------------------
term.setTextColor(32768)
for i = 1, #sectorObject do
    term.setCursorPos(sectorObject[i].PosX,sectorObject[i].PosY)
    term.setBackgroundColor(sectorObject[i].color)
    print(sectorObject[i].sector)
end

-- MAP LEGEND ---------------------------------------------------------------
local legendSystemObject = {
    [1] = {name="Current Pos: ", color=32, PosX=24, PosY=4},
    [2] = {name="Sun", color=16, PosX=24, PosY=6},
    [3] = {name="Rock Planet", color=4096, PosX=24, PosY=8},
    [4] = {name="Ocean Planet", color=2048, PosX=24, PosY=10},
    [5] = {name="Ice Planet", color=8, PosX=24, PosY=12},
    [6] = {name="Asteroid", color=1024, PosX=24, PosY=14}
}

function mapLegend(cursorPosX,cursorPosY,color,text)
    term.setCursorPos(cursorPosX,cursorPosY)
    term.setBackgroundColor(color)
    term.write(" ")
    term.setTextColor(color)
    term.setBackgroundColor(32768)
    print(" "..text)
end
for i = 1,#legendSystemObject do
    mapLegend(legendSystemObject[i].PosX,legendSystemObject[i].PosY,legendSystemObject[i].color,legendSystemObject[i].name)
end

-----------------------------------------------------------------------------
-- POSITION
-----------------------------------------------------------------------------
function CurrentPos()
    term.setCursorPos(coordPosition[tempData.sector].PosX,coordPosition[tempData.sector].PosY)
    term.setTextColor(32768)
    term.setBackgroundColor(32)
    print(coordPosition[tempData.sector].text)
end
CurrentPos()

local OverObject = false
function LocationInSystem()
    term.setBackgroundColor(32768)
    term.setCursorPos(38,4)
    term.setTextColor(128)
    term.write(" Space")
    term.setCursorPos(38,4)
end
LocationInSystem()

for i = 1, #sectorObject do
    if tempData.sector == sectorObject[i].sector or "0"..tempData.sector == sectorObject[i].sector then
        term.setTextColor(sectorObject[i].color)
        term.write(" "..sectorObject[i].type)
        OverObject = true
    end
end

-----------------------------------------------------------------------------
-- MENU
-----------------------------------------------------------------------------
local sId = 1
local runMenu = true
local lastScreen = "/SpaceAdventure/screens/Map.lua"
local pilotAssigned = false

function printMenu(menu,textColor,textBackgroundColor,selectionColor)
    term.setTextColor(textColor)
    for i=1,#menu do
        term.setCursorPos(menu[i].PosX,menu[i].PosY)
        if i == sId then
            term.setBackgroundColor(selectionColor)
            print(menu[i].text)
        else
            term.setBackgroundColor(textBackgroundColor)
            print(menu[i].text)
        end
    end
    term.setBackgroundColor(textBackgroundColor)
end
function onKeyPressedVertical(key,menu)
    if key == keys.w then
        if sId > 1 then
            sId = sId-1
        end
    elseif key == keys.s then
        if sId < #menu then
            sId = sId+1
        end
    elseif key == keys.d then
        tempData.lastScreen = lastScreen
        saveTempData(tempData)
        menu[sId].handler()
        sId = 1
    elseif key == keys.a then
        runMenu = false
        shell.run("/SpaceAdventure/screens/MainMenu.lua")
    end
end

function handlerSetDestination()

    for i = 1,#tempData.crewMember do
        if crewMember[i].currentTask == "Piloting" then pilotAssigned = true end
    end
    if pilotAssigned == true then
        shell.run("/SpaceAdventure/screens/SetDestination.lua")
        runMenu = false
    else
        term.setCursorPos(1,19)
        term.setTextColor(16384)
        term.write("THERE IS NO PILOT ASSIGNED                ")
    end
end
function handlerZoomIn()
    if OverObject == true then
        runMenu = false
        shell.run("/SpaceAdventure/screens/ZoomIn.lua")
    else
        term.setCursorPos(1,19)
        term.setTextColor(16384)
        term.write("THERE IS NOTHING TO ZOOM IN                  ")
    end
end

while runMenu == true do
    newMenu = {
        [1] = {text=" ZOOM IN         ", handler=handlerZoomIn, PosX=2, PosY=17},
        [2] = {text=" SET DESTINATION ", handler=handlerSetDestination, PosX=2, PosY=18}
    }
    printMenu(newMenu,32,32768,2048)
    event, key = os.pullEvent("key")
    onKeyPressedVertical(key,newMenu)
end

Dog

Unfortunately I have no idea what 242 means, but I would suggest placing print statements at various locations throughout your program to help narrow down where the problem is happening.

  • Administrator

3d6

This is a bug. You can usually fix it by restarting your client/emulator, or server if you're in multiplayer.