Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 589 590 [591] 592 593 ... 796

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

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8850 on: January 24, 2016, 10:51:46 am »

No.  CollisionShape exampleTriangle = new CollisionTriangle();
The other way around will throw an exception.
And you can also declare them as the subclass and declare the storage thing as using the superclass.
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.

nullBolt

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8851 on: January 24, 2016, 10:54:53 am »

No.  CollisionShape exampleTriangle = new CollisionTriangle();
The other way around will throw an exception.
And you can also declare them as the subclass and declare the storage thing as using the superclass.

Of course. I'm retarded. :-[

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8852 on: January 24, 2016, 06:37:11 pm »

Problem is, at least in C# the standard way of solving it w/o the dynamic keyword won't let you use the Collided (Rect) / Collided (Circle) because the type of the variable is Shape, not rect or circle. Dynamic seems to let you cast your generic Shape to its final derived class before running function overloading?

My understanding is, if you do standard inheritence:

class CollisionShape  { public bool Collided(CollisionRectangle other);}
class CollisionCircle inherits CollisionShape {}
class CollisionRect inherits CollisionShape {}
///
CollisionShape var = new CollisionCircle();
CollisionShape var2 = new CollisionRectangle ();
var.Collided(var2); // error: couldn't find overloaded function with argument Shape
« Last Edit: January 24, 2016, 06:39:19 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

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8853 on: January 24, 2016, 09:05:57 pm »

Have the function just take a generic collider, and check the type inside via casting.

Rectangle rekt = input as rectangle
If(rekt!=null)
//do rectangle stuff
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8854 on: January 24, 2016, 10:01:54 pm »

Try casting it?
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.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8855 on: January 24, 2016, 11:29:52 pm »

Ah, so in this case the dynamic keyboard basically is casting automatically rather than manually.
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

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8856 on: January 24, 2016, 11:31:56 pm »

I don't into C++.  Excuse my ignorance.
I shall just be over here testing CollisionWallCorner.
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.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8857 on: January 24, 2016, 11:35:18 pm »

Cast will throw an exception if it can't be casted, while the as keyword will just set the result to null, so you can use it to check what type the input actually is, and work with that.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8858 on: January 24, 2016, 11:37:43 pm »

Yes, I didn't know the existence of the as keyword, but I think dynamic feels like a cleaner implementation.

Even if it's "dynamic", it immediately gets reassigned a type since it gets put into the CollisionImpl functions with the proper overload. If the proper CollisionImpl doesn't exist, it will throw a runtime exception but I think that is ok.

@Fish: this is actually C#!
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

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8859 on: January 24, 2016, 11:43:24 pm »

I'm not sure hot the dynamic keyword works, but I feel it would give you less control over the operations, which makes me not trust it.
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8860 on: January 25, 2016, 12:02:34 am »

@Fish: this is actually C#!
*facepalm*
It's Monday, blame it on that.
Retroactively.
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.

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #8861 on: January 25, 2016, 04:55:55 pm »

I'm learning Python 2.7.11 because we're doing networking next week.

I keep having to remind myself not to stick a semicolon at the end of each line.

Also, it seems weird to have a language where
Code: [Select]
foo = 25 / "egg"is perfectly valid.

Until you try to actually execute it, anyway.
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8862 on: January 25, 2016, 05:06:23 pm »

It's technically not valid, because it crashes when the code is executed.
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.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8863 on: January 25, 2016, 05:16:12 pm »

Yeah, by your definition that would be "valid" in any interpreted language.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8864 on: January 25, 2016, 06:04:22 pm »

unless you override the __div__() function for... whichever operand is relevant, i forget

or, in more recent python, __truediv__()
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.
Pages: 1 ... 589 590 [591] 592 593 ... 796