Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 10 11 [12] 13

Author Topic: Party House Experiment > Development on Pause  (Read 18509 times)

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #165 on: June 23, 2010, 04:10:25 pm »

Ooh, I hadn't thought of that!

I'll have it cout things to a text file since I can't get the console window to display text.


This is going to be really premature,
 but I've been working on some of the resources for my next project.

I'm happy with how they are turning out, and once I have a good example images, I'll start that new thread.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #166 on: June 23, 2010, 04:45:09 pm »

It's because you make a pointer to a variable that was declared in the function, I think. And you can't use str1.c_str() as a real pointer, you'll have to copy the data to some piece of reserved memory.
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))

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #167 on: June 23, 2010, 05:37:21 pm »

i suggest using std::string globalmessage. Thats the simplest way, if not you need: first check if globalmessage_* ==0 if not delete [] it, alloc enough space for message (prob new char[string.size()]) then strcpy(globalmessage_*,string.c_str())... That's too much trouble if you ask me...

EDIT:Oh wait you don't need to alloc/delete it everytime. You can set char globalmessage_dist[256] and use strcpy into it (just be carefull not to make a longer then 256 string)
« Last Edit: June 23, 2010, 05:38:59 pm by darius »
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #168 on: June 24, 2010, 01:00:12 am »

void special::setmessage_float(int messagesort,float displayfloat){
    int displayint = displayfloat;
    std::stringstream sstr;
    sstr << displayint;
    std::string str1 = sstr.str();
    switch(messagesort){
        case 1:     globalmessage_dist  = new string(str1.c_str()); break;
        case 2:     globalmessage_x     = new string(str1.c_str()); break;
        case 3:     globalmessage_y     = new string(str1.c_str()); break;
        default: break;
    }
}
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #169 on: June 24, 2010, 03:18:12 am »

What alfie said...
But you still need to delete() the old value before assigning it a new() one. And don't forget to initialise the pointers with 0 :)
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))

Alexhans

  • Bay Watcher
  • This is toodamn shortto write something meaningful
    • View Profile
    • Osteopatia y Neurotonia
Re: Party House Experiment > Hiatus
« Reply #170 on: June 24, 2010, 06:40:35 am »

Came in to say hi. 

Between exam madness, work madness, life madness + World cup madness (witch is a great madness) :P  I haven't done almost anything programming wise for myself.

Once the madness stops, I intend to go back to it.

See ya.
Logged
“Eight years was awesome and I was famous and I was powerful" - George W. Bush.

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #171 on: June 24, 2010, 08:00:45 am »

Guys, why does it make a difference?

I already have those three values global so that they may be changed
 from multiple places in the code without hassle.

Maybe I should define their size somehow?

I don't really want to leave it up to myself to delete things properly.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #172 on: June 24, 2010, 08:15:18 am »

Then don't use a pointer-to-char-array but a std::string? That takes care of your memory management.
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))

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #173 on: June 24, 2010, 08:16:46 am »

The library function I what prints text to the screen only likes const char pointer deallies.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Party House Experiment > Hiatus
« Reply #174 on: June 24, 2010, 10:28:01 am »

std::string.c_str() returns a constant char pointer.  Just use std::string's to store the messages, and convert them to const char* with .c_str() when you need to output them.
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #175 on: June 24, 2010, 12:31:50 pm »

The best (IMNSHO) way is:
somewhere above:
Code: [Select]
std::string  globalmessage_dist , globalmessage_x, globalmessage_y;
then
Code: [Select]
void special::setmessage_float(int messagesort,float displayfloat){
    std::stringstream sstr;
    sstr << (int)displayfloat;
    switch(messagesort){
        case 1:     globalmessage_dist  =  sstr.str(); break; //no need for pointers, temporary strings and etc- autocopy!
        case 2:     globalmessage_x     =  sstr.str(); break;
        case 3:     globalmessage_y     =  sstr.str(); break;
        default: break;
    }
}
using them:
Code: [Select]
print_with_c_style_function(globalmessage_dist.c_str());
making a function that accepts strings:
Code: [Select]
void print_cpp_style(std::string const &r) //or not const if you want to change it...
{
//do sth
}
making a function that accepts string c style
Code: [Select]
void print_c_style(char const *r)
{
//do sth
}
and so on...
« Last Edit: June 24, 2010, 12:34:33 pm by darius »
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #176 on: June 24, 2010, 04:21:48 pm »

Thanks everyone, I actually thought up Timmeh's suggestion earlier today.

When I get around to it I'll implement that.

I hate const char *'s.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Party House Experiment > Hiatus
« Reply #177 on: June 24, 2010, 04:53:39 pm »

Doesn't const just prevent it from being modified by the function, so you can pass a regular char* to a function that has a const char* as it's paramater?
Logged
Eh?
Eh!

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #178 on: June 24, 2010, 07:02:58 pm »

That honestly makes a lot of sense.
I don't understand why a const int would work for this anyways,
 but it seems to.

If I could not use const's to this goal, I would avoid them.
I usually will only use consts for init stuff.

EDIT:

It works!
I have overcome this bug.
The scary part is that the bug was a part of a system
 designed to debug the more complex code.

I suppose I'll check that off of my list.
« Last Edit: June 24, 2010, 07:19:20 pm by Outcast Orange »
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #179 on: June 24, 2010, 11:40:09 pm »

Okay, here is some more buggy code:
Code: [Select]
if( ax>bx ){

     if( ay>by ){ 
          if( Px<=ax && Px>=bx && Py<=by && Py>=ay ){go = true;}
     }else{     
          if( Px<=ax && Px>=bx && Py<=ay && Py>=by ){go = true;} }

}else{

     if( ay>by ){ 
          if( Px<=bx && Px>=ax && Py<=by && Py>=ay ){go = true;}
     }else{     
          if( Px<=bx && Px>=ax && Py<=ay && Py>=by ){go = true;} }

}

I want bool go to be true if point (Px,Py) is in rectangle (ax,ay) (bx,by) .

I'm having trouble reading the code when it is like this.

Does it look right?

EDIT:

Oh, I had the y values backwards.
I switched everything around and it works great!

This is going to be a slow progressing project,
 but I've nearly finished the first crucial system of it.
« Last Edit: June 24, 2010, 11:45:06 pm by Outcast Orange »
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream
Pages: 1 ... 10 11 [12] 13