前提・実現したいこと
分割コンパイルをする中で、別のソースファイルに入っている数値を読み取りたい
発生している問題・エラーメッセージ
読み取ったはずの数値が反映されない
(ソースコードを見て欲しいのですが、/sonota.cpp/のint choice()でm_SelectNumの値を読み取ったはずなのに、/main.cpp/のwhile内に行ったら、m_SelectNumの値が何であろうとGame1p_Act()に行ってしまうのです)
該当のソースコード
c++
/* sonota.cpp*/ #include "DxLib.h" #include "Game2p.h" static int m_SelectNum; void startmenu() { //メニュー画面 typedef struct { int x, y; char name[128]; } MenuElement_t; MenuElement_t m_MenuElement[4] = { { 100, 100, "ひとりであそぶ" }, { 100, 150, "ふたりであそぶ" }, { 100, 200, "せってい" }, { 100, 250, "おまけ" }, }; static int m_yazirusiiti; m_SelectNum = 0; while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) { gpUpdateKey(); if (Keyboard_Get(KEY_INPUT_DOWN) == 1) { m_SelectNum = (m_SelectNum + 1) % 4; } if (Keyboard_Get(KEY_INPUT_UP) == 1) { m_SelectNum = (m_SelectNum + 3) % 4; } m_yazirusiiti = ((m_SelectNum + 1) * 50) + 50; if (Keyboard_Get(KEY_INPUT_RETURN) >= 1) { break; } //描画 for (int i = 0; i < 4; i++) { DrawFormatString(m_MenuElement[i].x, m_MenuElement[i].y, GetColor(255, 255, 255), m_MenuElement[i].name); DrawFormatString(80, m_yazirusiiti, GetColor(255, 255, 255), "→"); } } } int choice() { return m_SelectNum; } /*sonota.h*/ #pragma once void startmenu(); int choice(); /*main.cpp*/ #include "DxLib.h" #include "Game2p.h" #include "Game1p.h" #include "sonota.h" int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK); while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) { startmenu(); if (choice() == 0) { Game1p_Act(); } if (choice() == 1) { Game2p_Act(); } if (choice() == 2) { settei(); } if (choice() == 3) { omake(); } } }
回答1件
あなたの回答
tips
プレビュー