• Home
  • Index
  • Search
  • Download
  • Server Rules
  • House Roleplay Laws
  • Player Utilities
  • Player Help
  • Forum Utilities
  • Returning Player?
  • Toggle Sidebar
Interactive Nav-Map
Interactive DarkMap
Tutorials
New Wiki
ID reference
Restart reference
Players Online
Player Activity
Faction Activity
Player Base Status
Discord Help Channel
DarkStat
Server public configs
POB Administration
Missing Powerplant
Stuck in Connecticut
Account Banned
Lost Ship/Account
POB Restoration
Disconnected
Member List
Forum Stats
Show Team
View New Posts
View Today's Posts
Calendar
Help
Archive Mode




Hi there Guest,  
Existing user?   Sign in    Create account
Login
Username:
Password: Lost Password?
 
  Discovery Gaming Community The Community Real Life Discussion
« Previous 1 … 80 81 82 83 84 … 246 Next »
A lil C# help

Server Time (24h)

Players Online

Active Events - Scoreboard

Latest activity

Pages (3): « Previous 1 2 3 Next »
A lil C# help
Offline Huhuh
05-02-2013, 02:13 PM,
#11
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

(05-02-2013, 01:56 PM)utrack Wrote: -snip-

Thanks, that really helped.

After a quick play, I've got my player sprite moving across the screen by itself. I'll simply have to write the appropriate methods for controlling it.

[Image: 6fZYcda.gif]

Reply  
Offline Huhuh
05-06-2013, 11:07 AM, (This post was last modified: 05-06-2013, 12:10 PM by Huhuh.)
#12
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

Hey guys, another question:

How to do read and write to a text file from resource?
I have already created and populated the text file, and I have added it to my program. I'm just having trouble figuring out how to access it.

edit:

Code:
/// <summary>
        /// Loads the high scores from a resource file
        /// </summary>
        public void LoadScores()
        {

            StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(SpaceInvaders.Properties.Resources.hiscores));

            string line;
            string[] fileArray;

            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                fileArray = line.Split(','); // splits the information from the csv file by commas

                string name = fileArray[0];
                int score = int.Parse(fileArray[1]);

                Score s = new Score(name, score);
                scoresList.Add(s);
                listBoxScores.Items.Add(s.GetScore());
                Debug.WriteLine(s.GetScore());
            }//while
          
            
            reader.Close();
        }

This is my code as it is, I'm being thrown this error in the output window:
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll

My thinking is the file not being read in correctly.

[Image: 6fZYcda.gif]

Reply  
Offline Huhuh
05-15-2013, 08:58 AM,
#13
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

Hey guys, new issue:

Where do I find the keydown/press/up for the arrow keys? Do I need some sort of listener or can I just have an event on my form that triggers when an arrow key is pressed?

[Image: 6fZYcda.gif]

Reply  
Offline Stuffz
05-15-2013, 11:39 AM, (This post was last modified: 05-15-2013, 11:39 AM by Stuffz.)
#14
[KNF] - Kusari Naval Forces
Posts: 483
Threads: 30
Joined: Mar 2011

Google helps a lot.
http://msdn.microsoft.com/en-us/library/ms171538.aspx
Reply  
Offline Huhuh
05-16-2013, 01:24 PM,
#15
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

(05-15-2013, 11:39 AM)Stuffz Wrote: Google helps a lot.
http://msdn.microsoft.com/en-us/library/ms171538.aspx

Does not show how to use arrow keys.

[Image: 6fZYcda.gif]

Reply  
Offline Stuffz
05-16-2013, 01:38 PM,
#16
[KNF] - Kusari Naval Forces
Posts: 483
Threads: 30
Joined: Mar 2011

Another 5 seconds google..
http://www.dreamincode.net/forums/topic/...rrow-keys/

If e.KeyCode = Keys.Up Then
MessageBox.Show("It worked")

You'll have to use KeyDown for arrow keys tho
Reply  
Offline Huhuh
05-16-2013, 01:47 PM,
#17
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

(05-16-2013, 01:38 PM)Stuffz Wrote: Another 5 seconds google..
http://www.dreamincode.net/forums/topic/...rrow-keys/

If e.KeyCode = Keys.Up Then
MessageBox.Show("It worked")

You'll have to use KeyDown for arrow keys tho

That is VB, and it appears that the syntax is different.

[Image: 6fZYcda.gif]

Reply  
Offline Ichiru
05-16-2013, 01:53 PM, (This post was last modified: 05-16-2013, 01:58 PM by Ichiru.)
#18
Librelancer, LancerEdit
Posts: 811
Threads: 80
Joined: Oct 2011
Staff roles: Coding Dev

Try this Crackpunch

In Form1() or whatever your constructor is called
this.KeyDown += HandleKeyDown;

void HandleKeyDown (object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up) {
//do stuff here
}
}

Also for your high scores use a file instead of a resource, you can't write to a resource. Also make sure that scoresList has been set somewhere. So in Form1() Or Form1_Load etc. make sure there is a line that says scoresList = new List<string>();

Add me on skype at crazy.ichiru if you want any more help. I've got enough experience Tongue

Acolyte of NoMe
  Reply  
Offline Huhuh
05-16-2013, 02:03 PM,
#19
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

I fixed the high scores file a while ago.

The key presses still aren't working. I'm thinking it might have something to do with my listbox on the form, as I can see it selecting things while I'm actually trying to steer my space ship.

I'll skype ya later, off to bed now.

[Image: 6fZYcda.gif]

Reply  
Offline Stuffz
05-16-2013, 02:11 PM,
#20
[KNF] - Kusari Naval Forces
Posts: 483
Threads: 30
Joined: Mar 2011

Alright. So I opened VS myself and coded a bit.

This works for me:

Code:
void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                MessageBox.Show("Form.KeyPress: '" +
                    e.KeyCode.ToString() + "' pressed.");

            }
       }

And this in the constructor of the form:

Code:
this.KeyPreview = true;
this.KeyDown+=
                new KeyEventHandler(Form1_KeyDown);
Reply  
Pages (3): « Previous 1 2 3 Next »


  • View a Printable Version
  • Subscribe to this thread


Users browsing this thread:
1 Guest(s)



Powered By MyBB, © 2002-2026 MyBB Group. Theme © 2014 iAndrew & DiscoveryGC
  • Contact Us
  •  Lite mode
Linear Mode
Threaded Mode