Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 670 671 [672] 673 674 ... 796

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

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10065 on: September 29, 2016, 07:31:07 pm »

In other news, apparently Aptana Studio 3.6.1 is suffering from installer buggery where you need to install things before you install things.  This is not fun.

There's always a thing you need to install before the thing.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10066 on: September 29, 2016, 07:36:12 pm »

Not when it's supposed to be included by default...

In other news, can somebody explain to me how the carp reflection (in C#, preferably) works?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10067 on: September 29, 2016, 07:41:35 pm »

https://msdn.microsoft.com/en-us/library/mt656691.aspx

Well, what exactly are you trying to do with reflection? Just getting the type of an object via reflection is simple. To be able to use GetType for your own classes, you need to inherit them from Object / System.Object

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10068 on: September 29, 2016, 08:13:52 pm »

Getting the type, and then calling a class-specific method based on that type.

And yes, everything is inheriting from Object.
« Last Edit: September 29, 2016, 08:19:31 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10069 on: October 03, 2016, 12:43:32 pm »

Working on a program for a college assignment. Part of the program is code written by my professor, and the program is expected to use this code. It uses an overloaded operator<<. I've never tried overloading a stream operator and I'm not sure why the program is crashing at the statement:

Code: [Select]
cout<<"List A: "<<listA<<endl;
I cannot change the code for this statement without losing points.

Taking endl out of the statement causes the program to work fine.

Spoiler: overloaded operator<< (click to show/hide)
Spoiler: List::display() (click to show/hide)

Help please? I'm sure it's endl messing everything up but I'm not sure how it's messing things up or how I'm to fix it.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10070 on: October 03, 2016, 12:52:08 pm »

Well i can identify two issues

- That operator method has a return type specified (non-void) but you're not returning anything. What compiler are you using? Visual Studio would have spat an error out on that.

This is what a normal ostream overload looks like (taken from MSDN)

Code: [Select]
ostream& operator<<(ostream& os, const Date& dt)
{
    os << dt.mo << '/' << dt.da << '/' << dt.yr;
    return os;
}

Just add the return line into the operator, that should fix it. How this operator works is it grabs the stream, adds your data, then returns the stream so that the next chunk can be added. You're adding your own chunk but then not passing the stream along so that the next chunk has a place to go.

The other issue is more about redundancy in your list function

Code: [Select]
while(addr!=nullptr)
{
if(addr!=nullptr)
out<<addr->get()<<" ";
addr=addr->getNext();
}

Basically, the line while(addr!=nullptr) ensures that addr can never be null at the top of the loop, hence you don't need the if statement - the while is already doing the exact same check immediately before the if check happens. You'd only need the if-statement if something changed in the middle of the while loop that could cause addr to be null but you're still doing something with it.
« Last Edit: October 03, 2016, 01:20:36 pm by Reelya »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10071 on: October 03, 2016, 01:37:25 pm »

Oh. I didn't even notice I wasn't returning anything in the overloaded stream operator. Adding "return out;" fixed that. Thanks Reelya.

The compiler I'm using is TDM GCC 4.9.2, and the IDE is Orwell Dev C++. I'd prefer to use Code::Blocks over Orwell but the college computers are set up with Orwell. So I figured it's best to make sure everything should compile and look good when he's grading by using the same compiler, formatting settings, and IDE as what I'd use in the class and what he uses to grade.

I've considered trying Visual Studio but it never seems to want to finish installing on my computer and I really don't feel like learning yet another IDE.

That redundant bit of code was added when I was searching for why the program initially crashed, and I added the redundant if statement thinking that the crash was somehow caused by trying to dereference a null pointer, and never got around to removing the if statement once I found out the issue was with the overloaded operator, not the display method.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Gamerlord

  • Bay Watcher
  • Novice GM
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10072 on: October 04, 2016, 05:37:57 am »

*finds way back to Bay12 in ragefit*
Okay, maybe you guys can help me! I'm trying to install Visual Studio Express, but it won't install. It keeps getting stuck on KB2999226, and the only fix online I can find for that is to go here and download the appropriate package. I grabbed the Windows 7 x64 one, but when I go to install that it just says 'The update is not applicable to your computer'. Can someone help me unscramble this shitshow before I once again lose all motivation to learn c++?

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10073 on: October 04, 2016, 06:30:19 am »

Well for KB2999226 you need Windows 7 Service Pack 1 installed first, but I assume you already have that.

But you could always install Visual Studio Community instead of Express, I've never heard of that problem before, and have been using that on Windows 7 without any problems.

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10074 on: October 04, 2016, 08:28:44 am »

If you're just getting into C++, I wouldn't reccomend using Visual Studio. It's incredibly powerful but a bit overwhelming to install and use for newbies like us. I've been programming for a few months and haven't attempted to use it. Might I recommend Orwell Dev-C++ or Code::Blocks if Visual Studio proves too frustrating for you?

Alternatively, you could learn in online compilers like repl.it and see if you like C++ before bothering to set up a programming environment.
« Last Edit: October 04, 2016, 08:31:17 am by DragonDePlatino »
Logged

Gamerlord

  • Bay Watcher
  • Novice GM
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10075 on: October 04, 2016, 08:54:26 am »

I found a decent, extensive set of tutorials, but they require Visual Windows.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10076 on: October 04, 2016, 11:06:57 am »

Get Visual Studio Community, yeah.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Sergius

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10077 on: October 04, 2016, 12:13:44 pm »

As an experiment, I want to reproduce the "line-of-sight" algorithm from Ultima 5 and 6 (which, unlike the previous two Ultimas, didn't use a "raycasting" technique but what appears to be normal pathfinding).

I am thinking I should start from the center, then just trace a path until every single reachable tile within a radius (11 x 11 tiles, maybe slightly more) is mapped out. To avoid doing this multiple times along the same path, should I use some sort of recursive function that branches, for example for each of the 4 (or 8 if doing it diagonally as well) directions from the center? Any opinions? I don't want to overdo it with premature optimization but I thought I'd start with whatever method should give me the fastest algorithm.

I plan on using GameMaker Pro, tho I haven't yet bothered to even look at how the scripting language looks like, but the question should be general enough that it can be done whether C++, java or something, right?

For anyone who wonders, in U5 you could see to any point unless it was completely sealed off (within the 11x11 tile viewport. Assume the edges are walls), that includes around corners, any room with a window that you could see, etc.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10078 on: October 04, 2016, 12:18:16 pm »

As an experiment, I want to reproduce the "line-of-sight" algorithm from Ultima 5 and 6 (which, unlike the previous two Ultimas, didn't use a "raycasting" technique but what appears to be normal pathfinding).

I am thinking I should start from the center, then just trace a path until every single reachable tile within a radius (11 x 11 tiles, maybe slightly more) is mapped out.

I think that would just be Dijsktra's algorithm.

Sergius

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10079 on: October 04, 2016, 12:56:49 pm »

I think that would just be Dijsktra's algorithm.

If it can be adjusted to just find all paths regardless of route length or weight, I would definitely go with this one or equivalent.

The way I'm thinking it, is to have a Master grid (with the whole unobscured 11x11 view) and a visibility grid that starts at FALSE or whatever in each point, except the center, it traverses each point, marking it as TRUE then branching off to all non-revealed (false) points adjacent to it (unless it's a visual obstacle, then it stops after setting it to TRUE, and doesn't keep looking). If this can be done iteratively rather than recursively, even better, maybe have an array/list of "seekers" of some kind that mark where stuff has branched off.

EDIT: Seems to me that the first part of Dijsktra is what I'm looking for, while the final "shortest route" part can just be skipped. The "seekers" are just the tentative nodes...

EDIT2: Furthermore, it seems there's no need to explore nodes in any order, like the algorithm does (by distance), so I can just iterate over every tentative node in just the array order.

MOAREDIT: Seems like what I described is just a bog-standard 8-direction flood-fill method. Maybe using a stack of some sort. Which isn't too different from a pathfinding algorithm... I'm definitely on the right track.

Thanks for the help!
« Last Edit: October 04, 2016, 01:36:34 pm by Sergius »
Logged
Pages: 1 ... 670 671 [672] 673 674 ... 796