2020-01-13 04:58:45 (edited by alisson 2020-01-14 20:26:41)

Edit:
If someone wants to check the full code, the repository is this:
https://github.com/CartridgeSoft/game-e … testBranch
Hi. So Im trying to create a dialog class to send story mesages, object descriptions etc for my game. The dialog class works... more or less, but I can't separate the dialog thing of the player actions ive tried several things, googled a bit but sighted people usually  uses sprite fonts to draw text. Here is my code, if Anyone can help i will be very grateful.
I will put the dialog class and the object class wich is the clas im trying to make work
this is the actually dialog clas. For some reason when y try to use the clas, the game crashes.
using DavyKager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Game3
{
    public  class DialogBox
    {
public  Map Map
        {
            get { return map; }
        }
         Map map;
        public ISoundEngine engine = new ISoundEngine();
        public bool IsInDialog;
        KeyboardState keystate = Keyboard.GetState();

        public DialogBox(Map map)
        {
            this.map = map;
            Tolk.Load();
        }

        public void dlg(string message)
        {
            Tolk.Speak(message, true);
            engine.Play2D("sounds/UI/menuback.mp3");
            while (true)
            {
                if (Input.WasKeyPressed(Keys.E))
                {
                    Tolk.Speak(message, true);
                }
                else if (Input.WasKeyPressed(Keys.Enter))
                {
                    engine.Play2D("sounds/UI/menuconfirm.mp3");
                break;
                }
            }
        }


    }
}

now the object class:
    public class Object
    {
public Map Map
        {
            get { return map; }
        }
            Map map;
        public int x, y, z;
        public string name;
        public bool IsInteractable;
        public Object(Map map, int ox, int oy, int oz, string oname, bool interactable=false)
        {
            this.map = map;
            this.x = ox;
            this.y = oy;
            this.z = oz;
            this.name = oname;
            this.IsInteractable = interactable;
            map.engine.Play3D("sounds/rooms/" + oname + ".mp3", ox, oy, oz, true);
        }

        public void Update(GameTime gameTime)
        {
        }
       
        public void interact()
        {
            map.dialog.dlg("this is a"+name);
        }

    }
}

Sorry for my english

2020-01-13 05:46:18

hi,
your problem is that you should put break; at the second if statement, not outside it in the main loop

2020-01-13 06:09:57

yea. ive made thath before, but the program whas crashing overall, because of thath ive put the break outside the if to se if it works

Sorry for my english

2020-01-13 07:36:14

The error message would be important here.

2020-01-13 15:33:29

theres no message, the game just crashes

Sorry for my english

2020-01-13 15:53:24

Isn't an exception raised? What does Visual Studio object browser says? Is your coordinate system compatible with the one used in IRR? And congrats about choosing C# lol.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2020-01-13 17:44:25

@nuno Yea c# is greath. and nop, theres no esception, nothing. the only thing is happening is the program crashing. well not crash at all. I have to cancel the execution because wen I interact with the object, the dlg function starts and then the game crashes and I have to cancel the run

Sorry for my english

2020-01-13 18:15:17

I believe what he means is the game goes unresponsive when he interracts with an object. You know, the "Windows is checking for a solution for this problem" message? Correct me if I'm wrong, though.

2020-01-13 19:08:19

Then use the debuugger to step over the code.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2020-01-13 20:16:34 (edited by Ethin 2020-01-13 20:17:28)

Usually C# programs don't crash like that unless there's something very, very wrong with your code or your .NET runtime. Try adding this in your main() function (don't keep this around, its far too broad and you should narrow the scope to only those parts that do throw exceptions):

