0

I've been struggling to get any input from Ncurses working. The keyboard input works fine if I use stdscr rather than my custom window. However, if I use the stdscr, I get absolutely no output to the terminal.

Here is my compile argument:

gcc -o dungeon dungeon.c -lncursesw

Code in question:

  setlocale(LC_ALL, "");
  int key;
  window = newwin(XLEN, YLEN, 0, 0);
  keypad(window, TRUE);
  initscr();
  clear();
  noecho();
  cbreak();
  refresh();
  while (player.alive && !playerWin(monsters)){
    key = wgetch(window);
    if (key == 'y' || key == '7'){
      player.alive = 0;
    }
    render(monsters);
    refresh();
    for(i = 0; i < numMonsters; i++){
      moveMonsters(&monsters[i]);
    }
    monsterPlayerCollision(monsters);
    int dead = monsterMonsterCollision(monsters);
    if(dead){
      monsters[dead].alive = 0;
    }
    dijkstraNon();
    dijkstraTunnel();
    clear();
    usleep(3);
    wrefresh(window);
  }

Please let me know if there's anything I can do to clarify.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
briang0
  • 1
  • 1
  • Not a minimum compilable example. not enough context to help. If I were to guess, move the last `wrefresh(window)` before `usleep(3)` -- and/or replace `refresh()` after `moveMonsters` with `wrefresh(window)` – JohnH Mar 06 '18 at 20:56
  • Also, make sure output uses `wprintw()`, `mvwprintw()`, `waddch()` etc, with the window passed to the correct `w` prefix routine. – JohnH Mar 06 '18 at 21:04
  • Something like that. The given example is too incomplete to do more than point out the conflict between `stdscr` (clear/refresh) and the other calls. Some of the missing code is also using curses calls. – Thomas Dickey Mar 06 '18 at 21:10
  • "However, if I use the stdscr, I get absolutely no output to the terminal." -- Then, take out the `noecho()`? Otherwise, yeah, not enough info here. – William McBrine Mar 07 '18 at 12:54
  • Thanks for the help. I'll try to make my code clearer next time. I was able to fix my problem by getting rid of clear() and replacing my printing from wprintw() to mvwaddchr() and mvwaddstr(). – briang0 Mar 08 '18 at 04:48

0 Answers0