Sponsors

Go Back   Zune Boards > Zune Discussions > Zune Games > Development Discussions

New Member?


Register Zunecentive FAQ Members List Calendar Search Today's Posts Mark Forums Read

Development Discussions All developers who are coding games may stop by here for any help, suggestions, and everything development related.

Reply
 
LinkBack Thread Tools
Old 05-15-2008, 09:19 PM   #1 (permalink)
Zuner
 
Greenskull's Avatar
 
Join Date: Feb 2008
Posts: 72
Reputation: 15
$zB: 10
Donate
Default Frustrating problem with my game...

I'm currently designing a rhythm game called BeatWave and I've run into a really stupid problem. I have this line of code: player.Power += 1; and it's in one class but whenever I put it in the other class the game breaks and gives me an unhandled exception. I learn by modifying code so this will help me greatly. Please assist me! Thanks.
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Last edited by Greenskull : 05-15-2008 at 09:23 PM.



Greenskull is offline   Reply With Quote
Remove Advertisements Sponsored Links
Advertisement
 
Old 05-15-2008, 09:29 PM   #2 (permalink)
Zuner
 
Join Date: May 2008
Location: WA
Posts: 69
Reputation: 12
$zB: 60
Donate
Default

Amazingly enough the answer is going to be exaclty the same in here as it was over on the XNA boards: http://forums.xna.com/62123/ShowThread.aspx#62123

Its almost impossible to help with such vague questions when its obvious you don't have a basic grasp of programming. Please take everyone's advice and write and learn some basic c# programs to learn how to do this. Even if we could answer this one I am sure the next time you randomly move a line of code and get a compiler error you won't understand why.

I'll recommend you back to the learning c# FAQ we sent you to originally http://forums.xna.com/thread/16573.aspx
__________________
Zman - XNA MVP

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




TheZMan is offline   Reply With Quote
Old 05-16-2008, 04:40 AM   #3 (permalink)
Zuner
 
Greenskull's Avatar
 
Join Date: Feb 2008
Posts: 72
Reputation: 15
$zB: 10
Donate
Default

I do have at least a basic understanding of c#. The point is I've tried all the logical things to make it work to no avail.
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



Greenskull is offline   Reply With Quote
Old 05-16-2008, 05:31 AM   #4 (permalink)
Zuner
 
Join Date: May 2008
Location: WA
Posts: 69
Reputation: 12
$zB: 60
Donate
Default

Then you are going to have to find a way of expplainign exactly what you are doing and exactly the error message so that people can help you. The questions you are asking can only be answered by a psychic.

e.g. Try asking this in a car forums:
I pulled a random wire out of my car and now it makes a strange noise what is wrong?
__________________
Zman - XNA MVP

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




TheZMan is offline   Reply With Quote
Old 05-16-2008, 06:43 AM   #5 (permalink)
Experienced Zuner
 
jsedlak's Avatar
 
Join Date: May 2008
Posts: 110
Reputation: 22
$zB: 93
Donate
Default

You do not have a basic understanding of C#. You have a basic understanding of what the equal sign does in C#.

The reason you cannot just move a line like that is because code is context sensitive. The entire reason this line of code worked in the first place is because in its original place, the code had access to an object named player (probably of type Player or something similar). When you take the line out of this place and move it to another file, you are removing it from the context and thus that object no longer is available to modify. You have to somehow pass the reference to the new place.


Your best bet to answering this problem is to buy a C# book and learn Object Oriented Programming. It is near impossible to learn how to program just by modifying someone else's game.
__________________
John Sedlak
Microsoft Xna / DirectX MVP

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



jsedlak is offline   Reply With Quote
Old 05-16-2008, 07:40 AM   #6 (permalink)
zB Programmer
Experienced Zuner
 
Join Date: Nov 2007
Posts: 111
Reputation: 35
$zB: 99
Donate
Default

My guess would be(if you get the exception on that line) that Player is null, you haven't initialized it in the new class.
__________________
-Mark
Check out my new game, "Squadron Z":
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


Check out my version of pong with multiplayer:
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



MarcusMaximus is offline   Reply With Quote
Old 05-16-2008, 07:41 AM   #7 (permalink)
zB Programmer
Experienced Zuner
 
Join Date: Nov 2007
Posts: 111
Reputation: 35
$zB: 99
Donate
Default

on another note: come on guys, just tell him to post his code and tell you where to look or something, it should be obvious the guy is trying to learn.
__________________
-Mark
Check out my new game, "Squadron Z":
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


