Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 241 242 [243] 244 245 ... 796

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

Wolfy

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3630 on: December 25, 2012, 02:58:50 am »

I've done it off and on for years, I've never been able to "use" what I know, I dont see how to use each thing as a group to make what I want.
Logged
I'm a bad speller, no amount of telling me how bad I am is going to make me better. People have been trying for over two decades. English is hard for me, its like how some cant get math, i cant get English.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #3631 on: December 25, 2012, 03:16:24 am »

In pseudocode (assuming string::find will return -1 if it doesn't find it):
*see note at bottom of post

do{
   int stringIndex = string::find(blahString);
   string::replace(stringChunk, stringIndex, wordLength, replaceString);
}while (stringIndex != -1;

Also going with the assumption that I didn't totally bork the pseudocode on that one hehe :D

*Note: I haven't used C++ in a while, mostly C# for me nowadays. Hopefully I didn't bork the code too much!
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3632 on: December 25, 2012, 08:10:14 am »

Slightly optimized:
Code: (Pseudocode) [Select]
for each pattern, replacement {
  newString = "";
  stringIndex = find(string, pattern);
  while (stringIndex != string.length) {
    newStringIndex = find(string, pattern, stringIndex+pattern.length);
    if (newStringIndex == -1) {
      newStringIndex = string.length;
    }
    newString.append(replacement);
    newString.append(string.substr(stringIndex + pattern.length, newStringIndex);
    stringIndex = newStringIndex;
  }
  string = newString;
}
« Last Edit: December 25, 2012, 09:48:55 am by MagmaMcFry »
Logged

Mego

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

string::find returns string::npos if the substring is not found. The standard is string::npos == -1, but certain compilers (cough cough Microsoft) have been known not to follow standards.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3634 on: December 30, 2012, 01:48:00 am »

Entire errors & command line input

Compiling on Linux using g++ 4.6.3.

I believe the error can be traced back to

Code: (PODS.h) [Select]
class statpairs
{
public: int current;
                  int max;
                  const string nameof;
                  TCODColor color;
                  statpairs(string name, TCODColor statcolor);
  void updatestats(int stat, int maxstat) {current = stat; max = maxstat;}
  };
Code: (PODS.cpp) [Select]
HUDisplay::statpairs::statpairs(string name, TCODColor statcolor) : nameof(name), color (statcolor)  {}
Code: (PODS.cpp) [Select]
void sideDisplay::update(SoilMap &map, Cursor &cursor)
{
  tile *tilepointer = 0;
  plants *tempplant = 0;
  herb *tempherb = 0;
 
  if (cursor.visible == true)
    {
    tempherb = map.herb_at_pointer(cursor.getX(), cursor.getY());
    if (tempherb != 0) //if it exists
      {
      string plantname; plantname.assign(tempherb->plantname.c_str());
            //test code start
      plantname.append("(");
      plantname.append(to_string((long double)tempherb->strength));
      plantname.append(",");
      plantname.append(to_string((long double)tempherb->plant_durability));
      plantname.append(")");
           //end test code

      infovector.push_back(pair<string, pair<TCODColor, TCODColor> >(plantname, pair<TCODColor,TCODColor>(tempherb->background, tempherb->foreground)));
      }

    tempplant = map.grass_at_pointer(cursor.getX(), cursor.getY());
    if (tempplant != 0)
      {
       
      string plantname; plantname.assign(tempplant->plantname.c_str());
      //testcode start
      plantname.push_back(' ');
      plantname.append(to_string((long double)tempplant->plant_durability));
      //testcode ends

      infovector.push_back(pair<string, pair<TCODColor, TCODColor> >(plantname, pair<TCODColor, TCODColor>(TCODColor::lerp(tempplant->background, TCODColor::black,0.5f), tempplant->foreground)));
      }   
   
>>>>>>    tilepointer = &map.tile_at(cursor.getX(), cursor.getY());
    infovector.push_back(pair<string, pair<TCODColor, TCODColor> >(tilepointer->getTileName(), pair<TCODColor, TCODColor>(TCODColor::lerp(tilepointer->foreground, TCODColor::black,0.5f), tilepointer->background)));
   
    }


}

Relevant errors:
PODS.h:48:9: error: ‘HUDisplay::statpairs& HUDisplay::statpairs::operator=(const HUDisplay::statpairs&)’ is implicitly deleted because the default definition would be ill-formed:

In member function ‘void sideDisplay::update(SoilMap&, Cursor&)’:
PODS.cpp:65:60: error: taking address of temporary [-fpermissive]
(this error's line is marked as >>>>>>)

I'm pretty sure there's a lot more errors, but it's too much gibberish to understand.

This code compiles fine on MSVC / windows. @_@
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

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3635 on: December 30, 2012, 02:02:13 am »

The problem would probably be in SoilMap::tile_at. Can you give us the code for that function?
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3636 on: December 30, 2012, 03:34:43 am »

I'm reading through the entire error output, and I'll make notes here as I see things.

Error with using TRUE - use true instead.

Taking address of temporary - g++ (and all standards-conforming compilers, for that matter) don't like when you take a reference to something that isn't an lvalue (a function call is an rvalue). So, store the result of the function call, and take reference of that.

Ill-formed default definition - your class doesn't have a default constructor (constructor with no arguments) that instantiates the const string nameof field. Your choices are to define the default constructor and initialize nameof, or to make nameof a static field.

Fixing these things should make the rest of the errors go away.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3637 on: December 30, 2012, 04:48:37 am »

I already caught the first error xD
Taking address of temporary : I don't quite understand what that means, probably because I can't understand "lvalue" and "rvalue" @_@ I think I can fix it by changing tile_at to tile_at_pointer, though, which is the second function I made to return an address. I made the tile_at function incorrectly, but there was some usages that relied on it being copied instead of an address.

Edit: now only if I could get Linux and Virtual Box to cooperate with each other.
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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3638 on: December 30, 2012, 10:16:34 am »

An lvalue is something that can have a value assigned to it. An rvalue is something that cannot have a value assigned to it. For example, variables are lvalues, while function calls are rvalues.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3639 on: December 30, 2012, 12:33:52 pm »

An lvalue is something that can have a value assigned to it. An rvalue is something that cannot have a value assigned to it. For example, variables are lvalues, while function calls are rvalues.

Yeeeah, about that...
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3640 on: December 30, 2012, 12:49:14 pm »

You can see those concepts whistling over my head. :( I still can't understand it.

Also, while linking, I have errors of '-l[libraryname] not found' despite the files being along the path I added with -L/home/skyrunner/Desktop/ASCII\ sandbox/Resources/libtcod-1.5.1"... The files' names are 'libtcod.so' and 'libtcodgui.so' which are included by -llibtcod and -llibtcodgui. Am I doing wrong? The .so files aren't in the standard path, which might be a problem...?

By the way, is letting programs use shared objects in Linux hard? Do they just have to be where the executable is, or do they need an arcane method to add tem to the system's info? If they have to be magicked into the system, does -static while compiling let the sos be forcibly statically linked?
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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3641 on: December 30, 2012, 01:12:50 pm »

An lvalue is something that can have a value assigned to it. An rvalue is something that cannot have a value assigned to it. For example, variables are lvalues, while function calls are rvalues.

Yeeeah, about that...

Damnit. Every time I think I have C++ semantics figured out, something else pops up.

Skyrunner, basically, if you want to make a pointer to an object that is the result of a function call, store the return value somewhere first, and take the reference to that. If you have a const field in a class, either define a default constructor that initializes it, or make it static.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3642 on: December 30, 2012, 01:18:44 pm »

Damnit. Every time I think I have C++ semantics figured out, something else pops up.

They're introduced by C++11 and basically exist so you can explicitly break those rvalue rules and make it clear you're doing it. auto_ptr had to do some hideous tricks, which introduced some problems. unique_ptr can achieve the same goal without those hacks via the move semantics rvalue references introduced.
« Last Edit: December 30, 2012, 01:25:39 pm by MorleyDev »
Logged

darklord92

  • Bay Watcher
  • [CREATURE:SERGALNORTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3643 on: January 10, 2013, 12:42:20 pm »

I see to be having my own short comings as well learning nes/6502 asm 

I'm following pataters guide to it using nesasm3

(( http://www.patater.com/nes-asm-tutorials/day-9  and http://www.patater.com/nes-asm-tutorials/day-10  for refrence))

I seem to be unable to set the x and y of sprites as well as having more than one sprite when i do the steps in part 10 to load sprites into the DMA

code so far:
Spoiler (click to show/hide)
Logged
Form walking potato man out of corpse. Absorb anyone else in the house.
We have a successful derail.
The Vilous Mod - Jingle berries!

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3644 on: January 10, 2013, 05:54:55 pm »

First of all, why are you going right/up twice as fast as left/down?


Other than that I can't find any obvious errors. Can you describe what's happening? Do you have a debugger to step through the code?
« Last Edit: January 10, 2013, 05:56:42 pm by Virex »
Logged
Pages: 1 ... 241 242 [243] 244 245 ... 796