Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem is not understanding how enumerative types work. Specifically, this line:</p> <pre><code>game1.GameStates = IntroState; </code></pre> <p>First, let's discuss a little of what an enum actually is. It's a structure that simply assigns names to integer values, and can then refer to each value by name, and thus make code more readable (as it's far easier to understand <code>direction = Dir.Up</code> than <code>direction = 1</code>).</p> <p>Notice how I use those two example statements, though. In the code, you treat the enum as a <em>type</em> not as a <em>variable</em>, and this is the problem you're encountering. In fact, your problem is twofold. The first issue id that you're trying to assign a value to a structure, which is similar to writing <code>int = 4</code> - i.e. it doesn't make sense. Your second issue is that enums are not global, so <code>IntroState</code> has no meaning outside <code>game1</code>.</p> <p>Interestingly enough, you've set up the system correctly, as you have the <code>currentGameState</code> variable, which is what you actually intend to change. However, it is a <code>private</code> variable, disallowing access to it from outside the game1 class. You can either make the variable <code>public</code>, or create a <code>property</code> to access it. The latter is good practice, as it allows you to control how the variable is set. To create this, you can use something like this:</p> <pre><code>public GameStates CurrentState { get { return currentGameState; } set { currentGameState = value; } } </code></pre> <p>Once you have this in your game1 class, you can set the game state like so:</p> <pre><code>game1.CurrentState = Game1.GameStates.IntroState; </code></pre> <p>Notice how this code tells the program where to look for what you want. <code>IntroState</code> is part of a structure (<code>GameStates</code>) within game1, and so needs to be accessed explicitly.</p> <p>Hopefully, this has helped you to understand how enumerative types work, and why the code you wrote doesn't make sense, and thus why it breaks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload