This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheOddByte's profile picture

[QUESTION] Why Is this Not Working Correctly?

Started by TheOddByte, 10 February 2013 - 01:19 AM
TheOddByte #1
Posted 10 February 2013 - 02:19 AM
As I was updating my Game Boxer Tournament I thought I would add the settings Menu now..
But It's not working as it should since if i press Enter it does'nt change the settings displayed!
And I wonder if someone could help me explain what's wrong.

CODE:
Spoiler


---------------------------------------------------------------------------------------------------
--SETTINGS
---------------------------------------------------------------------------------------------------
hintLevel = "Low"
subOnOff = "Off"
xyPosOnOff = "On"
colorsOnOff = "Off"
detailLevel = "Low"
connection = "None"
shName = "On"
shScore = "On"
shHUD = "On"


--[[
GAME:{
Hint Level (hinLevel)
Subititles (subOnOff)
}

GRAPHICS:{
ShowXYpos = Allows you to choose if you want to see X/Y pos. (xyPosOnOff)
Colors = Allow you to turn on and off the colors (colorsOnOff)
Detail Level = Low,Medium, Normal,High,Ultra High (detailLevel)
}

CONTROLS:{
Default Controls
Set Controls
}

NETWORK:{
Connection = Global, Private, Lan (connection)
Show/Hide Name (shName)
}

HUD: {
Show/Hide Score (shScore)
Show Hide HUD = Shows Or Hides Everything (shHUD)
}

ENTER CHEAT = Here you can enter a cheatCode to enable a cheat

]]--

function drawSetCursor()
if posMode == show then
drawAt(3,sMenuStat,">")

elseif posMode == hide then
drawAt(3,sMenuStat,"<")

elseif posMode == setOption then
drawAt(3,sMenuStat,"*")
end
 end

 setOpt0 = {
 "GAME",
 "GRAPHICS",
 "CONTROLS",
 "NETWORK",
 "HUD",
 "ENTER CHEAT",
 }

 setOpt1 = {
 "GAME",
 "----------",
 "Hint Level:"..hintLevel.." ",
 "Subititles:"..subOnOff.." ",
 "----------",
 "GRAPHICS",
 "CONTROLS",
 "NETWORK",
 "HUD",
 "ENTER CHEAT",
 }

  setOpt2 = {
 "GAME",
 "GRAPHICS",
 "----------",
 "Show X/Y Pos:"..xyPosOnOff.." ",
 "Colors:"..colorsOnOff.." ",
 "Detail Level:"..detailLevel.." ",
 "----------",
 "CONTROLS",
 "NETWORK",
 "HUD",
 "ENTER CHEAT",
 }


  setOpt3 = {
 "GAME",
 "GRAPHICS",
 "CONTROLS",
 "----------",
 "Default Controls",
 "Set Controls",
 "----------",
 "NETWORK",
 "HUD",
 "ENTER CHEAT",
 }

   setOpt4 = {
 "GAME",
 "GRAPHICS",
 "CONTROLS",
 "NETWORK",
 "----------",
 "Connection:"..connection.." ",
 "Show/Hide Name:"..shName.." ",
 "----------",
 "HUD",
 "ENTER CHEAT",
 }

  setOpt5 = {
 "GAME",
 "GRAPHICS",
 "CONTROLS",
 "NETWORK",
 "HUD",
 "----------",
 "Show/Hide Score"..shScore.." ",
 "Show/Hide HUD"..shHUD.." ",
 "----------",
 "ENTER CHEAT",
 }

 function checkOptions()

 if setOpt == Nothing then
 minStat = 4
 maxStat = 9

 for i = 1, #setOpt0 do
  drawAt(4,i + 3,setOpt0[i])
  end

  elseif setOpt == Game then
  minStat = 5
  maxStat = 7
 for i = 1, #setOpt1 do
  drawAt(4,i + 3,setOpt1[i])
  end

  elseif setOpt == Graphics then
    minStat = 6
  maxStat = 9
 for i = 1, #setOpt2 do
  drawAt(4,i + 3,setOpt2[i])
  end

  elseif setOpt == Controls then
    minStat = 7
  maxStat = 9
 for i = 1, #setOpt3 do
  drawAt(4,i + 3,setOpt3[i])
  end

  elseif setOpt == Network then
    minStat = 8
  maxStat = 10
 for i = 1, #setOpt4 do
  drawAt(4,i + 3,setOpt4[i])
  end

  elseif setOpt == Hud then
    minStat = 9
  maxStat = 11
 for i = 1, #setOpt5 do
  drawAt(4,i + 3,setOpt5[i])
  end
   end
    end


