This forum is in permanent archive mode. Our new active community can be found here.

Weekend coding

1181921232439

Comments

  • I'd suggest focusing specifically on Python.
  • Apreche said:

    Thanks for reminding me why I correctly vowed never to program in C++ ever again.

    That's okay. Less competition for C/C++ systems programmers like me. :)

    That said, Python's solution to the same problem is to make you use self.send() instead of just send() if you're calling a method on your current object.

  • edited April 2014
    So, my dad asked for an extremely simple program to save him some time and I feel really stupid for not being able to get this working. There's a file which is basically an ordered set of keys seperated by line (cns), and another file with the keys and data that goes along with them (data). The objective is to make a third file (output) with the data in the order given. Here's my python code:
    cns = open('callnumbersequence.txt', 'r')
    data = open('alldata.txt', 'r')
    #output = open('output.txt', 'w')

    for cnsline in cns:
    cnslinewithoutnewline = cnsline.replace("\n", "")
    for dataline in data:
    if cnslinewithoutnewline in dataline:
    print dataline

    For some reason I cannot fathom, it only prints the dataline of the first key in the cns file. I even tried adding a continue statement after the print statement to make it go on with the loop.
    Post edited by Pegu on
  • edited April 2014
    That's because the for loop through the data file can only ever read the data file once - after the "for dataline in data" loop happens once, the position indicator for "data" is now sitting at the end of the file, and so the next time you get to that loop you'll get 0 iterations of the loop.

    You could just re-open the data file every time, or move back to the start of the file on every new loop, but that's not a very good approach. A better approach (assuming the file can fit into memory) would be to first read the data file into some kind of data structure, and then retrieve the data from the data structure when you're looping through the keys.

    An ideal data structure for this purpose is a dictionary - it allows you to efficiently store key-value pairs, and to efficiently look up the value corresponding to a given key.
    Post edited by lackofcheese on
  • Thanks. I didn't realize the iterator wouldn't reset back to zero.
  • myfile.seek(0) would do it, but you probably (read: almost certainly) don't want to do that.
  • I'm not sure this is the best thread for this, but I have an idea for a game I want to make, and I'm wondering what software would work for it. Basically I want to make a series of one-off turn based RPG boss fights, with highly customizable characters and the ability to respec characters and change equipment at no cost, but also no way to gain extra levels or money through other battles.

    What I'm wondering is, will RPG Maker work with this? The game only needs to include character management/equipment screens and combat, no maps or overworld, and needs a degree of character customization that I'm not sure RPG Maker will provide (I have used it in a decade plus). Failing that, would Game Maker help with this? Failing that, any suggestions on tools for this? I really don't want to try making this totally from scratch. Thanks.
  • I'd suggest to at least look at RPG Maker first for that. I'd imagine that after all the time RPG Maker has been a thing, there would be some quite varied tools for anything that might be included in a normal jrpg, including character customization and management.
  • My cursory knowledge of RPG Maker says that you should be able to do a lot with RPG Maker. I know you can at least write scripts for it and you can probably implement the tools to get the numbers to go up and down as you please. The rest of the system is already 80% of the way to what you want without any customization. I would do some more research and see what you can script into the engine. Otherwise I would probably recommend Game Maker Studio. Relatively cheap, simple, you don't even really need to know how to program.

    Although even Unreal has gotten to the point where its possible to make a game with zero programming experience. Just an understanding of logic.
  • MATATAT said:

    .... Although even Unreal has gotten to the point where its possible to make a game with zero programming experience. Just an understanding of logic.

    While that's true, RPG maker is purpose build to make RPGs. There is nothing easier. It has a bunch of assets and framework in place to where if an experienced person was manning it, he could whip up a prototype for this in a day. The same can't be said for Unreal. Unreal is bad for 2D games, and the entire gamelogic and flow is structured around a real-time, event driven game. Use RPG maker.
  • edited July 2014
    Yeah I wasn't suggesting Unreal, I was just making a point. I would suggest Game Maker far before I would suggest even Unity to develop the game he's talking about. But RPG Maker is probably the best bet since the engine is already so focused on the turn based RPG gameflow. I just can't say for sure how extensible it is.
    Post edited by MATATAT on
  • Ikatono said:

    I'm not sure this is the best thread for this, but I have an idea for a game I want to make, and I'm wondering what software would work for it. Basically I want to make a series of one-off turn based RPG boss fights, with highly customizable characters and the ability to respec characters and change equipment at no cost, but also no way to gain extra levels or money through other battles.

    What I'm wondering is, will RPG Maker work with this? The game only needs to include character management/equipment screens and combat, no maps or overworld, and needs a degree of character customization that I'm not sure RPG Maker will provide (I have used it in a decade plus). Failing that, would Game Maker help with this? Failing that, any suggestions on tools for this? I really don't want to try making this totally from scratch. Thanks.

    I suggest you use the tool that you know the best. If you aren't sure which one that is, use the tool that gets you closest to what you want to make. Use tutorials whenever you can find them.

    Then make one level of your game and everything it takes to make that one level reflect the core game experience you want to have in your game. Then have people test it. (If they hate it, that's normal; just try to remove/make changes to things people have problems with). Once you've had it tested by 5 different people you will know where to go from there.
  • Arduino: 3 hours and it's a = where a == should be.
  • edited July 2014
    Omnutia said:

    Arduino: 3 hours and it's a = where a == should be.

    God, I hate bugs like that. It ranks right up there with one of my other "favorite" bugs. See if you can spot it here (it's subtle, but obvious if you look):

    for(int i = 0; i < 10; ++i);
    {
    // do something with i
    }
    Post edited by Dragonmaster Lou on
  • I've actually never seen someone put a ; after the ) like that.
  • edited July 2014
    Semicolon outside the brackets?

    Biggest problem with going hardware + software is working out where the fault is.
    Post edited by Omnutia on
  • Why are you using i as the counter? Bad programmer!!! That and the extra semicolon.
  • HMTKSteve said:

    Why are you using i as the counter? Bad programmer!!! That and the extra semicolon.

    Uh what?
  • I make it a point to never use i anywhere in a program as a counter because you may end up being lazy and use i elsewhere in your code and run into conflicts.
  • Apreche said:

    I've actually never seen someone put a ; after the ) like that.

    Omnutia said:

    Semicolon outside the brackets?

    Yep, that's it. A simple typo that cost me a bunch of hours to figure out back in college. I was pretty new to C at the time and that typo just didn't register as I looked over the code and tried everything else I could think of to figure out what the problem was. I never made that mistake again, but I think the pain of solving that particular bug has kept it in my mind ever since. It's definitely a total "dumbass moment" bug.
    HMTKSteve said:

    Why are you using i as the counter? Bad programmer!!! That and the extra semicolon.

    Well, first, this was an example. I don't remember the actual variable I used in the particular mistake way back when. :) It may or may not have been i, depending on what I was doing at the time.

    Second I only use i as a counter. Similarly, I'll use j and k and so on when doing nested loops, but only in those situations. The only times I use single-letter variables is when I'm using them for a counter, or, sometimes when I'm working with Cartesian coordinates and I use x, y, and z to refer to those coordinate values. I find that these rules also work very well to prevent conflicts, even if they are the exact opposite rules as yours.
  • edited July 2014
    Or you could create a dedicated counting function

    void CounterFunction(int x, function do_this, int argc, char *argv[])
    {
    int i = 0;
    While ( x > i )
    {
    do_this(int argc, char *argv[]);
    i++;
    }
    }


    Or something like that. It has been so long I might have screwed that up. Pointers....

    Edit: freaking autocorrect...
    Post edited by HMTKSteve on
  • That's actually a great example of what Python's good for.

    for thing in things:
    dosomething(thing)


    That's it.
  • Every time I decide to go along the for things in thing route, I end up needing some kind of counter anyway, so default to using i and incrementing. I'm sure there are super useful situations for it but I like the comfort of i.
  • edited July 2014
    For what it's worth, you can go
    for i, thing in enumerate(things)
    too. Auto-increments for you.

    Also I forgot zip(). If you need a counter because you're iterating over lists in parallel, you can `zip(lista, listb)` and you get tuples of the items together.
    Post edited by Starfox on
  • BOOST_FOREACH


    ~_^
  • edited July 2014
    If it's C++, stick to
    for (auto &thing : things) {
    dosomething(thing);
    }
    Post edited by lackofcheese on
  • HMTKSteve said:

    Or you could create a dedicated counting function

    Er, umm, why? Seems like excessive overhead if all you're doing is iterating over an array or performing a repetitive task a fixed number of times.
    HMTKSteve said:

    Or something like that. It has been so long I might have screwed that up. Pointers....

    Yeah... reason enough not to go through the rigamarole of having a special function that takes a function pointer as an argument when all you want to do is iterate over something a number of times. Yes, sometimes you do have to do something like that, but it's not the common case.
    Starfox said:

    That's actually a great example of what Python's good for.

    for thing in things:
    dosomething(thing)


    That's it.

    Starfox said:

    For what it's worth, you can go
    for i, thing in enumerate(things)
    too. Auto-increments for you.

    Also I forgot zip(). If you need a counter because you're iterating over lists in parallel, you can `zip(lista, listb)` and you get tuples of the items together.

    Yeah, I use the for...in... thing in Python fairly frequently, though I didn't know about zip() or enumerate(). I'm not a full-time Python guy, and I know there are certainly useful features in the language I don't know of.
    Andrew said:

    BOOST_FOREACH

    Use it all the time. :)

    If it's C++, stick to
    for (auto &thing : things) {
    dosomething(thing);
    }

    That depends... You need a C++11 compliant compiler in order to support auto and that syntax. Not all of us have compilers that are that up to date.
  • edited July 2014
    Might as well quote myself from the same time last year, as I'm currently in the same hole:

    "It's a catch 222222 situation.

    Every solution to a sticky problem assumes I have knowledge in one area. I google that, and all I find are solutions that assume I have knowledge of the very area I'm stuck with in the first place.

    Sometimes it's as simple as that, but often there are more steps along the way. I understand step 2, 3, 4, and 5, but step 6 assumes I already understand step 1. "

    Why the fuck is everything to do with coding so fucking obtuse? Why all the magic words? Why all the magic recipes? Where do I get the magic pills that suddenly make all of this make sense?
    Post edited by Luke Burrage on
  • That's what we always talk about. You have to understand every aspect of how a computer works from the bottom up. The magic pills are in my computer science degree.
  • I'm talking more specifically about coding tools, not the code itself.

    For example, I just downloaded Xcode to futz around with Swift for giggles. I entered my apple id, and I was immediately experimenting in a "Playground". It was utterly pain free. "Here, install this. Done. Now get to work."

    So I thought I'd try out an IDE for python. You know, for the fourth or fifth time. What a fucking pain in the ass. About two hours later and I've finally managed to open a single .py file.

    Now I've got to work out what an ant is.

    Or I'll go back to using a text editor.
Sign In or Register to comment.