Press "Enter" to skip to content

Lesson 17.1 – Running the game on another computer

Lesson Objectives

At the end of this lesson, you will know…

  • How to move your game to another computer, and run it without Visual Studio

 

Right now, you have to start Visual Studio and load your solution before you can play the game. But if you want to share your program with someone else, you don’t want to make them install Visual Studio.

So, now we’ll build a version that you can copy to a CD/DVD/thumb drive/etc. and share with your friends and family.

Visual Studio has a nice installation package creation project, but it gets a little complex. So, we’re going to use the “quick and dirty” method, for now.

 

Building the program for another computer

The first thing you want to do is build the program in “Release” mode.

So far, we’ve used “Debug” mode, which can be useful while writing the program. Debug mode lets you take a look into the program while it’s running, in case you have a problem and aren’t sure where it’s happening.

But when you’re done writing your program, and are ready to “release it”, you want to use Release mode.

Then, you just need to copy the program’s files to a computer that has the correct .Net Framework installed, and you can run it there.

 


Link to video on YouTube

 

Step 1: Start Visual Studio Express 2013 for Desktop, and open the solution.

 

Step 2: In the menu, to the right of the “Start”, there is a dropdown that probably says “Debug” right now (that’s the default value). Change it to “Release”.

 

Step 3: From the menu, click on “Build”, then “Build Solution”. This will create the executable files – the ones needed to run your program.

Check the “Output” box, in the bottom middle of Visual Studio. It will tell you when it’s done building the program, along with where it was built.

 

Step 4: Open up Windows Explorer and get to the folder where the executable file was created.

You’ll see the file there, along with some other ones. You don’t need all of them, but it won’t hurt to have the extra files. So, we’ll copy all of them to our new location.

In this case, I just created a new folder named “Games”, with a sub-folder under it named “SuperAdventure”. You can name your folder whatever you want.

Then, paste the files into this folder.

 

Step 5: To make this easier to run, create a desktop shortcut for the SuperAdventure.exe file. That’s the executable, the file to run the game.

Now, you can double-click on the shortcut on the desktop and start playing your game.

 

Summary

