How do I call a lower family to get a value from another family?

0 favourites
  • 6 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hello;

    I have a family called mobile--which needs to find out how many moves it gets from other families, knight(5 moves) and rogue(7 moves).

    I have a function getMoves that accepts mobile UID as an arguement and then casts it first as a knight and then as a rogue to get my moves (5 or 7). This seems kind of like a Kludge. In a full Object language Knight or Rogue would override the mobile getMoves function.

    Is this the best way to do this?

    thanks for your time.



  • The number of moves should be a parameter you pass through one function and probably a variable on the object? GetMoves not required, you call the other function with number of moves based on what was picked.

  • plinkie--thanks for the response.

    You are suggesting I populate a numberOfMoves variable that is a family variable at the mobile level with a call to a function at the Knight,or Rogue level? The mobile family does not know if it is a knight or a rogue as well, so it still has to casts itself as a knight and call the function that populates the numberOfMoves variable in mobile--and then it has to call rogue as well in case it was a rogue etc for every other possibility.

    Or perhaps I don't understand what you are suggesting?



  • having one family would simplify your code a lot - I would have Mobile hold all the variables: Type (Knight, Rogue, etc.), #ofMoves, health, strength, whatever, ...

    If you have more that a dozen variables, you might want to make Mobile a Container instead of a family and put an array (or dictionary) in the container. That will get created/destroyed with the object, and automatically picked with the object - and can hold as much data as you want.

  • Must say I can't fully understand the game you will have to draw it out or something but 'lower family' isn't a thing. If you have move numbers then they should be on the characters and you set the variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks AlanR and Plinkie;

    the moves the knight has depend on location, armor, wounds, how far he moved already etc. So it needs to be a function about stuff that pertains to a knight.

    The mobil family is associated with the user interface and I want to highlight how far a piece can go. I should be able to write all the code for the mobil family without knowing anything about what a knight does or how it calculates the moves etc. When I make something a member of the mobil family it gets all the user interface stuff so long as knight can provide what the mobil family expects of a family member (like being able to tell me how far it can move, whose side it is on, is certain terrain forbidden etc).

    Unfortunately it seems like the mobil family has to know about the kight since it has to get to the moves function somehow for the knight (or rogue or something I haven't thought of the user may need to move). In other languages I can do this since I just have to write a getMoves routine and then override it if the mobil happens to be a knight--but I don't need to know beforehand that I have a knight when I write the mobil code.

    I appreciate your comments and your time.



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