Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 185 186 [187] 188 189 ... 796

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

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2790 on: August 18, 2012, 04:12:15 am »

Is there an easy way to output a value to a character string of string type? Or vector type.
Easy, I am going to refrain from using the C way and just show you the c++ way.

In the <string> header, there is a overloaded method called std::to_string(value).
This will convert most values to strings. But remember there is a extra conversion involved if you are converting chars or shorts to strings. So, as long as you are not doing 5 billion number to string conversions, it should suffice.

Edit:
This is actually a C++11 feature, I had no idea..
If you are using an older version of the language, the c way of converting numbers is also pretty simple:

Code: [Select]
char buffer[25];
sprintf(buffer, "%[FormatCharacter]", numberToConvert);
string output(buffer);
« Last Edit: August 18, 2012, 04:18:07 am by malloc »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2791 on: August 18, 2012, 10:33:27 am »

No, if you cast it it becomes wacky.

Code: [Select]
int (-237) -> SUDDEN WEIRD STUFF if you cast it to a char.
int (48) -> char (0)

And itoa() seems to have the same problem as sprinf() does: it needs an array of characters, not a string or vector. And arrays of characters always seem to invite out of bounds errors D:

I might be doing it wrong, though. Perhaps I need an iterator where it wants a char * str argument?

Are you looking to transform -237 (int) to '-237' (char*)? If so, there's an easy way to do it using stringstreams.

Code: [Select]
#include <sstream>

using namespace std;

char* int_to_cstring(int a) {
    stringstream sstr;
    sstr << a;
    return sstr.str().c_str(); // std::stringstream::str() returns the contents of the stringstream as a std::string. std::string::c_str() returns the contents of the string as a C-style string (char*).
}

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2792 on: August 18, 2012, 11:23:53 am »

@Elu: I am using java, as much as people like to hate on it, its only major flaw is the size of its memory footprint and it doesn't really matter if I use an extra 200mb for the vm on my 16gb machine.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2793 on: August 18, 2012, 02:27:25 pm »

There's something cathartic about writing one giant Go Game god class and then slowly refactoring it out into a bunch of interfaces...

Maybe I'm just insane xD
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2794 on: August 18, 2012, 02:36:14 pm »

Maybe I'm just insane xD

Look at the title of the thread. Then back at yourself. Then back at the title. Then back at yourself.

You are most definitely insane.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2795 on: August 18, 2012, 02:51:00 pm »

Look at the title of the thread. Then back at yourself. Then back at the title. Then back at yourself.

Look down, back up. Where are you? You're in the office with a bloated piece of legacy code written in Java. What's that your compiling? Back at me. It's a language that refuses to evolve. Look again, the language is now C#! Anything is possible when your coders are willing to adapt and change with the times.

I'm on a Laptop.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2796 on: August 18, 2012, 02:56:02 pm »

Look at the title of the thread. Then back at yourself. Then back at the title. Then back at yourself.

Look down, back up. Where are you? You're in the office with a bloated piece of legacy code written in Java. What's that your compiling? Back at me. It's a language that refuses to evolve. Look again, the language is now C#! Anything is possible when your coders are willing to adapt and change with the times.

I'm on a Laptop.

I am not your programmer. I am the programmer your programmer could program like.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2797 on: August 18, 2012, 03:37:02 pm »

Shit....

Trying out some crap. the eCobertura plugin for eclipse is behaving oddly. It is highlighting some of the files it covers, but not all of them. I have 1 file with 92.77% coverage and i can't figure out what isn't being tested.

Fucking awesome... It only highlights files that were created before the last time eclipse was opened. This is not a documented "feature"

Edit: Oh. and yay eCobertura also reports 100% line coverage with less than 100% branch coverage. It does not count switch case fall through as branch coverage. Even accounting for that and making sure I don't have some late && conditions never being hit, I have a file with 8 branches unaccounted for in a file with 100% coverage.

Cobertura was one of the best code coverage tools available for java through ant/maven, but the eclipse plugin is hacked bullshit that barely works.
« Last Edit: August 18, 2012, 10:14:33 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2798 on: August 20, 2012, 04:07:32 pm »

I got completely distracted from my building generator when I ran into a problem where flat text property files would be annoying to deal with in creating material/form/usage trees.

So I said what the heck, I can write that shit in MNML, and then I spent the whole weekend converting that project to java, writing junit tests and java docs. And now I realize I have a recursion issue on the program side if you a do something crazy, like putting a container inside itself. Fortunately that does not affect reading MNML documents... so I might be able to convince my self to ignore it for now.

It doesn't matter what i try to code, outside of actual paid work, I can't seem to ever finish anything.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2799 on: August 20, 2012, 05:14:57 pm »

It doesn't matter what i try to code, outside of actual paid work, I can't seem to ever finish anything.
Welcome to the club.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

etgfrog

  • Bay Watcher
  • delete & NULL;
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2800 on: August 20, 2012, 05:56:29 pm »

so i figured i'd post here...i'm currently trying to make a game, having some problems trying to do some testing on other computers since i'm writing it in python, now most guides and books i've read about programing has suggested to write it in python 2.7, but i noticed python 3.2 runs twice as fast so i go code it in that, problem i'm running into is every single script that will binary freeze...works with python 2.7, almost every single source of making a standalone is for python 2.7, so i'm questioning what i should do at this point, i could always cross that bridge when i get farther in it but its one of those problems that will annoy me untill it is fixed...
Logged
"How dare you get angry after being scammed."

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2801 on: August 20, 2012, 05:59:56 pm »

It doesn't matter what i try to code, outside of actual paid work, I can't seem to ever finish anything.
Welcome to the club.
If you really want to finish something, promise yourself at the start that if you don't finish it, you will donate $100 to a Koch Bros SuperPAC. :P
Logged

Fenrir

  • Bay Watcher
  • The Monstrous Wolf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2802 on: August 20, 2012, 06:02:29 pm »

It doesn't matter what i try to code, outside of actual paid work, I can't seem to ever finish anything.
Welcome to the club.
If you really want to finish something, promise yourself at the start that if you don't finish it, you will donate $100 to a Koch Bros SuperPAC. :P
If one were that trustworthy, one could just promise oneself to finish.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2803 on: August 20, 2012, 06:56:17 pm »

So that charity thing I was planning isn't going to happen. Maybe another time.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2804 on: August 20, 2012, 08:46:08 pm »

Thanks, Mego, to_string worked perfectly :3 Much better than having to write my own function that carefully dissects ints into vector output.
« Last Edit: August 20, 2012, 09:06:52 pm by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward
Pages: 1 ... 185 186 [187] 188 189 ... 796