Recently, I have been (trying) to learn a bit of this language.
I have seen that many people, in public NVGT code, create menus and make the user return to the menu after completing a certain option or action.
The problem is that I have tried almost everything and I really can't make it work. My program closes after finishing an action, and I have tried a few things to make it return to the menu.
I have tried using the menu's name, maybe calling something called mainmenu like many people do, but it doesn't work.
hope i've explained myself well and thanks
Yeah, I’ve understood (a little). I did what you said, but when I click an option, it doesn’t activate — it just plays the select sound and nothing else.
I’ve written a code example. It’s really badly structured because I used it just for practice, but maybe it can serve as an example.
NVGT Code
#include "speech.nvgt"
#include "menu.nvgt"
string name;
void main() {
show_window("my program");
alert("name undefined", "you must define a name to continue");
wait(5);
name = input_box("name", "what is your name?");
if (name.is_empty()) {
alert("error", "you didn't type a name.");
exit();
}
alert("welcome", "welcome, " + name + "! Nice to meet you.");
wait(200);
menu m;
m.add_item("play", "p");
m.add_item("options", "opt");
m.add_item("change your name", "cn");
m.add_item("exit", "ex");
m.intro_text = "Main menu. Use arrow keys to move and Enter to select.";
m.focus_first_item = true;
m.wrap = true;
m.click_sound = "move.ogg";
m.select_sound = "select.ogg";
m.edge_sound = "edge.ogg";
m.intro();
while (true) {
wait(5);
if (!m.monitor()) {
// Possibly handle menu updates here
}
if (m.selected_item_id == "p")
game();
else if (m.selected_item_id == "opt")
alert("option unavailable", "sorry, this option is not available currently");
else if (m.selected_item_id == "cn") {
name = input_box("new name", "please enter your new name here", name);
if (name.is_empty()) {
alert("invalid name", "you can't leave your name blank");
} else {
alert("success", "your name has been updated to " + name + " correctly");
}
} else if (m.selected_item_id == "ex")
exit();
}
}
void game() {
sound s;
sound tim;
s.load("press.ogg");
tim.load("t.ogg");
timer gt;
timer pt;
int points = 0;
speak("the game has started");
while (true) {
wait(5);
if (key_pressed(KEY_ESCAPE))
return;
if (key_pressed(KEY_SPACE)) {
points += 1;
s.play();
}
if (pt.has_elapsed(1000)) {
tim.play();
pt.restart();
}
if (gt.has_elapsed(10000)) {
gt.restart();
info_box("results", "your results:", "you've earned " + points + " points.\r\nthanks for playing.");
points = 0;
return;
}
}
}
maybe a little weird, but i did that. just to test.
Just a little hint before I'll get to the actual issue: menu.nvgt includes speech.nvgt automatically, so there's no need to include it again. However, this is up to you.
Anyway, I just executed your code and it doesn't seem like you have anything major you could've done wrong. Of course there are a few minor things I recommend to adjust (you can put the if statements for the selected items into the if(m.monitor()) loop), but that's, at the end, up to you.
The only thing I could think of to ask you is what your NVGT version is. I executed it and I think I had the expected behaviour. I clicked on change name and could enter my name just fine. I could click play as well. I'm using this version:
NVGT (NonVisual Gaming Toolkit) version 0.90.0-dev, built on Friday, September 26, 2025 at 10:23:33 PM Coordinated Universal Time for Windows NT AMD64
Are you using a version prior to that? If so, would you see it worthy to update and see wether the issue has been patched in a future commit? I believe it either has something to do with the form (which menu uses as backend) or menu include. I can't recall of any critical bugfix from the top of my head right now, but I this is pretty much the only thing your code depends on.
NVGT (NonVisual Gaming Toolkit) version 0.89.1-beta, built on Thursday, October 10, 2024 at 03:07:01 AM Coordinated Universal Time for Windows NT AMD64
i’ve improbed the code, i’m going to see if I can add the options in m.monitor(). the version of nvgt i have is the latest in the site