Now you can copy your program to another computer (assuming they’ve been running Windows Update, and have the same version of the .Net Framework you used when you made the program.

If you learn how to create a Windows Installer project, you can end up with a single program someone can use to install your program on their computer. If their computer is missing anything, or doesn’t have the correct version of the .Net Framework, the installer program will fix that for them.

There are also some more complex installations for different types of projects – ones that use a database, or are run as a website.

But, now you know how to copy this game over to your friend or family member’s computer, so they can see the program you created and play the game.

 

Source code for this lesson

No source code for this lesson

 

Next lesson: Lesson 18.1 – Future enhancements for the game

Previous lesson: Lesson 16.3 – Functions to use weapons and potions

All lessons: Learn C# by Building a Simple RPG Index

52 Comments

  1. Scott
    Scott October 21, 2015

    Hey Scott! I changed the Solution Configurations to “Release” and when I build the program it came up with an error: “SuperAdventure” is a ‘namespace’ but is used like a ‘type’ in the program.cs Ive checked the code on SuperAdventure and it is spelled correctly I also re typed it in both codes. Not sure what happened :/

    • Scott Lilly
      Scott Lilly October 21, 2015

      Does it work if you build the program in “Debug” mode, or do you still see the same error?

      I’ve seen this problem come up for a couple other people, and it’s usually a little difficult to track down to the original source. But, here are the places I’d start:
      1. Did you rename any of the projects (SuperAdventure or Engine) after you created them? If so, you’ll probably need to manually correct the namespaces in the projects. You can see how to do that here: https://scottlilly.com/learn-c-by-building-a-simple-rpg-index/lesson-05-1-creating-objects-from-classes/#comment-1639
      2. Check the SuperAdventure.cs class and make sure it says “public partial class SuperAdventure : Form”. Then check SuperAdventure.Designer.cs and make sure it starts with this:
      namespace SuperAdventure
      {
      partial class SuperAdventure

      If those look good, is there a place you can upload a copy of your solution? DropBox, Github, etc. Then I could check out some other things that are a little difficult to describe through us talking back and forth in the comments here.

      • Scott
        Scott October 22, 2015

        Nope haven’t Renamed anything and everything else looks fine. I don’t have a way to upload it but I can make an account which site do you prefer?

        • Scott Lilly
          Scott Lilly October 22, 2015

          DropBox is probably the easiest. Please upload the complete solution (including all the sub-directories, and files in them) and reply here with the share link for the DropBox directory. I might not be able to look at it until Friday night or Saturday.

  2. Scott
    Scott October 23, 2015

    Alright sorry for all the comments since it never showed that they passed the moderation so I kept putting them in :/

    • Scott Lilly
      Scott Lilly October 23, 2015

      I got the comments, but am holding them in moderation (since they’re not really relevant to anyone else, until we figure out the problem). I sent you a couple e-mails that the Engine project was missing from the zip file. Can you check on that and try re-uploading it?

    • Scott Lilly
      Scott Lilly October 25, 2015

      I’m going to check something out on Monday (when I’ll be at my computer with Visual Studio 2013). I think the problem might be how the solution was setup, which might also be why you had problems sending both projects together.

    • Scott Lilly
      Scott Lilly October 26, 2015

      I found the problem. Your UI project’s name is different from “SuperAdventure”. If you right-click on your UI project, and select “Properties”, and click on “Application”, you’ll see your project’s namespace. Right now, it matches the project name “WFA game practice”. But, when you copy-paste the code from the lessons, they are all defined with “namespace SuperAdventure”.

      The easiest way to fix this is to change the “Default namespace” value (on your UI project’s properties) to “SuperAdventure”. You could also change all the classes in the UI project to have the namespace match the namespace in your properties. But then you’d need to remember to do that every time you copy-paste something into the project.

      Please let me know if that doesn’t fix the problem.

      • Christopher K
        Christopher K April 26, 2018

        So I tries it that way and I think it is right but it is not working. I am new to all of this so I might have not done it right. I had the same error pop up and have tried renaming everything I could find but had to revert back and have the same problem. I went to the application spot and changed it from “Simple_RPG” to “SuperAdventure”.

        • Scott Lilly
          Scott Lilly April 27, 2018

          Can you upload your solution (including the directories under it, and all the files in those directories) to GitHub or Dropbox, so I can look at it?

          • Christopher K
            Christopher K April 27, 2018

            How do I send it to you through Dropbox?(Email/Name)

          • Scott Lilly
            Scott Lilly April 28, 2018

            The best way is probably to click on “Copy link”, which will show you a URL you can put in your reply here.

          • Christopher K
            Christopher K April 28, 2018

            LINK REMOVED FOR PRIVACY

          • Scott Lilly
            Scott Lilly April 29, 2018

            There are two things to do, to get the program to run.

            1. Open SuperAdventure.sln in Visual Studio (there is also a “Simple RPG” solution, but I used the SuperAdventure solution). In the SuperAdventure project, edit the Program.cs file. Change the name space (on line 7) to from “Simple_RPG” to “SuperAdventure”.
            2. Right-click on the SuperAdventure project and choose “Set as StartUp Project” – so Visual Studio will know the UI project is the project to run.

            Let me know if that doesn’t fix the problem.

          • Christopher K
            Christopher K April 29, 2018

            Oh. I changed the one I think you meant. I changed the program one now and it is working. Thank you!

          • Scott Lilly
            Scott Lilly April 29, 2018

            Great! Let me know if you have any other questions.

  3. Scott
    Scott October 27, 2015

    Yes! It worked thank you so much! Love these lessons now I can finally see how it looks. thanks again.

  4. Jeremie
    Jeremie August 29, 2016

    Hey Scott

    this was my first experience with visual studio and programming, and i had a lot of fun ! really great tutorial and looking forward to continue this one with the enhancements to the game !

    Thanks you so much for doing this really complete tutorial

    Keep up ! 🙂

    • Scott Lilly
      Scott Lilly August 29, 2016

      Thanks! I’ve started creating the lessons for a WPF version of the game, which will eventually add more capabilities to the game. I should be posting the initial lessons in the next week or two.

  5. Trung
    Trung September 28, 2017

    Hi Scott, I really appreciate your C# lessons as they gave a lots of insight into how to make a windows form application, as I have only have some previous experiences with C and Java.
    Now, onto my question, I ran into some problem when trying to compile the program in the final step. I have 2 errors which I don’t know how to resolve since the C# source file here doesn’t related to the files in the tutorial.
    https://1drv.ms/i/s!Amn8G2mbfJJfiYgPQxAhZUdSPKlr8g
    I also want to mention that when I commented those files, the game compiled normally, but I can’t kill the rat in the first quest since the use button didn’t work, so I suspect that the error has something to do with the “use” button
    Sorry if my description is to vague to you, in that case, here is my solution:

    https://1drv.ms/u/s!Amn8G2mbfJJfiYgQ_Ir4ub2_oVZumA
    Thanks for reading my question 🙂

    • Scott Lilly
      Scott Lilly September 28, 2017

      Hello Trung,

      For the first problem, when you were working with SuperAdventure.cs in the Design screen, you might have accidentally double-clicked on a control. When that happens, Visual Studio creates an “eventhandler” and a new function. If you paste in code from one of the lessons, that code will not have the function – which causes the error. You can comment out lines 243 and 290, in SuperAdventure.Designer.cs. Those are the eventhandlers you do not need.

      For the “Use” button, it is missing its eventhandler. To fix this, edit SuperAdventure.cs, in the “Design” screen (you should be able to do this after you comment the two extra eventhandler lines). Left-click on the “Use” button once. Look at the “Properties” section in the lower-right corner of Visual Studio (see the picture below). Click on the lightning bolt picture (to see all the events). Find the “Click” event, and left-click in the box to the right of it. This will show you the available functions. Select “btnUseWeapon_Click”. That will create the eventhandler to connect the “Use” button to the function to use the weapon.

      Connect the Use button to its function

      You can read more about eventhandlers in Lesson 21.3.

      Please tell me if that does not fix the problem.

      • Trung
        Trung September 29, 2017

        My gosh, I can’t believe that the solution is so simple I have finally been able to fix the problem, thank you so much.
        As for the event handle, I have only reached lesson 17.1 of yours, so I haven’t thought about it. Now I can finally resume building the game.
        Just one question, do you work on any other languages other than C#?

        • Scott Lilly
          Scott Lilly September 29, 2017

          You’re welcome. Right now, I mostly work in C# and use SQL database. I’ve used other languages in the past, but not for several years.

          • Trung
            Trung September 29, 2017

            Hey Scott, I have one small problem. After having fixed the button things, I encountered “NullPointerException” after having completed a quest and go back (like when I retrieved 3 snake tails and so South), I got this
            https://1drv.ms/i/s!Amn8G2mbfJJfiYgcfNLqgc-adISn6A
            🙁

          • Scott Lilly
            Scott Lilly October 1, 2017

            Hi Trung,

            I can’t login to my Microsoft account, to look at your screenshot. But, check the eventhandlers for the movement buttons, to ensure they are moving to the correct location. The “South” button should call btnSouth_Click. If it is calling a different direction, that is one thing that could cause that error.

            If that is not the problem, can you post the error message in another place?

  6. Trung
    Trung October 3, 2017

    Sorry for the late reply, works in college carried my away.

    Anyhow, I can assure you that I have linked all the buttons with their appropriate events. As for the OneDrive link, I found it a little odd that since I thought that the link allow anyone to view and download the photo, with or without a Microsoft account. But here is my alternate Google drive link: https://drive.google.com/file/d/0B3ZAN8xIbpCdWlJBVkdwUjE3OTg/view?usp=sharing

    • Scott Lilly
      Scott Lilly October 3, 2017

      Hi Trung,

      If the buttons are all connected correctly, my next thought is to look at the PopulateLocations() function in the World class. Make sure all the lines that set the LocationToNorth/East/South/West properties are set correctly. If this is happening when moving South from the Alchemist’s Garden (for example), make sure there is the line:

      alchemistsGarden.LocationToSouth = alchemistHut;

      If you can’t find the source of the error there, can you upload your solution (including the folders under it, and all the files in them) to GitHub or Dropbox, so I can look at it?

      The OneDrive problem is with my Microsoft accounts. I have several of them, tied to different countries (I lived overseas for several years). So, logging in is often a problem for me. 🙁

  7. Brayn
    Brayn December 15, 2017

    Hello, I have some problems with the player movement. When I start the program and click on North, nothing happened. What have I do wrong??

    The error list doenst say anything. The name of the button is btnNorth

    • Scott Lilly
      Scott Lilly December 18, 2017

      It sounds like the button does not have its “eventhandler” – the line of code that says what function to run when the button is clicked.

      Look in SuperAdventure.Designer.cs, and see if it has this line:
      this.btnNorth.Click += new System.EventHandler(this.btnNorth_Click);

      If that line does not exist, add it near the other “btnNorth” lines.

      There is more information on how to use eventhandlers in Lesson 21.3. Please tell me if that does not fix the problem.

  8. Martin
    Martin February 4, 2018

    Hi again,

    another problem occur. When I choose the Build Solution, then on the bottom I can see description “Build Successed”, but no link where it was build, like in video, and the build doesn’t exist in the folder, where it could suppossed to exist. In fact, there is no Debug or Release folder at all in my Project folder. How come ?

    • Scott Lilly
      Scott Lilly February 4, 2018

      Make sure you are looking for the “bin” folder under the project folder, and not the solution folder.

      If it is not there, right-click on the “SuperAdventure” project (inside the Solution Explorer in Visual Studio) and select “Properties”. Click on “Build” and look for the “Output path:” value.

  9. Martin
    Martin February 5, 2018

    Yeah, the output path helped me found those files. Pretty hide though, thanks again !

  10. Chloe
    Chloe April 18, 2018

    Hi Scott,

    I ran into a couple bugs when I tried to follow the tutorial.

    First off, when I get to a location where a monster is, the weapon and potions combo list and use buttons don’t show up, despite their visabilities being set to true.

    Then If you try to go back to a location that has already given a quest I get NullRefferenceException from the HasThisQuest method in the player class.

    I’m sorry if my descriptions are vague. In LINK REMOVED FOR PRIVACY there are screenshots of my issues and my Solution and Files.

    Thanks in advance for your help!

    • Scott Lilly
      Scott Lilly April 18, 2018

      Hi Chloe,

      I noticed you set debug breakpoints (EXCELLENT JOB!) to help you track down the problem. However, the problem was happening after those breakpoints. In the UpdateWeaponsListInUI() function, the weapons combobox is hidden if the player does not have any weapons – which is what is happening for you. From one of the earlier lessons, you need to add a default weapon to the player’s inventory.

      In the constructor for SuperAdventure.cs, make sure you have this third line that gives the player a rusty sword:
      _player = new Player(10, 10, 20, 0, 1);
      MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
      _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));

      Let me know if that doesn’t fix the problem, or if you have any other questions.

      • Chloe
        Chloe April 18, 2018

        Thanks! That fixed my one problem, but now my game crashes when I try to go back to a screen with a quest. I followed the problem to when it attempts to load the quest that is available, when ever a new PlayerQuest is created, it’s details are always null. I’ve updated the Dropbox link with my new code, but I’ll link it again LINK REMOVED FOR PRIVACY for convenience. I’m really confused.

        Thanks again for your help and your awesome tutorials. You still respond to questions on this tutorial 3 years after it was published, and that makes quite a difference.

        • Scott Lilly
          Scott Lilly April 20, 2018

          Hi Chloe,

          I’m sorry I skipped over the second question. I’ve been working on several things, and that just fell out of my mind.

          If you look at the error message, it says that the PlayerQuest.Details property is null. To debug the problem, you would want to see where there property is being set – since it should not be null. The PlayerQuest object is instantiated on line 149 of SuperAdventure.cs. “newLocation.QuestAvailableHere” is passed into the PlayerQuest constructor. If we set a breakpoint there, we see that “newLocation.QuestAvailableHere” has a value, which is what we expect.

          So, the next step is to look at the PlayerQuest constructor. The name of the parameter is “details” (with a lower-case “d”). But, on line 16, when you try to assign the parameter value to the “Details” property, you have “Details = Details;” (with an upper-case “D”). So, that parameter value is never put into the property.

          I’ll leave the solution to you, but let me know if you have any problems.

  11. Kay
    Kay December 10, 2019

    Dear Scott Lilly:

    I am able to run my game by clicking the “Run” button in the visual studio just fine. However, whenever I click on the “exe” button in my file explorer or on a desktop shortcut, nothing happens. The game does not open that way.

    • Scott Lilly
      Scott Lilly December 10, 2019

      Did you copy the files to another computer, or are you trying to run the same computer with Visual Studio? If you are trying this on another computer, it might not have the correct version of .NET installed, or it might not have all the files from the SuperAdventure\bin\debug (or SuperAdventure\bin\Release) folder.

      If you see the problem on the same computer with Visual Studio, try opening the solution in Visual Studio and select (from the top menu) Build -> Clean Solution, then Build -> Build Solution. This will make sure the files in the bin\debug (or bin\release) folder were deleted and built from scratch.

      Let me know if those don’t fix the problem.

      • Kay
        Kay December 10, 2019

        I don’t know how, but it did solve the problem. Thank you!

      • Kay
        Kay December 10, 2019

        Okay, never mind. It works when I open it from my File Explorer, but not when I try to use the shortcut I copy-pasted onto my Desktop.

        • Scott Lilly
          Scott Lilly December 12, 2019

          In your Windows Explorer, make sure you have the “File Name Extensions” checkbox checked, and that your shortcut is pointed to the Application, not the XML configuration file. If the checkbox is not checked, the “config” is not shown on the filename, and it looks like the program file.

          • Kay
            Kay December 13, 2019

            Oh, man! I just realized what I did wrong, and I am seriously laughing at myself now. I hope you get a kick out of this, too. I was copy-pasting the ICON of the exe file, not the file itself. I should have known to pick “Paste Shortcut” instead of “Paste”. What a goofy mistake to make! At least I learnt from it.

  12. Anurag Kotamraju
    Anurag Kotamraju July 23, 2020

    Hello,

    I released the code and developed an exe file but when I open it and click north, it doesn’t work. Where might have gotten it wrong? Would you please guide me?

    • Scott Lilly
      Scott Lilly July 23, 2020

      It sounds like the eventhandlers might not be connected for the buttons. You can read about eventhandlers in lesson 21.3

      If that doesn’t solve the problem, can you upload your solution (including the directories under it, and all the files in those directories) to GitHub or Dropbox, so I can look at it?

  13. CAP10 KENWAY
    CAP10 KENWAY July 28, 2020

    Hi Scott,
    i have a big problem. Every time i open the Game nothing happen the Game is not working.I can see everything but i cant see anything like messages and the other things. I can press all keys exept the 2. Use key (btnUsePotion) when i press that key, a error comes up.

    • Scott Lilly
      Scott Lilly July 28, 2020

      What does the error message say? Does it give a description of the error and the class and line number where the error is happening?

  14. Gabriel K.
    Gabriel K. July 29, 2020

    Hello,
    I have a problem:
    I click on the game and it starts normally, but when I click on “north” nothing happens.
    Could you please help me? What did I do wrong?

    • Scott Lilly
      Scott Lilly July 29, 2020

      Like I said in my other response to you, can you upload your solution (including the directories under it, and all the files in those directories) to GitHub or Dropbox, so I can look at it?

  15. CAP10 KENWAY
    CAP10 KENWAY July 29, 2020

    It says
    “An unhandled exeption has occurred in the application, if you click Continue and application will ignore the error and try to continue. If you click “finish” the application will closed by winning and no object reference is set to an instance of an object.”

    • Scott Lilly
      Scott Lilly July 29, 2020

      Can you upload your solution (including the directories under it, and all the files in those directories) to GitHub or Dropbox, so I can look at it?

Leave a Reply

Your email address will not be published. Required fields are marked *