Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 7 8 [9] 10 11 ... 796

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

Aqizzar

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

Ta da! You added a library! Now go surf porn for half an hour as a reward and you are a real programmer!

I didn't realize it was quite that simple.  I'll still need to read the documentation though.  Out of curiosity if you know, what is it about libtcod that makes it write stuff to the console faster than Console does anyway?

Aquizzar, have you tried this thread for help with your rougelike?

No, because I thought that thread was long dead, and I don't like seeing post by me from three years ago and be reminded of how long I've wanted to do this.
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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #121 on: January 07, 2012, 09:57:56 pm »

Well it is truecolor, so I'm guessing it is because libtcod doesn't use the c# console at all.
Rather it produces a black box, and draws stuff onto it, but from a coding point of view, you don't need to worry about graphics or any of that shit, you can treat it just like a normal console.
It is a panel pretending to be a console, and your graphics card can process it's 2d brains out.

Aqizzar

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

It is a panel pretending to be a console, and your graphics card can process it's 2d brains out.

Oh, shit, so it's about the same thing Dwarf Fortress uses?  That would explain a lot about both of them, so excellent.  I still think I'll save that for my "serious" project; the one I've been posting pictures of is my learning session, so I want to do everything by hand if possible.  I can definitely think of how I want to use libtcod in the future then, especially since it seems to be perfectly capable of drawing tile graphics as well.
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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #123 on: January 07, 2012, 10:03:09 pm »

I believe it is similar in concept, yes.
And it is said that the first nine games you make are shit, always, without question, so don't get too attached to them. Something about 90% of everything blah blah meaningless sayings who cares.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #124 on: January 07, 2012, 10:04:16 pm »

I also have experience with robotics, but I'm sure my experience is much more limited. I only know how to program a VEX 2.0 Cortex.

If I do decide to do C/C++/Python tutorials, I'll skip the basics, which Max and Stargrasper have already covered. Most things are similar between similar languages, so I'll only bother bringing up the subtle differences.

Also any code I post here is licensed under the GNU Public License unless noted otherwise. I felt like I should bring this up after the copyright discussion. Feel free to use my code in your programming. Change it, experiment with it, do whatever it takes for you to learn.

Stargrasper, your tutorials, as well as any tutorials anyone decides to post here, are welcomed and encouraged. I'll be adding links to the OP later to make it easier to navigate.

For the last time, f* the copyright!  It's there because I keep copying the comments lesson code for starter code.  All I want is to get acknowledged for what I did.  Do whatever the hell you want with my stuff!

I can do C and C++ tutorials as well if anyone wants me to.  Python...I can do, but I need to brush up on it.  SQL I can do.  Verilog I can do.  Assembly I can do if you let me brush up on it.  I can handle tutorials for most anything.  Just ask and give me enough time.

Na, I have been wanting to do this forever.

If I want to cast some numbers into a boolean value, is that possible, and  what would that look like?

Sort of not really...  Traditionally, 0 is false and anything else is true.  In fact, C/C++ implement that directly.  Java refuses to.  The easiest way to make Java do that is with a conditional, which I actually was already writing into the next tutorial.  Here's how it looks like and I'll explain it in detail in the tutorial in a day or so.

Code: [Select]
package com.bay12forums.stargrasper.javatutorials.if_example;

public class If {

public static void main(String[] args) {
// Pick a number
int randomNumber = 15;
// Declare our boolean
boolean myBoolean;

/*
* Check if our number, randomNumber is equal to 0
* In Java, we check for equivalence with ==
*/
if (randomNumber == 0) {
// If the condition is true, that is, randomNumber is zero
// Move to this inner block of code
myBoolean = false;
} else {
// If the condition is not true, move to the else block
myBoolean = true;
}
/*
* Conditionals will only ever execute one of the given blocks
* of code.  Either the true code, under if, or the false
* code, under else.  The other is skipped entirely.
*/
}

}

Or isn't that what you're trying to do?  "Casting number to a boolean" is kind of vague.

Ask any questions you have.  I'm happy to answer them.
Logged

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #125 on: January 07, 2012, 10:06:00 pm »

Something it took me the longest time to figure out in C# libtcod (and it might be a little different now, I use an older version that wasn't stripped of certain functionality by a change in the way they updated it to newer versions) was the way to initialize it, and keep it running.

