Log In  

I'm trying to setup a new menuitem (i.e. on enter menu) for muting the music. (1) the code below will mute properly but won't display the updated value of the switch i.e. "Music:on" will always display. Putting menuitem() in _draw will fix this...allowing for "Music:off" to display, but not when the callback is true (menu doesnt auto-close).

(2), I'm concerned if I should be calling menuitem() in _draw or not to begin with (if its better cost-wise elsewhere). I am not overly familiar with cartdata and dset/dget but was trying to store a value there and check that in draw instead....not sure if that's the right way, but its not working atm anyways.

How should I ideally set this up such that music:on/off can be seen and toggled within the menu, with the callback returning true (menu not exiting on click)?

cartdata("test")
switch=true --true is music_on
music(0,1000,1) 

function _draw() cls(1)
    if dget(1)==0 then switch=true else switch=false end --not working, was trying to update display for menu
    ?switch
end

function _init()
    menuitem(2,"music"..(switch and ":on" or ":off"),
    function()
        switch= not switch
     if switch then
        music(0,1000,1)
        dset(1,0)
     else 
        music(-1)
        dset(1,1) end
     return true
    end)
end

(3) Does menuitem() being in _init() allow it to persist throughout the gameloop...so that any change to the enter menu calls it?...but it's not updating the value of switch while I'm in the menu itself....only after I close the menu...I don't understand how this works in relation to the gameloop (normally I expect to have to call the function in _draw/_update to run and update itself each frame). Menuitem() is a callback function that runs on its own loop in the background once first called so its ideally called once in init...? Do I have to store switch somewhere menuitem can access (like outside the gameloop cause the gameloop dont run in menu)...?

Here's the same system as above, but storing the value of switch in cartdata, the end result is the exact same as above though...still no dynamic updating while in menu.

cartdata("test")
switch=dget(3)
music(0,1000,1)

function _draw() cls(1)
    switch=dget(3)
    ?dget(3)
    ?switch
end

function _init()
    menuitem(2,"music"..
    (switch==0 and ":on" or ":off"),
    function()
     if switch==1 then
        music(0,1000,1)
        dset(3,0)
     else --switch==0 aka on
        music(-1)
        dset(3,1) end
     return true
    end)
end
P#114087 2022-07-08 23:16 ( Edited 2022-07-08 23:45)

I think the menuitem text only updates when a new menuitem() command is run - essentially, you replace the old one with the new one.

P#114132 2022-07-09 19:13

Maybe, but why is there the option of preventing the menu from closing when you choose a command then? The idea you would toggle multiple options without any indicator u toggled them....doesn't seem right.

P#114142 2022-07-09 21:27

since a recent version you can pass a callback function that returns true to request to keep pause menu open (and it can also react to left/right buttons): https://www.lexaloffle.com/dl/docs/pico-8_manual.html#Custom_Menu_Items

P#114151 2022-07-10 00:03

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 19:26:21 | 0.007s | Q:14