Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 3 [4] 5 6 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 831453 times)

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #45 on: January 04, 2012, 01:19:19 am »

Does anyone here have experience with graphical tile-based stuff in C++? I'd like to make a roguelike which displays tiles similarly to DF; since I suppose that using basic graphics rather than the console/terminal will make it more portable (ideally Mac OSX and GNU/Linux, but Windows would be nice too). Right now I'm looking at using OpenGL's texture mapping on an 80x25 group of squares (each square being the same size as one character in the tileset) which are drawn in a window. Is that a good way to go about it, or is there a better option?


If the goal is the game and not learning drawing stuff, why not use one of the dozen roguelike libraries out there?
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #46 on: January 04, 2012, 02:50:10 am »

I know this is something the other programming thread did/does, but I like the idea and I'm going to do it here too.

I issue a challenge to Bay12 programmers.

Challenge: Write a program in any language of your choosing that acts as an interpreter for that language, in that it takes code as input and gives the output from running that code.

Restrictions: If you are using an interpreted language, you cannot simply use a built-in function that takes code as input and gives you the output, like Python's exec() function. You can use anything else, whether it is built-in, code you write, or a third-party library. In addition, simply copying an example from the internet won't teach you anything except how to copy and paste code. This is for people to develop their skills and learn more about different programming languages.

Let's see how many different languages we can get here. In a little bit, if I can find it, I'll post my C++ program.

You've written a C++ interpreter?  How much of the standard did you implement, because that must be bogglingly large if it implements much of it.
Logged
Through pain, I find wisdom.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #47 on: January 04, 2012, 06:34:43 am »

Posting to enjoy.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #48 on: January 04, 2012, 08:06:39 am »

I know this is something the other programming thread did/does, but I like the idea and I'm going to do it here too.

I issue a challenge to Bay12 programmers.

Challenge: Write a program in any language of your choosing that acts as an interpreter for that language, in that it takes code as input and gives the output from running that code.

Restrictions: If you are using an interpreted language, you cannot simply use a built-in function that takes code as input and gives you the output, like Python's exec() function. You can use anything else, whether it is built-in, code you write, or a third-party library. In addition, simply copying an example from the internet won't teach you anything except how to copy and paste code. This is for people to develop their skills and learn more about different programming languages.

Let's see how many different languages we can get here. In a little bit, if I can find it, I'll post my C++ program.

You've written a C++ interpreter?  How much of the standard did you implement, because that must be bogglingly large if it implements much of it.

Actually, I posted the code here a few posts up. It's not a true interpreter, because it actually compiles the code using g++ and executes it, but it gives the appearance of being an interpreter, which is what I was going for.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #49 on: January 04, 2012, 08:34:45 am »

Ohhh, haha, yes, that makes much more sense.  I was having a hard time thinking up all of the features a full compiler would need, much less how to pack that into an interpreter.
Logged
Through pain, I find wisdom.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #50 on: January 04, 2012, 09:58:53 am »

a question to other fellow programmers: what the hell is a functional diagrams with functional components?

in the way they described it to me it sounded like the usual component diagram but with component described instead that being called with their own name, which, frankly, is what the glossaries are for.

I guess they have some sort of use, but the wikipedia page is filled with meaningless gibberish:
http://en.wikipedia.org/wiki/Functional_software_architecture
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #51 on: January 04, 2012, 01:25:54 pm »

At least the Wikipedia page knows it is filled with gibberish. From what I've understood, the Wikipedia page names a software development process and then proceeds to explain all its benefits without actually explaining the process itself, an example of perfect managerese. But this has so little to do with programming that if you replace some abbreviations with more general ones, you'd probably get company theory.

I think that what's on the page is not what you're looking for. Functional diagrams are probably just another term for component diagrams. Just use the terms equivalently, until someone tells you that's wrong. Then ask him about the difference, because he seems to know.
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #52 on: January 04, 2012, 07:52:37 pm »