Check out my version of pong with multiplayer:
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



MarcusMaximus is offline   Reply With Quote
Old 05-16-2008, 08:55 AM   #8 (permalink)
Zuner
 
Join Date: May 2008
Location: WA
Posts: 69
Reputation: 12
$zB: 60
Donate
Default

He was asked for more information in the XNA forums (follow the link in my post) and I've suggested that he needs to provide more in here... for some reason he appears to prefer that we make guesses.

We know he's trying to learn but he's not giving enough information.
__________________
Zman - XNA MVP

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




TheZMan is offline   Reply With Quote
Old 05-16-2008, 10:05 AM   #9 (permalink)
Jr. Member
 
SimReality's Avatar
 
Join Date: May 2008
Location: Seattle, WA
Posts: 398
Reputation: 60
$zB: 341
Donate
Default

Quote:
Originally Posted by MarcusMaximus View Post
on another note: come on guys, just tell him to post his code and tell you where to look or something, it should be obvious the guy is trying to learn.
If he really wanted to learn, he would go to one of the thousands of C# tutorials online (like suggested above) or get a book. From these short posts it just looks like he wants to mash code around and have other people solve any of his problems. It does him no good for me (or anyone else) to just fix his code for him. If he wants to become a game programmer, he has to learn the language first and then, secondly, learn how to debug that code. I'm not trying to be mean (and I know neither are the other MVPs above), but there is no gain for anyone by us just solving all of these trivial* problems. We are trying to help him become better by actually taking things slowly and learning one step at a time.

*These are trivial because if the OP spent a few days/weeks learning C# he would be able to solve these himself in a matter of minutes.
__________________
Nick Gravelyn
Microsoft MVP - DirectX/XNA

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



SimReality is offline   Reply With Quote
Old 05-16-2008, 03:08 PM   #10 (permalink)
zB Programmer
Experienced Member
 
LedZepp's Avatar
 
Join Date: Mar 2007
Posts: 950
Reputation: 107
$zB: 610
Donate
Default

I had that problem and I fixed it by making the variable static. But i dont know if it will help him. Like everyone else is saying you need to provide more information about the problem(what is the error saying exactly) and even posting your whole code will help



LedZepp is offline   Reply With Quote
Old 05-16-2008, 06:49 PM   #11 (permalink)
Experienced Zuner
 
jsedlak's Avatar
 
Join Date: May 2008
Posts: 110
Reputation: 22
$zB: 93
Donate
Default

Quote:
Originally Posted by LedZepp View Post
I had that problem and I fixed it by making the variable static. But i dont know if it will help him. Like everyone else is saying you need to provide more information about the problem(what is the error saying exactly) and even posting your whole code will help
Generally a baaaaaaaaad idea just to make something like that static.

This is exactly why you should take the time to learn C#.
__________________
John Sedlak
Microsoft Xna / DirectX MVP

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



jsedlak is offline   Reply With Quote
Old 05-16-2008, 07:06 PM   #12 (permalink)
zB Programmer
Experienced Member
 
LedZepp's Avatar
 
Join Date: Mar 2007
Posts: 950
Reputation: 107
$zB: 610
Donate
Default

Well for me i had everything in my class file static and made the stupid mistake of just declaring the variable without the static keyword, thats why i said it probably wont work for him.



LedZepp is offline   Reply With Quote
Old 05-16-2008, 07:28 PM   #13 (permalink)
putis killed my baby!
Administrator
Ultimate Zuner
 
Nurta's Avatar
 
Join Date: Jan 2007
Location: NYS
Posts: 6,077
Reputation: 266
$zB: 4972
Donate
Awards Showcase
Chiup's Bitch Most Flamboyant Personality 
Total Awards: 2
Default

Yeah, posting code and context is a good idea when asking for help.

My guess based on name is that what you should have is something like:

in the Player class have a method increasePower(int amount)

and in the other class, if you are given p as the current Player, do p.increasePower(1).

I'm guessing power is a private variable and hence you get issues.
__________________
Note: The viewpoint posted above does not necessarily reflect the opinion of Zuneboards, Zuneboard's staff, Nurta, or any affiliate of any of the previously mentioned parties.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

I'm sorry Dizzy, I don't swing that way


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
my army, while you can




Nurta is online now   Reply With Quote
Old 05-17-2008, 10:59 AM   #14 (permalink)
Zuner
 
Greenskull's Avatar
 
