Thursday, June 16, 2011

Pounding my head against a target.


Okay so trying to use the extends class stuff. So it work perfect for assistants and girls. Unfortunatly not for player. Basically if everything works fine you get...

girl.HP
assistant.HP

What you get for player though is

player.Combatant.HP

Because it was basically a static class... Which defeats the entire purpose. So after playing with it for a nice few hours I got a plan. I re-named the Player class to cPlayer and made the variable Player an instance of cPlayer. This created a few bugs most of them I fixed by every class that bugged out I added a new variable of Player and then assigned them at the start of the game... There has got to be a better way.

var Player:cPlayer = new cPlayer();
Girl.Player = Player;
GoodsScreen.Player = Player;
AuctionScreen.Player = Player;
StringExpander.Player = Player;
Bidding.Player = Player;
GameTables.Player = Player;
PictureList.Player = Player;

But hey it seems to be working. I'm sure I created bugs somewhere that I haven't found yet though. But now I can get...

Player.HP

From an extension class.

Sorry about the code stuff and I am sure someone is going to write in that this was a stupid idea but... oh well.

Daisy

8 comments:

  1. testing the site's time.

    ReplyDelete
  2. Stupid idea? No, that looks like a great idea. In fact, I think it should have been done this way since the beginning.

    So, good job. ;)

    ReplyDelete
  3. I have no experience with Flash or ActionScript or whatever, but (based on other languages) couldn't you just declare it as a 'static' variable and reference it directly rather than making a bunch of pointers to it?

    ReplyDelete
  4. That could work, but then, in addition to having a static class consisting of a single property, you'd need to reference HP with StaticClassName.player.HP ... which isn't really an improvement over Player.Combatant.HP. (Player was originally conceived as a static class for just that reason.)

    Personally, I don't think Player.Combatant necessarily defeats the purpose. You'd simply need to think of that as a single entity. (As a static class, Player operates a little differently than the other 2, anyway.) It's all a matter of what you're trying to do.

    Alternatively, you could split everything up, so you have a Player class that you use to build a player object that you can pass around like the girls & assistants, to represent the physical player character, and a separate, static class (perhaps, you'd call it PlayerData) to handle all of the other stats and behind-the-scenes data crunching that the static class was responsible for, up to now (things like the date, time of day, cash total, and such that need to be kept track of, but aren't actually a part of the player character).

    Frankly, they really are serving two different purposes, so it'd probably be better to split them up, anyway. Then, the player object could be a static property of the PlayerData class, much like the Assistants and Girls are stored in static arrays, now, which you could then, reference directly, without having to make all of those pointers.

    Doc would probably be the best one to talk to about this, though, since he's the one who wrote the Player class, as it stands, so he best understands his reasons for designing it the way he did.

    ReplyDelete
  5. Actually having Player class and then instancing it is proper way to do it, so its all right. Well, at least in Python and C++ land.
    As for assigning stuff like `girl.player = player`, this is generally correct if `girl.player` means "player who owns the girl" and in this case I'd name it `girl.owner` instead. If its just global value that has no direct relation to the object, its still tolerable, but usually some decoupling is adviced.

    ReplyDelete
  6. I can never tell if any of these Anonymous people are supposed to be the same person or not.

    Anyway, I had a few more thoughts, but I've already gone on far longer that is really practical for the comments section of a blog, so I'm posting them in Code Review topic in the forum, again.

    ReplyDelete
  7. Wheres the picture of the day from?

    ReplyDelete
  8. @anonymous

    It looks like Illyasviel and Sakura from Fate/Stay Night.

    ReplyDelete