function drawSetMenuExtra()
drawAt(1,1,"+-------------------------------------------------+")
drawAt(1,2,"|               ---SETTINGS---                        |")
drawAt(1,3,"+-------------------------------------------------+")
drawAt(1,18,"+-------------------------------------------------+")
end

function drawSettingsMenuArt()
setMenu = {
"+-------------------------------------------------+",
"|               ---SETTINGS---                        |",
"+-------------------------------------------------+",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"|                                                               |",
"+-------------------------------------------------+",
}

for i = 1, #setMenu do
   drawAt(1,i,setMenu[i])
   checkOptions()
   drawSetMenuExtra()
    end
end




function setMenuEvents()
if setOpt ~= Nothing and
sMenuStat ~= minStat then
posMode = setOption

elseif setOpt ~= Nothing and
sMenuStat == minStat then
posMode = hide

elseif setOpt == Nothing then
posMode = show
end

drawSetCursor()
event, p1 = os.pullEvent()
if event == "key" and

p1 == 200 then
sMenuStat = sMenuStat - 1
if sMenuStat < minStat then
sMenuStat = minStat
end

elseif p1 == 208 then
sMenuStat = sMenuStat + 1
if sMenuStat > maxStat then
sMenuStat = maxStat
end

elseif p1 == 28 then

if sMenuStat == 4 then
if setOpt == Nothing then
posMode = hide
setOpt = Game
end


elseif sMenuStat == 5 then
if setOpt == Nothing then
posMode = hide
setOpt = Graphics
end

elseif sMenuStat == 6 then
if setOpt == Nothing then
posMode = hide
setOpt = Controls
end


elseif sMenuStat == 7 then
if setOpt == Nothing then
posMode = hide
setOpt = Network
end


elseif sMenuStat == 8 then
if setOpt == Nothing then
posMode = hide
setOpt = Hud
end


elseif sMenuStat == 9 then
print("Not Available YET!")
return
end


elseif p1 == 14 then
return menu() -- This Is Already Declared In The Game, But won't work if you test too Copy/Paste This Here
end
   end




function settingsMenu()
setOpt = Nothing
posMode = show
minStat = 4
maxStat = 9
sMenuStat = 4
settingsNum = 0

while true do

cleanScreen()
drawSettingsMenuArt()
setMenuEvents()
checkOptions()
                 end
                       end 
TheOddByte #2
Posted 10 February 2013 - 02:38 AM
And for you to know what i'm meaning, It's this

--If we say that I press enter when the cursor is on game I want it to print


GAME
----------
Hint Level:Low
Subititles:On
----------
GRAPHICS
CONTROLS
NETWORK
HUD
ENTER CHEAT

theoriginalbit #3
Posted 10 February 2013 - 02:54 AM
The problem is that your assembling the strings that print when the table is created… this isn't updated each time it is called. so you need to update the appropriate entries in the table yourself. chances are they are changing, just your not seeing it.
TheOddByte #4
Posted 10 February 2013 - 03:16 AM
Oh thx but I fixed this now by changing like nothing to "nothing" since it seemed to work better as strings..
Soon I'll release the new version of Boxer Tournament :D/>