(anything between ##'s in the following example should be replaced by your own thing)

Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using libtcod;

namespace _______
{
    class Display
    {
        public static void Init()
        {
            // Use this if you want to define your own font image
            TCODConsole.setCustomFont(##FONT LOCATION##, (int)TCODFontFlags.LayoutTCOD);

            // This initializes the libtcod console
            TCODConsole.initRoot(95, 60, ##CONSOLE TITLE##, false, TCODRendererType.OpenGL);
        }

        public static void UpdateScreen()
        {
            // Clear the console
            TCODConsole.root.clear();

            // put code between these two things that draw to the console

            // This updates the console
            TCODConsole.flush();
        }

    }
}

Like I said, things have changed from the version I use, so you might have to play around with it.
« Last Edit: January 07, 2012, 10:08:41 pm by Willfor »
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #126 on: January 07, 2012, 10:06:44 pm »

That copyright thing wasn't meant to be an attack against you. I really don't care how/if you copyright your code. I'm just saying that for my code, you can do whatever without worrying about me getting mad or anything.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #127 on: January 08, 2012, 12:22:12 am »

Still using C# here, but I bet that whole family of programs has something like this.

I'm making a conditional operation, and using a standard If/Else seems inappropriate here, because if the value to be checked fails, I want nothing to happen.  Is there a one-line conditional check?  It feels sloppy putting in dummy statements just to complete the If/Else structure.
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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #128 on: January 08, 2012, 12:31:37 am »

Well I have had a bit to drink, but I couldn't make heads or tails of that.
Would you please post the code you already have that relates to the problem? I read code better than English.

Although from the sound of it, I think you want if if statement. Just an if statement, no else. For example.
Code: [Select]
            if (x < 5)
            {
                x = 5;
                doSomeShit(x);
            }
That will work fine. No else statement and all is cool with the world. You do not need
Code: [Select]
            if (x < 5)
            {
                x = 5;
                doSomeShit(x);
            }
            else
            {
            }

EDIT:
Also, before I forget. If you only want one line after your if statement, you don't need the {}
So
Code: [Select]
            if (x < 5)
                x = 5;

is totally legal. You can do that. I advice against it. This is because when you want to modify or fix your code, you will find it most oftern needs to be changed within an if statement or a loop. Adding the {}, although not needed, makes it a lot easier to find. It compiles the same anyway, so it doesn't even slow the program down a single tick, it just makes life a little easier on you.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #129 on: January 08, 2012, 12:58:50 am »

Still using C# here, but I bet that whole family of programs has something like this.

I'm making a conditional operation, and using a standard If/Else seems inappropriate here, because if the value to be checked fails, I want nothing to happen.  Is there a one-line conditional check?  It feels sloppy putting in dummy statements just to complete the If/Else structure.

Most other languages have a ? : operator, that acts sort of like this:

Code: [Select]
x = (2 > 1) ? 'woot math' : 'boo math'  #if 2 is greater than 1, then return 'woot math' to x, else return 'boo math'.
Code: [Select]
(myvalue == 'good') ? print('Everything is fine') : null So the bit before the question mark is the conditional, the bit after the question mark is if the conditional resolves to true, and the bit after the colon is if it resolves to false.

If c# doesn't use the exact same syntax, it probably has something similar.  About the only language I've used that DIDN't use that syntax is python for some reason. 
« Last Edit: January 08, 2012, 01:01:40 am by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #130 on: January 08, 2012, 01:10:20 am »

That is because Python is more retarded than Java.
It is like programming languages are subject to inbreeding, and the higher level they are, the more retarded they are. C# is somehow not more retarded than a lot of shit, at the cost of being Microsoft's bitch.

But yea, c# has that.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #131 on: January 08, 2012, 01:11:26 am »

I suspect C# would have the ?: operator, since C++ and Java, the two languages it primarily is based on, use it.

True fact: ?: is the only ternary operator in C++. It takes the condition, the if-true statement, and the if-false statement as arguments.

That is because Python is more retarded than Java.
It is like programming languages are subject to inbreeding, and the higher level they are, the more retarded they are. C# is somehow not more retarded than a lot of shit, at the cost of being Microsoft's bitch.

But yea, c# has that.

You see? This is EXACTLY the kind of garbage I wanted to avoid.



THIS IS WHY WE CAN'T HAVE NICE THINGS.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #132 on: January 08, 2012, 01:17:15 am »

Leave me drunk, I'm alone.

Gonna go crash the JVM now, BRB.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #133 on: January 08, 2012, 01:19:40 am »

Leave me drunk, I'm alone.

Gonna go crash the JVM now, BRB.

You just redeemed yourself.

Carry on.

EDIT: While screwing around with code with a friend (yes I am that much of a nerd), we discovered a great way to make Python eat a ton of memory:

Code: [Select]
x = []
x.append(x)
for a in x: x.append(a)

Let's examine what's going on here. The first line constructs an empty array named x. Simple enough.

The second line is where things start to get interesting. X appends a new element in the array, itself. Because of the way Python handles stuff like this, you get an infinitely-deep nested array. The output for ">>> x" is "[[...]]". Surprisingly enough, Python doesn't die on that line. It apparently was designed while keeping in mind ways people would be trying to break it.

The third line is the kicker. For each element a in x, a is appended to x. Well, at the first execution of the loop. the only element in x is that infinitely-deep nested array. So, it gets appended to the array. The output at this point would be "[[...], [...]]". Then, it iterates to the next element in the array, which is that recursive nightmare that we just appended. Repeat ad infinitum.

Recursion is !!FUN!!
« Last Edit: January 08, 2012, 01:26:52 am by Mego »
Logged

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #134 on: January 08, 2012, 01:27:35 am »

I promise to detail all of this and more when I write that tutorial on conditionals.  I'll probably write it tomorrow.

In short, though, you never need to add the else clause to a conditional.  It's entirely optional and preferred to leave it out than to have an else clause with a noop or one that's empty.  It actually turns out that there's three or four ways to handle conditionals...some a bit more creative than others.  I'll cover it later.  You'll just have to take the generic information (which I imagine will all apply) and translate the Java to C#.

Also, I really need to get back to my own projects.  Just have to fit it between time spent with people (which I'm sorely lacking...I miss my friends), homework, the unnecessarily large amount of time it takes to write Java tutorials that exactly one person is reading, taking care of the house, and other miscellaneous things.  There has to be time somewhere...right...?
Logged
Pages: 1 ... 7 8 [9] 10 11 ... 796