So this is probably a really simple issue, but I can't figure anything out in short order, because I don't know why this isn't working.

Using C# - I'm making a Class for an object, and the many methods to print individual bits of object data.  For some reason, the compiler is throwing a huge fit over having an if/else statement in it, but not other if/else statements, and with some "void" methods but not others, which all seem to stem back to it not liking me working in a namespace.  Anyone know what this is about?
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #53 on: January 04, 2012, 08:00:31 pm »

That is not the most descriptive description of a problematic problem I've ever seen. Care to code some code that your compiler barks at so we can look at it and bark back?
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #54 on: January 04, 2012, 08:07:25 pm »

I've seen a variety of simple issues that often get overlooked and cause problems, and complicated issues that it's best to just not go into why that won't work, that cause errors like those. We'll need some code to be able to help.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #55 on: January 04, 2012, 08:08:11 pm »

Well, nevermind, it solved itself.  I had a method that did some internal math with frequently-referenced data, and figured it'd be a good idea to make the numbers used in that method Private so I wouldn't accidentally namecheck them elsewhere.  For some reason, this caused the whole thing to panic, and disqualified almost everything downward in the file.  I can print the offending chunk if you can explain what's going on, but at least the problem is resolved.

Code: (I don't know how namespaces work.) [Select]
public void printAge()
{
private int months = age % 12;
private int years = age / 12;

if (ageKnown == false)
{
Console.Write("Approx {0} Years",years);
}
else
{
Console.WriteLine("{0} Years, {1} Months",years,months);
}
}

Yeah, unnecessary formatting, I wanted it to be clear.  Age is a ushort by the way, but apparently it works fine.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #56 on: January 04, 2012, 08:11:28 pm »

I don't know what's supposed to be wrong with that code, but you're mixing Write and WriteLine without obvious reasons. Also, are age and ageKnown defined in your class or  global variables? Else, that's going to cause some barking as well. There's also nothing wrong with your formatting, I think that's GNU style? I also use that for Ada-like languages as putting every bracket on a line helps keeping track of scope.
« Last Edit: January 04, 2012, 08:14:53 pm by Virex »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #57 on: January 04, 2012, 08:12:12 pm »

Wait you can have private variables within functions? How does that work?

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #58 on: January 04, 2012, 08:14:10 pm »

I don't know what's supposed to be wrong with that code, but you're mixing Write and WriteLine without obvious reasons. Also, are age and ageKnown defined in your class or  global variables? Else, that's going to cause some barking as well

The Write and WriteLine was an error, so thanks.  And age and ageKnown are part of the Object, so it should throw in whatever ones belong to the named Object when the method is called.  Right?

Like I said, it was making the int's private that caused it to lock down.  I took that off and it compiles fine.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #59 on: January 04, 2012, 08:22:47 pm »

Wait you can have private variables within functions? How does that work?
Yeah that's also an error I think, private variables don't make sense outside of class definitions because the variables declared in a function are already private to that function.


I don't know what's supposed to be wrong with that code, but you're mixing Write and WriteLine without obvious reasons. Also, are age and ageKnown defined in your class or  global variables? Else, that's going to cause some barking as well

The Write and WriteLine was an error, so thanks.  And age and ageKnown are part of the Object, so it should throw in whatever ones belong to the named Object when the method is called.  Right?
Yes. C# doesn't make it terribly clear, but when you invoke a function via object.Function(input), you're invoking the function on that object. That means that it will use the function definition for that specific class (or object in case you did something wonky with replacing functions at run-time) and it will use the variables in that object for the function.


What happens in the bytecode generated (at least for most languages) is that the memory address of the object is pushed on the stack first, then any additional parameters you passed to the function. The memory address of the object is then used to retrieve the values of the variables such as age and ageKnown, as they are stored at a specific location relative to the memory adress of the object and the additional paramters are popped from the stack as always.
« Last Edit: January 04, 2012, 08:29:24 pm by Virex »
Logged
Pages: 1 2 3 [4] 5 6 ... 796