Jump to content

  • Log In with Google      Sign In   
  • Create Account

c# help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 cyril98   Members   -  Reputation: 115

Like
0Likes
Like

Posted 11 December 2012 - 07:56 PM

hi guys i need some help whenever i compile code like this it comes up with random errors and i followed the book of ron pentons properly

class lexington
{
weapon = lazarus revolver
armor = military uni
level = 70
}

now i get these errors
; needed
undeclared variable which is strange because i have declared it

thanks :)

Sponsor:

#2 Khaiy   Crossbones+   -  Reputation: 1342

Like
2Likes
Like

Posted 11 December 2012 - 10:56 PM

At a glance, I notice several things:

-Each statement needs a semicolon (;) after it
-Not having semicolons will screw up the rest of your code that comes after where it ought to be
-Individual variables cannot be separate words like "lazarus revolver"
-The variable types in the code are not declared

I suspect that there are more issues as well, but it's hard to say for certain what they would be based on this fragment of code alone. If you post more code I'll be able to help you more, and I don't want to make guesses about what you're doing based on this alone. But from what's already here, I think that you may want to spend some more time practicing C# syntax before tackling something game-sized.

I think it's unlikely that you're following Ron Penton's book correctly, given that code formatted as above will never compile in C#. As a good general rule, remember that errors aren't random. They always represent problems in your underlying code, and they contain highly relevant information (even if the relevance isn't clear).

#3 adt7   Members   -  Reputation: 434

Like
1Likes
Like

Posted 12 December 2012 - 06:35 AM

The post above is 100% correct, you really need to take the time to learn C# and it's syntax before going any further.

As for your code, I believe something along the lines of the following is what you were actually trying to achieve:

class Lexington
{
    private String weapon = "lazarus revolver";
    private String armor = "military uni";
    private int level = 70;
}


#4 BCullis   Crossbones+   -  Reputation: 1813

Like
1Likes
Like

Posted 12 December 2012 - 10:40 AM

i followed the book of ron pentons properly

No, no you didn't.

I'm seriously having a "not sure if trolling" moment here. At any rate, the other posters have hit the nail on the head: you're not using correct C# syntax at all. Look at adt7's code, then look at your book again, and notice the things you left out.
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#5 cyril98   Members   -  Reputation: 115

Like
0Likes
Like

Posted 12 December 2012 - 05:01 PM

could someone take a look at my code and please give me a few pointers thanks
i didnt mean to troll

#6 Khaiy   Crossbones+   -  Reputation: 1342

Like
0Likes
Like

Posted 12 December 2012 - 07:10 PM

I don't think that you're trolling. But you are being awfully vague in what sorts of "pointers" you're looking for. Based only on the code you posted above, the best advice I can give is to read up on C# syntax. MSDN has some great intro material that is free, though it can be a lot to absorb. I'd give a link, but I'm posting from my phone. I'll edit the link in when I get home. You can also post more code, so that we can get an idea of what you're trying to accomplish.

If you post back with a description of what you want the code fragment you posted to do, I can tell you how I might approach it.

EDIT: Added link to MSDN

Edited by Khaiy, 12 December 2012 - 08:37 PM.


#7 cyril98   Members   -  Reputation: 115

Like
0Likes
Like

Posted 12 December 2012 - 07:32 PM

thanks khaiy :)

#8 bakshadow   Members   -  Reputation: 149

Like
0Likes
Like

Posted 14 December 2012 - 04:03 PM

Some advice and Im not sure if this can be repeated enough, learn c# syntax. What you originally had written looked sudo and nothing resembling c#. Before continueing in your book check out this site, this guy has released 200 c# videos that do a great job teaching almost everything you need to know. http://thenewboston.org/list.php?cat=15




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS