Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 55 56 [57] 58 59 ... 796

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

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #840 on: January 24, 2012, 09:53:32 am »

Max, I love your lessons, by the way. Just wanted to say that.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #841 on: January 24, 2012, 11:38:00 am »

Something I was entertained by today:

http://www.youtube.com/watch?v=EzzLzUCRmBw&feature=player_embedded

This is an interpreter for the programming language brainfuck.  The entertaining bit?  It was written in spacechem, the space chemistry video game by Zachtronics Industries.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #842 on: January 24, 2012, 12:18:02 pm »

Brianfuck? Please, it's all about SNUSP nowadays ^^ (Pretty cool nonetheless =P).
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #843 on: January 24, 2012, 03:16:34 pm »

Unless your code has changed a lot from the version you put online, it looks like it's working like it should other to RemoveMob not working.

I finally did get the currentHP reduction thing fixed, when I noticed the debugging numbers acting weird.  Apparently, it was just a problem with the if/else stack of attack/dodge/DAM/BLK - even though they're supposed to work fine with one-line following statements, I added clarifying brackets and now the HP works fine for everyone.  But it still doesn't remove the target.  I tried changing the removal clause:

Code: [Select]
if (target is MobObject)
{
mobList.Remove( (target as MobObject) );
}

But that doesn't work either.  I'm starting to think I'll have to have to give Mobs a method to delete themselves, checked against their currentHP each turn.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #844 on: January 24, 2012, 03:22:14 pm »

Wouldn't it only need to check against their current hp when they take damage? Not every turn.
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #845 on: January 24, 2012, 05:43:01 pm »

Code: (Buncha bullshit code that didn't do anything.) [Select]
bluh bluh bluh

Why does the referenced Mob not delete itself?  What am I not doing here to make a reference object remove itself from a List it has access to?  I've tried making the MobObject's value for the map Protected and Public as well as Private, does nothing; tried making outside methods to removed the referenced Mob, does nothing.  There is something I don't know that will fix this.

See my next post for the retarded followup.
« Last Edit: January 24, 2012, 05:59:15 pm by Aqizzar »
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #846 on: January 24, 2012, 05:50:00 pm »

Are you iterating through the list using an iterator or foreach loop? In that case you are not allowed to remove an item from the list in c#, but it should throw an exception.

Hmmm... Looking at your code... the RemoveSelf() does not appear to be in the MobObject class. In that case removing "this" won't work. But I think that is an editing issue.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #847 on: January 24, 2012, 05:58:21 pm »

Hmmm... Looking at your code... the RemoveSelf() does not appear to be in the MobObject class. In that case removing "this" won't work. But I think that is an editing issue.

Yeah, that's a new thing I just added.  And there is no iterator of foreach loop, because it's basically such that, the MeleeAttack Method is called, wherein the Player is the attacker, and the mob at a location is the target (and I've tested it with one mob in existence, so there's no confusion).  If it hits the part of the attack logic that removes HP...

Oh Jesus Christ, I think I just figured it out.  Or rather, I figured out why the Removal wasn't being called, because I didn't have a reference for it in the spot that the Mob would reach because of how I fudged some attack math.

Okay, now the RemoveSelf is being called, and it threw an Exception.  So I reverted back to my MapObject's location-based RemoveMob and everything works peachy keen now.

Holy fuck.  Well, that was two days wasted that I didn't need to waste.  Sorry folks, my bad.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #848 on: January 24, 2012, 06:00:32 pm »

One of us. One of us. One of us.
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #849 on: January 24, 2012, 06:27:32 pm »

I figured out my trajectory problem, and wrote a pretty nifty piece of code for finding trajectory in the future.

Spoiler (click to show/hide)

What do you think?
and I figured out height*2 is the same as ((distance/2)*(distance/2))*a

edited to update code to include option to run again, so I didn't have to keep running it over and over.

and also, how do you guys feel about single line simple if else statements?  do you ever use them?
like the almost last line of the code i pasted,

if (yesno == 'y' || yesno == 'Y')
    again = 1
else
    again = 0

is the same thing as

again=(yesno == 'y' || yesno == 'Y')?1:0;
« Last Edit: January 24, 2012, 07:16:00 pm by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #850 on: January 24, 2012, 07:56:37 pm »

Lesson time, gather round, were gonna learn all about static, and why you should never, ever use it. Because it is like terrorists, I don't need to explain why it is evil, it just is.

Now, let's say we wanted a program to do our physics homework for us, because we don't need no education.
Spoiler (click to show/hide)
Run that, try it out. Enjoy being able to solve the simplest physics equation I could think of at the time.
But it seems a bit strange, doesn't it? Why would we need to make a new instance 'physics' when no two instances will ever be different. Wouldn't it be nice to just have one set of physics that we can access?
Well we can, by making it static! Let's start by making the method static.

Spoiler (click to show/hide)
Bam, that easy. We now have a static method that can be invoked without dealing with making new objects. But red lines are showing up when we try to invoke it in our main. This is because the method no longer really belongs to the objects you make, but rather the class, so you can't invoke it is object.StaticMethod(), instead you need to use Class.StaticMethod() as so!
Spoiler (click to show/hide)
Now there is no reason at all to have to make a new type of physics... But we can. It is an empty little object with no use at all, but we can still make one, and that is bad. We know we can make a class unconstructable with the 'abstract' keyword, but that is for when you want things to extend it. Instead, let's use our 'static' keyword again.

Spoiler (click to show/hide)
Bam, the class is static, and we can no longer make an instance of it.
Hopefully some of this seems natural to you, as you would have used static methods before by this point. 'Console', for example, is a static class, and when you call it's methods you are calling static methods. You don't need to declare a new instance of Console, you can just use it any place and any time.
The thing to remember is that when you make a static class, all attributes and methods in it must be static, but when you have a non-static class you can still have static methods/fields, you just have to pretend the class is static while using it.

Now remember how I told you that static was frowned upon? There are several reasons for this.
Firstly, is makes your program more closed to extensions. Let's say you decide that your 'map' class should be static, because your player will only ever see one map, but then later on down the track you change your mind and decide there should be several maps you can visit. Because you used static, you need to go through all this needless bullshit of clearing out your map class! Go play Terraria, and when it says 'Resetting Game Objects' on the loading screen, that is what it is doing. You are waiting because somebody made something static and shouldn't have. Think very carefully, 'is it ever even possible in any way that there might be two different versions of this thing ever?' and if the answer is yes, then don't make it static.
Secondly, static classes are loaded when your program starts, meaning long waiting times just to get to the options screen. Go play the sims, notice how you need to wait fifteen minutes to load an options screen, but thirty seconds to load a house? It is bullshit, when the only reason I have this game open is because of a misclick, I wanted SimCity! Static classes also remove your power to instantiate them with data from the first tick. If you had a player with a name field and made it static, what do you put in the field before the player enters their name? Leaving it null is very bad practice, much better to wait until we can get the players name before we can even access it. So think 'Is there data that I don't need yet, or do not have yet, contained in this class?' if so, don't make it static.

There are other reasons, but my tea just boiled. Point is they are like duel wielding double ended flaming poison great swords of doom. Given the right problem, they can be an effective diplomatic solution! But do it wrong and you will cut your arm off, and then some people just do not like violence static and will protest your use of it.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #851 on: January 24, 2012, 08:10:24 pm »

Wait, so "static" in C# just means class level methods?

Weird!

Considering that's like a super important component of my programming style, (what with ruby being like super keen on them), I use class level methods all the time! (Though I almost never ever use "static" type classes. My "static" methods are usually recordkeeping stuff for the class - so the class keeps track of all its members, for example, meaning I don't have to pass around lists)
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #852 on: January 24, 2012, 08:13:17 pm »

It works differently in Ruby?
It is the same thing for c#, Java, c++ and python (Although the syntax in python is a lot different, but same basic idea)

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #853 on: January 24, 2012, 08:29:56 pm »

There are good reasons to make things static. Accessibility and runtime performance for example. Using a static final string is far more efficient than a string constant, and depending on the application, that performance tweak alone can boost your speed by up to 5%.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #854 on: January 24, 2012, 10:06:50 pm »

Well, Ruby has "class level" stuff, but it doesn't really have anything that works quite like static does, no. A lot of stuff is done at the class level, though - in fact, most everything you write is class level code, and when you call the "new" method on the class (In this case, equivalent to 'static new()'), the class builds an object based on the provided specifications. but not all the code in a class relates to building objects.

As an example, the ActiveRecord class has a whole host of finder, matcher, and database manipulating methods to monitor and manipulate and identify objects within the class.

IO classes, like File, are like 75% class level methods, too, I think.

Generally, though, Class-level, static equivalent methods are used for organizing and finding elements, so you don't have to keep track of them in the program or pass them around constantly making copies of them. You can just ask the class what it has.
Logged
Pages: 1 ... 55 56 [57] 58 59 ... 796