Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 564 565 [566] 567 568 ... 796

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

Magnumcannon

  • Bay Watcher
  • Deep waters don't run still
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8475 on: November 23, 2015, 03:43:06 pm »

Alright, now i'm trying to use curses on python 2.7. I downloaded UniCurses and i put the pdcurses.dll file in the same folder (site-packages) as unicurses.py. It's not working, for some reason, and everytime i try to import unicurses, i get this:
Spoiler (click to show/hide)
I have no idea what's going on. I tried putting the .dll on the DLLs folder, but it didn't work either.
EDIT: I also found that i could install it with .whl ...but it says it does not support Unicode characters. And i want my ASCII characters  >:(
You need to have the pdcurses dll and py in the some folder as the project, or in the Python directory (I think? Maybe not), or somewhere else but pointed to in the Path environment variable.
I could get it working by putting the .dll in the folders i work on, but i couldn't get it working by pointing to it in the environment variables. At least that's something  :D
Logged

Lightningfalcon

  • Bay Watcher
  • Target locked. Firing main cannon.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8476 on: November 24, 2015, 04:56:06 am »

So I have an array of Object pointers, which can be one of two different classes derived from Object. Object has a virtual function, intersect, which in Object has no parameters, but in both the derived classes have the same parameters, just different implementations. I want to be able to go down the array, calling intersect each time without having to worry about checking which class it is.
 Problem is that whenever I try to call the intersect function I get "No matching function for call", and it says that it expects 0 arguments instead of the 4 in the derived classes. I try to make it into a pure virtual function in the base, but since I can't have an array of pointers to an abstract class, that doesn't work. I look it up on Stack overflow and the only thing that I can get results on is name hiding, but that seems to come from people trying to use the method in the base class. Still tried the recommended solution of inserting "using base: method", but that doesn't do anything, again.

 Basic structure is-
class Object
{
    public:
    virtual int intersect() {};
}
class thing: public Object
{
   public:
   int intersect(double, double, double, double)
}
class thing2: public Object
{
   public:
   int intersect(double, double, double, double)
}

obj = new Object*[numObj]
tempThing = new thing();
obj[0] = tempThing;
obj[0]->intersect(double, double, double, double);
Logged
Interdum feror cupidine partium magnarum circo vincendarum
W-we just... wanted our...
Actually most of the people here explicitly wanted chaos and tragedy. So. Uh.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8477 on: November 24, 2015, 05:53:34 am »

The problem is that the Object class doesn't have the parameters included in the intersect function. C++ allows name overloading, as long as the parameters can be determined. C++ does this by generating an internal "name" that adds info about the parameters to the normal name, so "intersect, which takes zero parameters" is not understood to be connected in any way to "intersect, which takes four doubles".  Another way to look at it is that the parent is the interface you're using, and that interface does not specify four doubles as allowed parameters for "intersect".

Your existing "thing" class therefore has two completely unconnected "intersect" functions:

tempThing->intersect(); // this calls the one from "Object"
tempThing->intersect(1,2,3,4);  // this calls the one from "thing"

So you just need the parameters to match and it will know what want.

Another trick is "pure virtual" functions. You replace the {} in the parent with = 0. What this does is it omits the base-classes function body. Any class with an empty function body cannot be created, so you can't create the base class (often what you want) and it will give a compiler error if you make a derived class from "Object" but forget to add it's own "intersect" function, which is a very helpful reminder.

class Object
{
    public:
    virtual int intersect(double, double, double, double) = 0;
}
« Last Edit: November 24, 2015, 06:25:36 am by Reelya »
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8478 on: November 24, 2015, 08:05:04 am »

*snip*

Yeah, like Reelya said.

intersect() != intersect(double, double, double, double)

As far as the complier is concerned, the only things they have in common is that they are both functions.
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Magnumcannon

  • Bay Watcher
  • Deep waters don't run still
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8479 on: November 24, 2015, 07:57:26 pm »

In java, you have the System.out.print, which would print stuff in the same line. Is there something similar in python? I want part of the print to only be print if a certain condition is met. And that in a single line.

EDIT: After a not-so-long search, i found out that i could simply add a ',' to the end.
« Last Edit: November 24, 2015, 08:25:50 pm by Magnumcannon »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8480 on: November 24, 2015, 08:11:48 pm »

I thought I was dealing with looping.


It turned out that I was recursing to the main method through the empty constructor of an object I had coded.


I have no idea what possessed me to write that.


Well, at least I've solved it!  Maybe!
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.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8481 on: November 24, 2015, 08:39:27 pm »

In java, you have the System.out.print, which would print stuff in the same line. Is there something similar in python? I want part of the print to only be print if a certain condition is met. And that in a single line.

EDIT: After a not-so-long search, i found out that i could simply add a ',' to the end.
You can also use the end argument to replace the default new line, like so:
Code: [Select]
print (x, end="whatever")
This is useful where you want multiple print statements.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8482 on: November 25, 2015, 05:38:31 pm »

Hey guys have you run into this bug?

Spoiler (click to show/hide)
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8483 on: November 25, 2015, 05:58:51 pm »

Hey guys have you run into this bug?

Spoiler (click to show/hide)
A happy compile-time error to you too!
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8484 on: November 25, 2015, 06:10:12 pm »

Hey guys have you run into this bug?

Spoiler (click to show/hide)
It's probably the smiley. IDEs tend not to like those. You can get rid of them by using [code] or [nobbc] tags. :D

On a related note, I wasted a bunch of time a week ago trying to figure out what was wrong with some code I copy-pasted from the instructor. Turns out the -'s were actually the extended ASCII character "soft hyphen", changing every n-1 into n1 for Visual Studio, but not in Notepad++ (which I saved it and fixed the indenting with.) I did a search and replace AD → 2D using Notepad++'s hex-editor plugin, and that fixed it.
« Last Edit: November 25, 2015, 06:14:57 pm by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8485 on: November 25, 2015, 06:22:58 pm »

On a related note, I wasted a bunch of time a week ago trying to figure out what was wrong with some code I copy-pasted from the instructor. Turns out the -'s were actually the extended ASCII character "soft hyphen", changing every n-1 into n1 for Visual Studio, but not in Notepad++ (which I saved it and fixed the indenting with.) I did a search and replace AD → 2D using Notepad++'s hex-editor plugin, and that fixed it.
i know your pain

smart quotes are a special kind of hell if you don't know what they are
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8486 on: November 26, 2015, 12:07:46 am »

Smart quotes... oh, how I'd forgotten about those.

We had incessant problems with those in our ticket tracking software.  It would take incoming emails and convert them into HTML, complete with lots of gibberish everywhere there was a " or ' character.  It took us ages to figure out exactly how to reprocess those into the simple character and not madness inserted by Outlook from the user's clients.
Logged
Through pain, I find wisdom.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8487 on: November 26, 2015, 12:10:33 am »

Smart quotes are basically Satan.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8488 on: November 26, 2015, 12:45:52 am »

Didn't think a basic string could do that if I typed in a :D

Attempting to fix it..
...

Ran it in my Visual studios compiler an it checks out.

Do compilers matter or am i just not able to replicate this for another reason?

EDIT: It's 12:46 and i'm discussing something so trivial. Magma how'd you copy that?
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8489 on: November 26, 2015, 02:19:48 am »

You wrote "end", not "endl". That's the compile-time error I get when I run it through cpp.sh.
Logged
Pages: 1 ... 564 565 [566] 567 568 ... 796