Inheritance Problem again...

0 favourites
  • 3 posts
  • Hi guys,

    I'm really unhappy with the structure of families in construct and try to think of a better way to handle this issure, since I have a lot of class inheratance. I've made up an example, which hopefully make you understand my problem. Let's assume the atachment is my class model and I create one family for each class. (I love car examples ).

    Imagine one day a costumer comes to my vehicle rental agency. His requirements are:

    • He wants a land vehicle
    • All motorcycles should be in first row
    • all trucks should be in last row
    • When he clicks on a motorcycle show me the horsepower

    This is what I would do:

    Pick all vehicles

    ---Foreach Vehicles

    ---LandVehicles = Vehicles.UID

    -------Show LandVehicle

    ------Foreach LandVehicles

    ------Motorcycles = LandVehicle.UID

    ----------Put motorcycle in first row

    ------Foreach LandVehicles

    ------Trucks= LandVehicle.UID

    ---------Put truck in last row

    On click Motorcycle

    Vehicle = Motorcycle.UID

    ---show Vehicle.horsepower

    Is there any better solution? I mean there are a lot of foreach loops. And the biggest problem: I can't even access my instance variables from other families. For example horsepower is an attribut that's shared by all vehicles. But when I click on a specific vehicle I always have to reference to the family.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Where you storing the horsepower?

    My thoughts, is use instance variables.

    Will try to do demo...

    Here you go, its not the best way, but I just made a whole keyboard input system yesterday doing this way and worked FANTASTICLY well. Upercase, lowercase etc (for mobile devices so we can drop the TextBox all together

  • ,

    So now it is 1 check if you require it - using instance variable "Type", but you can add more instance variables to check.

    You can use foreach vechiles

    And put conditions in based on instant variables.

    So many options, and no real right way to do someting lol.

    Oh, I'm not using families at all here. But you can use them to if you want.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)