try {
// main function code here
} catch (Exception ex) {
MessageBox.Show($"{e}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
Environment.Exit(1);
}

That should give you exception information that you can just control+a, control+c and paste into here that's far clearner than a complete applicationtermination.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2020-01-13 21:47:50

Have you tried running it with the vs debugger to see what exception is raised?
The code looks good enough, but I am not familiar with the libraries you use, so I can't be shure. Are you using xna, or am I mistaken? Isn't it deprecated?
Anyway, I don't know enough about your code to give you more advice than I have already. For example, how does the map class look like, what about the engine class, what if the exception originates from there?

2020-01-13 21:58:44

@bgt lover nop, is monogame. the devs have left the old namespaces for some reason. but its monogame and this framework its updating every day. If you want, I can upload all the code in github. Tried to use the debugger but says nothing. and I canot use the winform because well, its a monogame template, not a win forms big_smile

Sorry for my english

2020-01-13 22:05:16

MonoGame uses the XNA namespaces because MonoGame is an open-source implementation of XNA.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2020-01-13 23:15:18

@13: I didn't ever use mono game. I always used winforms with entities whos various methods I call at OnKeyXxx in the current form.
For example, if we have this code fragment:
namespace model
{
public class Player
{
...
public void Move(PlayerDir pd)
{
//check for movement value, left or right
State=PlayerState.Walking;
}
...
}
}
...
using System.Windows.Forms;
using System.Keys;
...
Player p= new Player();
Then, in the overwrited OnKeyPressed method, one can do the following:
if(Key==Left) P.Move(Playerdir.Left);
Do you think this is too much code for nothing? Is this perhaps a sighn that I should learn monogame as well?
@12: Make shure you build the project with the debug configuration in place and you have the debugger running on the project by clicking debug>run debugger.
Check this and please post here, I am rather curious on what is happening there.

2020-01-14 01:43:41

@14, that's a bit overkill, and as I've said (many) times before, try not to use windows forms wen making games. Use a 3D GUI library explicitly designed for the engine your working with. Standard GUIs won't blend well with the 3D background interface, for one, nor do they integrate well, so you can't, for example, make them (say) a part of a computer in-game. The central "key manager" method is definitely one way to go about things, however as you ad more functionality your key manager will have to become a state machine that is capable of handling all possible inputs from the user. The more you add to the game, the longer this function will get, and therefore the harder it will be to maintain as a result. If we break a game down to its core components, then it becomes a state machine:

  1. User loads game. Game enters "verification" state.

  2. Game checks registration information, say, with Steam. If registration succeeds, go to "loading" state; otherwise, go to "verification error" state.

  3. If in error state, display error message and wait for input from the user. Transition to "terminate" state.

  4. Otherwise, if in loading state, load all required game assets that you require (excluding assets that must be streamed or memory mapped).

  5. Continue...[

And so on. Generally what I do when designing games is I use a game loop, which is what MonoGame does. The game loop, for example, might manage the state of the game. My game loop acts as a dispatcher: if game is in "x" state, call "x" state's callback function. "x"'s function should complete as fast as possible as to not stall the game loop. Repeat until state changes. (Alternatively, you can do this asynchronously or in parallel, but that involves a bit more work, which means your loop must store the thread that's running and check its status. I'll let you figure that out on your own. Generally, make your game loop as fast as possible. Use all the optimization tricks in the book, because that loop will be running every 16 MS (or less), which doesn't give you a lot of time to do your work and get out. Remember, however, the Pareto principle: for many events, roughly 80% of the effects come from 20% of the causes. Put in a relative way, your code is only running 20 percent of the time; the other 80 percent of the time your code is patiently waiting for operations to complete (e.g. user input, I/O, ...). As such, do not needlessly optimize. Be careful; there is no point in optimizing code if it will only be ran 5-10 percent of the time. You can't make a network connection go any fasterby optimizing the code that sends the data over the network; hense, don't even optimize it because there's nothing you cando about it. Your game loop is the exception to this rule though -- make that as fast as possible because you have a very small time window to run in, and if you exceed that, bad things happen.)

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2020-01-14 04:14:38

Hi. Checked the debugg, but only says that.
pd. Ignore the mising sounds thing, I deleted some sounds, but I thing that is not the problem.
o, an other thing. If someone wants to check the full code the updated branch is this.
https://github.com/CartridgeSoft/game-e … testBranch
'Game3.exe' (CLR v4.0.30319: DefaultDomain): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: DefaultDomain): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\Game3.exe' cargado. Símbolos cargados.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\MonoGame.Framework.dll' cargado. El módulo se compiló sin símbolos.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_es_b77a5c561934e089\mscorlib.resources.dll' cargado. El módulo se compiló sin símbolos.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\SharpDX.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\SharpDX.DXGI.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\SharpDX.Direct3D11.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\TolkDotNet.dll' cargado. El módulo se compiló sin símbolos.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\irrKlang.NET4.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\Users\alisson\games etc\vs\Game3\bin\Windows\x86\Debug\SharpDX.XInput.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'Game3.exe' (CLR v4.0.30319: Game3.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll' cargado.
irrKlang sound library version 1.6.0
Loaded plugin: ikpflac.dll
Loaded plugin: ikpmp3.dll
Using DirectSound8 driver
irrKlang sound library version 1.6.0
Loaded plugin: ikpflac.dll
Loaded plugin: ikpmp3.dll
Using DirectSound8 driver
irrKlang sound library version 1.6.0
Loaded plugin: ikpflac.dll
Loaded plugin: ikpmp3.dll
Using DirectSound8 driver
irrKlang sound library version 1.6.0
Loaded plugin: ikpflac.dll
Loaded plugin: ikpmp3.dll
Using DirectSound8 driver
irrKlang sound library version 1.6.0
Loaded plugin: ikpflac.dll
Loaded plugin: ikpmp3.dll
Using DirectSound8 driver
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move4.ogg
Could not open sound file: sounds/Movement/stepback1.wav
Could not open sound file: sounds/Movement/move6.ogg
Could not open sound file: sounds/Movement/move5.ogg
Could not open sound file: sounds/Movement/move5.ogg
Could not open sound file: sounds/Movement/move7.ogg
Could not open sound file: sounds/Movement/move9.ogg
Could not open sound file: sounds/Movement/move8.ogg
Could not open sound file: sounds/Movement/move11.ogg
Could not open sound file: sounds/Movement/move9.ogg
Could not open sound file: sounds/Movement/move6.ogg
Could not open sound file: sounds/Movement/move4.ogg
Could not open sound file: sounds/Movement/move2.ogg
Could not open sound file: sounds/Movement/move7.ogg
Could not open sound file: sounds/Movement/move7.ogg
Could not open sound file: sounds/Movement/move6.ogg
Could not open sound file: sounds/Movement/stepback4.wav
Could not open sound file: sounds/Movement/move8.ogg
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/Movement/move6.ogg
Could not open sound file: sounds/Movement/move9.ogg
Could not open sound file: sounds/Movement/move2.ogg
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/Movement/move8.ogg
Could not open sound file: sounds/Movement/move6.ogg
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/Movement/move1.ogg
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/Movement/move9.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move5.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move9.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move3.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move8.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move4.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move5.ogg
Could not open sound file: sounds/Movement/stepback3.wav
Could not open sound file: sounds/Movement/move5.ogg
Could not open sound file: sounds/Movement/stepback2.wav
Could not open sound file: sounds/Movement/stepback1.wav
Could not open sound file: sounds/Movement/stepback4.wav
Could not open sound file: sounds/Movement/move6.ogg
Could not open sound file: sounds/Movement/move6.ogg
Could not open sound file: sounds/Movement/move9.ogg
Could not open sound file: sounds/Movement/move3.ogg
Could not open sound file: sounds/Movement/move5.ogg
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/Movement/move3.ogg
Could not open sound file: sounds/Movement/move8.ogg
Could not open sound file: sounds/Movement/stepback1.wav
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move10.ogg
Could not open sound file: sounds/walls/doorwall.wav
Could not open sound file: sounds/Movement/move9.ogg
the program '[17928] Game3.exe' whas terminated whit code -1 (0xffffffff).

Sorry for my english

2020-01-14 19:54:04

@15: I will just have to learn more about game design, I guess. It's not as if there are not dozens of books just about that thing on libgen alone, in fact, there are enough of them to crash me flat under their weight lol.
Btw, thanks for the advice, one question remains, though. If I should not use winforms for this kind of thing, how should I create audio/video menus where the sighted can use their mouse on the menu to select and activate menuitems and we can use the keyboard and sapy as usual? In my small prototypes, I used winforms buttons to make the menuitems. But those buttons were anything but ordinary because they are hooked up to an OnFocus event that sends text of the Sender to sapi and an OnClick event which cause the option to fire.
@16: I checked your code on my phone for I am not in an environment where I can bring my development laptop so I can test it properly, but what I see here is that you call Toke.Load at least twice and this is not good because the unmanaged dll may raise an exception of its own, like the c++ using the windows structured exception handling(seh) mechanism and .net might not see it.
The conclusion to all this is, delete every ocurrence of the Toke.Load from your codebase, except the one in the entrypoint of your game and see what happens.
When I get back to my computer, I will test the app  more thoroughly and post here with my findings, but until then, that is what I could find so far, so you might as well try that if you don't have any other option.

2020-01-14 20:20:26

@17. O, let's see what happen. maibe I have to do some global speech class big_smile

Sorry for my english

2020-01-14 20:36:32

Well, deleted all instances of tolk and used only the instance in the main class. But the problem still here. I think the problem is related to the gameloop and the while loop, wich is an other loop outside the game loop. I think the monogame class keyboard only react when the main loop is active, so when the dialog loop triggers the main loop stops. If the problem is this, what kind of solution I can do to resolve? Use an other keyboard class when the dialog class triggers?

Sorry for my english

2020-01-14 22:54:24

@17, that's what 3D GUI libraries are for. Check out BS::Framework and its user manual on GUI elements so you get an idea of what I'm talking about. You could always role your own, too, though I wouldn't recommend it if you don't know what your doing (graphics is hard, trust me, 've done it).

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2020-01-15 03:36:12

Hi. Just to say... Finally solved the problem. A friend helpedme and well. We found a metod wich makes the dialog work fine. Anyway, thanks to all for the help

Sorry for my english

2020-01-15 04:04:50

@21: what do you think was the problem? do you plan to post the method here for everyone to be able to compare them and see what changed?
@20: 3d GUIs? Who would need a third dimension to their buttons, do they want it to appear to float or am I missing something?
Anyway, are, for example, 3d buttons able to be focused with the keyboard Like normal buttons, even though inaccessible without adjustments with sapi like when using qt?

2020-01-15 05:05:28

@22, yep, you can do that. But a 3D GUI is also nice for making interactive consoles and other machine-based systems that actually feel like they're inside the actual game rather than being some foreign entity that feels like it doesn't belong (re: windows forms/WPF). BS::Framework's GUI system is one which I especially like because yes, you can make the GUI pretty much fully accessible, minus a few hiccups here and there, like selection lists requiring you to press enter before the selection is made.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2020-01-16 01:33:33

@22 yea for shure, We have implemented a interface wich uses the gameloop to make the dialog run instead of the while loop. that was the problem all the time. The updated code is on the test branch on the repo, if you want to check the changes you can of course

Sorry for my english