I'm trying to make a menu so it will be on right side of the screen and the game will stay on left side (game screen and menu share the same screen)
this is a whole file called menu.lua and it is then loaded from main.lua by require(menu)
as a swich between game and menu I chose TAB
when menu is active you can use arrows up/down to move (current position will be highlighted)
then you can use arrows left/right to change active (highlighted) position's values
i take the original values like this (4th position in each line of options table):
val = bspLvl
val = rMin
...
and here I have a problem that i cannot handle
how to update original value of each variable (4th position in each line of options table) according to its actual value from "options[lineNo].val" (changed when left/right arrow is pressed)?
for example :
options[1].val has a value of bspLvl
usin right arrow I will increase its value 1 step
now how to transfer this options[1].val back to bspLvl
probably there is another way of doing such thigs but it is unknown to me - that is all I could think of
Code: Select all
menu = {}
local options = {
{ title = "bsp", minV = 0, maxV = 30, val = bspLvl, x = 50*fs, y = 3*fs+3 },
{ title = "room min", minV = 1, maxV = rMax, val = rMin, x = 50*fs, y = 4*fs+4 },
{ title = "room max", minV = rMin, maxV = 30, val = rMax, x = 50*fs, y = 5*fs+5 },
{ title = "wall distance",minV = 0, maxV = 5, val = wShift, x = 50*fs, y = 6*fs+6 },
{ title = "monsters", minV = 0, maxV = 50, val = monNo, x = 50*fs, y = 7*fs+7 }
}
local lineNo = 1
function menu.keyPressed(key)
if key == "down" and lineNo < #options then
lineNo = lineNo + 1
end
if key == "up" and lineNo > 1 then
lineNo = lineNo - 1
end
if key == "left" and options[lineNo].val > options[lineNo].minV then
options[lineNo].val = options[lineNo].val - 1
end
if key == "right" and options[lineNo].val < options[lineNo].maxV then
options[lineNo].val = options[lineNo].val + 1
end
end
function menu.draw()
for i,v in ipairs(options) do
if i == lineNo then
love.graphics.setColor(255, 0, 0, 255)
else
love.graphics.setColor(200, 200, 200, 255)
end
love.graphics.print(v.title.." "..v.minV.."-"..v.maxV..": "..v.val, v.x, v.y)
end
end