Bay 12 Games Forum

Please login or register.

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

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

Vactor

  • Bay Watcher
  • ^^ DF 1.0 ^^
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #810 on: January 23, 2012, 07:27:27 pm »

In a situation like that, where it works one way, but not the other, it tends to be an issue with how the two different types of the superclass differ.  I'm guessing there is something different about how the mobs are instantiated from how the player is that is causing an issue that causes the player to do something funky when targeting, or change the variable of the source object that the mobs are all clones of, without changing the variable within the clone.

The best way to figure this out is to add in debug lines that print what the code is doing and to whom.  Another helpful thing to do is reduce the volume of activity.  Get it down to just one player and one mob, once that works add a second mob, and so on.  Unique IDs for each object wouldn't be a bad idea either, just for debugging.
Logged
Wreck of Theseus: My 2D Roguelite Mech Platformer
http://www.bay12forums.com/smf/index.php?topic=141525.0

My AT-ST spore creature http://www.youtube.com/watch?v=0btwvL9CNlA

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #811 on: January 23, 2012, 07:31:13 pm »

The best way to figure this out is to add in debug lines that print what the code is doing and to whom.  Another helpful thing to do is reduce the volume of activity.  Get it down to just one player and one mob, once that works add a second mob, and so on.  Unique IDs for each object wouldn't be a bad idea either, just for debugging.

Debug lines are not a bad idea, and I already had some (that's how I know the currentHP wasn't changing).  I just reduced the code down so that only one Mob is generated and tried attacking it.  No change in its currentHP, does change for the Player.  I think you might be right about it trying to change the parent Superclass or something, but I don't even know why that would happen, much less how to fix it.
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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #812 on: January 23, 2012, 07:34:09 pm »

Ok, this might take a little while, there is some stuff here that you just don't even need at all.
Going to have a go ripping some things up, and putting them back together, should make things a little neater for all involved.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #813 on: January 23, 2012, 07:36:48 pm »

Ok, this might take a little while, there is some stuff here that you just don't even need at all.
Going to have a go ripping some things up, and putting them back together, should make things a little neater for all involved.

I say again that you are under absolutely no obligation to do anything helpful for me.  Just that you did ask for a copy, after all.  I'd certainly love to see what someone who knows what they're doing has to say about all my duplication of method effort and referential congalines.  I know there's all kinds of stuff I'm doing wrong, or at least terribly inefficiently, but I did it all that way because I don't know of any other ways.
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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #814 on: January 23, 2012, 07:45:55 pm »

I'm enjoying myself. Been a while since I have had something like this to work with, keeps the mind active. Sort of like a fucking huge suduku.

Although firstly, protip: You know how you are using a char for color in just about everything? You do not have to, you can just use a ConsoleColor.

