Log In  

A helpful function to create a scrolling menuitem.

function menu(i,opt,func)
    local indx=0
    menuitem(i,"< "..opt[1].." >",
        function(b)
            if(b==112)then
                func(opt[indx+2])
                return
            end
            indx+=b*4-6
            indx%=#opt
            menuitem(i,"< "..opt[indx+1].." >")
        end
    )
end

Demo:

Cart #dobuidowat-0 | 2021-04-04 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2

P#89955 2021-04-04 04:31

Nitpick: callback doesn't happen if the user changes the option value using L/R and then uses the built-in "continue" menuitem to exit the pause menu rather than pressing O/X on the changed option.

The changed value persists for when the pause menu is subsequently opened again, but this is inconsistent with actual program state which would not have been modified (presumably you'd want to do something more interesting than just print.)

P#89998 2021-04-05 07:21

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 15:34:28 | 0.014s | Q:13