|
|
|
|||||||
| Development Discussions All developers who are coding games may stop by here for any help, suggestions, and everything development related. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Zuner
Join Date: Feb 2008
Posts: 72
Reputation: 15
Donate |
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. |
|
|
|
| Remove Advertisements Sponsored Links | |
Advertisement |
|
|
|
#2 (permalink) |
|
Zuner
Join Date: May 2008
Location: WA
Posts: 69
Reputation: 12
Donate |
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. ![]()
|
|
|
|
|
|
#3 (permalink) |
|
Zuner
Join Date: Feb 2008
Posts: 72
Reputation: 15
Donate |
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. |
|
|
|
|
|
#4 (permalink) |
|
Zuner
Join Date: May 2008
Location: WA
Posts: 69
Reputation: 12
Donate |
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. ![]()
|
|
|
|
|
|
#5 (permalink) |
|
Experienced Zuner
Join Date: May 2008
Posts: 110
Reputation: 22
Donate |
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. |
|
|
|
|
|
#6 (permalink) |
|
zB Programmer
Experienced Zuner Join Date: Nov 2007
Posts: 111
Reputation: 35
Donate |
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. |
|
|
|
|
|
#7 (permalink) |
|
zB Programmer
Experienced Zuner Join Date: Nov 2007
Posts: 111
Reputation: 35
Donate |
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. |
|
|
|
|
|
#8 (permalink) |
|
Zuner
Join Date: May 2008
Location: WA
Posts: 69
Reputation: 12
Donate |
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. ![]()
|
|
|
|
|
|
#9 (permalink) | |
|
Jr. Member
Join Date: May 2008
Location: Seattle, WA
Posts: 398
Reputation: 60
Donate |
Quote:
*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.
|
|
|
|
|
|
|
#10 (permalink) |
|
zB Programmer
Experienced Member Join Date: Mar 2007
Posts: 950
Reputation: 107
Donate |
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
|
|
|
|
|
|
#11 (permalink) | |
|
Experienced Zuner
Join Date: May 2008
Posts: 110
Reputation: 22
Donate |
Quote:
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. |
|
|
|
|
|
|
#12 (permalink) |
|
zB Programmer
Experienced Member Join Date: Mar 2007
Posts: 950
Reputation: 107
Donate |
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.
|
|
|
|
|
|
#13 (permalink) |
|
putis killed my baby!
Administrator
Ultimate Zuner Join Date: Jan 2007
Location: NYS
Posts: 6,077
Reputation: 266
Donate |
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 ![]()
|
|
|
|
|
|
#14 (permalink) |
|
Zuner
Join Date: Feb 2008
Posts: 72
Reputation: 15
Donate |
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. |
|
|
|
|
|
#15 (permalink) |
|
putis killed my baby!
Administrator
Ultimate Zuner Join Date: Jan 2007
Location: NYS
Posts: 6,077
Reputation: 266
Donate |
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 ![]()
|
|
|
|
|
|
#16 (permalink) |
|
Jr. Member
Join Date: May 2008
Posts: 325
Reputation: 90
Donate |
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;
}
you call it like this Code:
brokenClass.setPlayer(player) |
|
|
|
|
|
#17 (permalink) |
|
Zuner
Join Date: Feb 2008
Posts: 72
Reputation: 15
Donate |
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. |
|
|
|
|
|
#18 (permalink) |
|
putis killed my baby!
Administrator
Ultimate Zuner Join Date: Jan 2007
Location: NYS
Posts: 6,077
Reputation: 266
Donate |
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 ![]()
|
|
|
|
|
|
#19 (permalink) |
|
Jr. Member
Join Date: Nov 2007
Location: Pennsylvania
Posts: 321
Reputation: 16
Donate |
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
|
|
|
|
|
|
#20 (permalink) |
|
Jr. Member
Join Date: Apr 2008
Posts: 371
Reputation: 111
Donate |
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?
|
|
|
|