Join Date: Feb 2008
Posts: 72
Reputation: 15
$zB: 10
Donate
Default

ok links found out the problem but doesn't know how to fix it. Apparently, when placed into the other class, player is null. How do i change that?
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



Greenskull is offline   Reply With Quote
Old 05-17-2008, 11:12 AM   #15 (permalink)
putis killed my baby!
Administrator
Ultimate Zuner
 
Nurta's Avatar
 
Join Date: Jan 2007
Location: NYS
Posts: 6,077
Reputation: 266
$zB: 4972
Donate
Awards Showcase
Chiup's Bitch Most Flamboyant Personality 
Total Awards: 2
Default

um, you have to define player somewhere...

Again, without your code we have no clue what you are doing...
__________________
Note: The viewpoint posted above does not necessarily reflect the opinion of Zuneboards, Zuneboard's staff, Nurta, or any affiliate of any of the previously mentioned parties.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

I'm sorry Dizzy, I don't swing that way


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
my army, while you can




Nurta is online now   Reply With Quote
Old 05-17-2008, 11:33 AM   #16 (permalink)
Jr. Member
 
The Undead's Avatar
 
Join Date: May 2008
Posts: 325
Reputation: 90
$zB: 8
Donate
Default

I think i have an idea of what your problem is, and a possible way to fix it.

You have one class that has player in it, and you want to be able to use player in another class.

So using my experience in java(yes I know its not C# but the languages are alike)
you would have to do this in the class were player is null like this:
Code:
PlayerObject player;
public void setPlayer(PlayerObject newPlayer)
{
    player = newPlayer;
}
And in the class that already has player defined or assigned as you will
you call it like this
Code:
brokenClass.setPlayer(player)
Again this is all speculation, and some of this may be wrong because 1) you didnt provide much info, and 2) I havent programmed in a while, so im a little rusty.



The Undead is offline   Reply With Quote
Old 05-17-2008, 12:47 PM   #17 (permalink)
Zuner
 
Greenskull's Avatar
 
Join Date: Feb 2008
Posts: 72
Reputation: 15
$zB: 10
Donate
Default

ok so heres where the exception is thrown:

public override void Update(GameTime gameTime)
{
if ((position.Y >= Game.Window.ClientBounds.Height) ||
(position.X >= Game.Window.ClientBounds.Width) ||
(position.X <= -15))
{
MediaPlayer.Stop();
PutinStartPosition();
***** player.Power += 1; *****


}

Where i put stars is the exception
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



Greenskull is offline   Reply With Quote
Old 05-17-2008, 12:56 PM   #18 (permalink)
putis killed my baby!
Administrator
Ultimate Zuner
 
Nurta's Avatar
 
Join Date: Jan 2007
Location: NYS
Posts: 6,077
Reputation: 266
$zB: 4972
Donate
Awards Showcase
Chiup's Bitch Most Flamboyant Personality 
Total Awards: 2
Default

Well, is player a variable throughout the entire class? If so you probably forgot to initialize it in initialize()
__________________
Note: The viewpoint posted above does not necessarily reflect the opinion of Zuneboards, Zuneboard's staff, Nurta, or any affiliate of any of the previously mentioned parties.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

I'm sorry Dizzy, I don't swing that way


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
my army, while you can




Nurta is online now   Reply With Quote
Old 05-17-2008, 01:04 PM   #19 (permalink)
Jr. Member
 
Link9228's Avatar
 
Join Date: Nov 2007
Location: Pennsylvania
Posts: 321
Reputation: 16
Send a message via MSN to Link9228
$zB: 214
Donate
Default

Hey guys, thanks for the help. I'm really close to getting all the kinks out. And those of you up top, you don't have to be so negative towards people. Yes it's helpful to post what your code is when you are having problems, but it doesn't necessarily mean we are retarded people who don't know how to program and we are trying to get everyone else to do the work for us. This is the only problem we have had, and the program's almost done



Link9228 is offline   Reply With Quote
Old 05-17-2008, 05:35 PM   #20 (permalink)
Jr. Member
 
Tiptup300's Avatar
 
Join Date: Apr 2008
Posts: 371
Reputation: 111
$zB: 272
Donate
Default

It's perfectly alright to learn a language by messing around with a person's app. It's how i learned all the languages I learned. But when you give no real description on what the problem is is where people get irritated. Was player as initilized. Like are there any player = new Player(); or anything like that?



Tiptup300 is offline   Reply With Quote
Reply


Thread Tools