Guys, do any of you know how to make the onboard menu plugin command work properly in this code ?
I want the text, "confirmed" to only appear WHEN you select the menu item. From here, don't press [A] as that will only exit the program.
Instead press [ENTER] and select, "test." You will see that it does not run the function associated with it.
-- broken menu -- you can test this in splore -- or online function main() menuitem(1,"test",doit()) getkey("check menu now") end function doit() print"confirmed !" end -- simple get and wait key [a] function getkey(t) if t!=null then print"" print(t.." - press [a]") end repeat flip() until btn(4)==false repeat flip() until btn(4) end--getkey main() -- nifty put at top
The system menu runs outside of the normal code, and I assume using flip() also suspends execution. (from the manual: "Flip the back buffer to screen and wait for next frame" emphasis mine)
I put in an empty _update() and that gave it time/space to execute the function call from the menu. (after an extra press to get out of the flip() loop.)
function main() menuitem(1,"test",doit) getkey("check menu now") end function doit() print"confirmed !" end -- simple get and wait key [a] function getkey(t) if t!=null then print"" print(t.." - press [a]") end repeat flip() until btn(4)==false repeat flip() until btn(4) end--getkey main() -- nifty put at top function _update() end
Hi Tyroney. You are very close. It works only AFTER I press (A). I want to have it work BEFORE or AFTER you press (A).
Basically, I'd like the menu to work no matter what function it is in, what loop it is in, or anything else that might be happening. A true interrupt. If this is impossible, I understand and can develop my own menu system around this.
Your code is stuck in a loop, leaving no time for the menu callback.
Here's some code that demonstrates when the callback fires. (in this case in _update after its first if statement, and before the second if statement.)
function pause(a) print(a) repeat until btn(4) end u=0 flag=true menuitem(1,"test",function() print("done") flag2=true end) cls() pause("a") pause("b") pause("c") function _update() u+=1 if (flag) print("update "..u) flag=false if (flag2) print("ding") flag2=false end
edit: I don't know exactly how the callback gets inserted into execution, but no matter how many pause()s I run, it still doesn't happen until _update() gets run.
Seems to me it's a fault (or shortcoming) of PICO itself. Interrupts are pretty amazing things to write in code, and sometimes the language just won't accept it, or it can't be done.
Let me try your latest code. ...
Yeah, it's still got the same problem. When I run it from SPLORE, and the first thing I do is hit [ESC] and try out the TEST menu, it doesn't work.
Beginning to believe the menu can only be active when not inside another loop or function. :(
Would be a real advantage though if it could. (Penning my own notes ... need to make sure something like this will work in my own game maker).
Reflecting. It's really not that difficult, and if multitasking is the problem, just FREEZE whatever code was running, then give priority to the code from the menu, then return back.
[Please log in to post a comment]