For example:
Code: [Select]
    public abstract class Actor
    {
        public char Display;
        public ConsoleColor Color;

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #815 on: January 23, 2012, 08:30:00 pm »

Although firstly, protip: You know how you are using a char for color in just about everything? You do not have to, you can just use a ConsoleColor.

For example:
Code: [Select]
    public abstract class Actor
    {
        public char Display;
        public ConsoleColor Color;

Nope, didn't know that ConsoleColors could be passed as values.  Not surprised though.  I'm sure there's a lot of cases like that where I'm tossing around chars and bytes and such to tell different methods what to do by longhand, when I could probably chop out a step or two if I knew what did what.  Might squeeze a little performance out of my drawing code.  But as long as a piece of code isn't messing anything up, I consider simplifying/optimizing it a non-priority.
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 #816 on: January 23, 2012, 08:35:16 pm »

But if you don't become bogged down minutiae at the expense of your project, how can you ever call yourself a REAL programmer? ;)
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #817 on: January 23, 2012, 09:02:01 pm »

But if you don't become bogged down minutiae at the expense of your project, how can you ever call yourself a REAL programmer? ;)
Exactly! Now...

Here is what you need to know. ConsoleColor is neither a primitive, nor is it a class, but something else. In truth it is a lot closer to an int than anything else, but you can think of it as a super buffed up bool, and it is called an Enum. Short of enumerator. These things can be very handy.

Think of a bool, it only has two possible states, true and false. No middle ground, no margin for error. Imagine we are programming for a shop that sells shirts, and they only sell shirts in two sizes, small and large. We could easily use a bool to show shirt size like this.

Spoiler (click to show/hide)
Now all large shirts are shown with true, all small shirts are false, we can tell one from the other, job well done!
But then a darkness. The boss thinks that we should also sell medium sized shirts. MADNESS!!! A bool can not hold three different sorts of values! He doesn't seem to care for these details, and tells you to make it work.
Well there are several ways to do this, we could decide to use an int instead, make small = 0, medium = 1 and large = 2, but then we need to fuck around with meanless numbers the entire program. Really fucking annoying. Instead, we can use an enum! That way, small = small, medium = medium and large = large. For example

Spoiler (click to show/hide)

You see how we make an enum in a similar way to a class? Similar idea, but instead of 'class name {}' we have 'enum name {}'
Also, our lines do not end with a semicolon, rather a ','
This is because we are not declaring  process, or a field, but a type. The compiler doesn't go over these like lines, so it doesn't have to know when a line ends.
We can use enums in comparative statements
Spoiler (click to show/hide)
And also switch statements and loops, with similar syntax. As you can imagine, they make life tolerable when you have these massive if statements and have to try and remember what each and every int means! Instead, you have a descriptive name.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #818 on: January 23, 2012, 09:17:14 pm »

You... You can just... declare shit and it exists?  Like, private ThisShit right_here; and then you can refer to it with plain old getter/setters?  Man, why even have primitives...


Anyway, still haven't untangled that Attack Method thing yet.  This is really stumping me; it really is starting to look like either the individual Mob object isn't being addressed or like it's targeting the Superclass somehow.  And I don't know how to make it not do that, since everything I'm using is exactly what Max's example showed.
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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #819 on: January 23, 2012, 09:21:46 pm »

Unless you have changed something, the attack should be happening on the super class from what I can tell...

Where have you put your current attack logic?

Edit: I just realised something terrifying. I've seen the terraria source code, and so far Aqizzar has shown more programming knowledge than Redigit.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #820 on: January 23, 2012, 09:31:07 pm »

Unless you have changed something, the attack should be happening on the super class from what I can tell...

Where have you put your current attack logic?

The Attack method itself resides in the MapObject class, under the name MeleeAttack.  I do realize that I've probably changed it a little since I packed it for you, so here's what I have now.

Code: [Select]
public void MeleeAttack(SuperMob attacker, SuperMob target)
{
int ANH = attacker.final_minHit * 10;
int AXH = attacker.final_maxHit * 10;
int TND = target.final_minDodge * 10;
int TXD = target.final_maxDodge * 10;
int DAM = attacker.final_damage;
int BLK = target.final_block;

int attack = random.Next(ANH, (AXH + 1));
int dodge = random.Next(TND, (TXD + 1));

if (attack > dodge)
{
if (DAM > BLK)
if (target.currentHP > DAM)
target.currentHP -= (byte)DAM;
else
if (target is MobObject)
RemoveMob(target.mobX, target.mobY);
else
if (target.currentHP > 1)
target.currentHP -= 1;
else
target.currentHP = 0;

if(attacker is PlayerObject)
{
Console.SetCursorPosition(1, 1);
Console.Write("You hit {0}! {1} {2} / {3} {4}", target.referential, attack, dodge, attacker.currentHP, target.currentHP);
MainScreen.ClearToEdge(Console.CursorLeft);
Console.SetCursorPosition(1,1);
}
else
{
Console.SetCursorPosition(1, 1);
Console.Write("{0} hits {1}! {2} {3} / {4} {5}", attacker.referential, target.referential, attack, dodge, target.currentHP, attacker.currentHP);
MainScreen.ClearToEdge(Console.CursorLeft);
Console.SetCursorPosition(1,1);
}

Console.ReadKey(false);
MainScreen.ClearToEdge(Console.CursorLeft);
Console.SetCursorPosition(1,1);
}
else
{
if(attacker is PlayerObject)
{
Console.SetCursorPosition(1, 1);
Console.Write("You miss {0}! {1} {2}", target.referential, attack, dodge);
MainScreen.ClearToEdge(Console.CursorLeft);
Console.SetCursorPosition(1,1);
}
else
{
Console.SetCursorPosition(1, 1);
Console.Write("{0} misses {1}! {2} {3}", attacker.referential, target.referential, attack, dodge);
MainScreen.ClearToEdge(Console.CursorLeft);
Console.SetCursorPosition(1,1);
}

Console.ReadKey(false);
MainScreen.ClearToEdge(Console.CursorLeft);
Console.SetCursorPosition(1,1);
}
}

I know my "RemoveMob" method is totally useless, but it using that or a more straightforward idea like "this.MobList.Remove(target)" doesn't seem to matter anyway.  I do understand that it's probably operating on the SuperMob parent class somehow, but I don't know how or why it would do that, since it is apparently operating with a correct instance of the Mob subclass.

Edit: I just realised something terrifying. I've seen the terraria source code, and so far Aqizzar has shown more programming knowledge than Redigit.

Y'know, that somehow doesn't surprise me.  If I knew how to display graphics instead of just Console bits, I could probably make Terraria too.
« Last Edit: January 23, 2012, 09:33:01 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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #821 on: January 23, 2012, 09:33:52 pm »

That is all pretty much just smoke and mirrors provided by XNA. The engine Microsoft built for him is doing the heavy lifting. Anyway, I recon I can done do something fun for ya nows.

EDIT: Sorry, keep getting distracted by this other project. I just realised why my colors were getting fucked up. I forgot to thread safe.
*Facepalm*
That will teach me... I even told myself I would do that later.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #822 on: January 23, 2012, 10:38:55 pm »

As long as this thread is turning into a public private tutoring session between me and Max, hey Max a question for you.  Or anyone else who can decipher what I'm asking.

I'm still working on copying your Superclass tutorial, and I'm on a... problem.  I've got my Mobs, recreating the AIStack thing (I'm actually working on a little separate experiment, but it's all the same code), and I want to call a method out of a List of AITypes.  So, I'm making like ( mob.AIStack.FleeAI.Method() ) or something crazy like that, and I don't know how to call a specific method from a specific Subclass object in a List<> of Superclass objects.

In this case at least, I know a particular type of Subclass will be present in the list, but I want it to be dynamic, so it can find an appropriate Subclass type in the List<>, and call a method from it.  I'm sure there's a way to do this that I just don't know, but I haven't seen it covered here (yet).
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.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #823 on: January 23, 2012, 10:46:40 pm »

Do you know the specific index of the AIType? For example, in the code I gave before, fleeAI was AIstack[0]
So to specifically make a type of AI be invoked, knowing its index is the fastest way, then you just call mob.AIStack[index].Update();

Otherwise, things get a little trickier. The idea behind it all was that a creature doesn't have to know what its AI is doing, instead its AI figures out what it should be doing, but you can find it with this.

Code: [Select]
foreach(AIType ai in AIStack)
{
if(ai is FleeAI)
{
ai.Update()
}
}

GlyphGryph

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

(and making the odd snide remark) also, I fucked up my OS display settings and now all text boxes are black text on black background... I need to fix that...Hey now, this isn't private at ALL. I'm enjoying watching. :P
Logged
Pages: 1 ... 53 54 [55] 56 57 ... 796