What should the logic be in, a render component or a script?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • What should the logic be in, a render component or a script?

      Assume that I want to add something to show the current score of the player in a game. It's natural to create an actor along with a render component and a script for this purpose.
      In the components, I would add some logics like:
      - Register self to the event dispatcher, listening to something like "PlayerGotScore".
      - When triggered by the "PlayerGotScore", get the new score from the event.
      - Then update the appearance of the render component according to the new score.
      The question is that I don't know where should these logics be. Either the render component or the script seems to be a reasonable place. How to make this decision?
    • All the logic should be in the script. The only thing the render component should do is actually render.

      -Rez
    • Here is another similar question... Assume that there is a button in a game. The only functionality of the button is to pause the game when clicked.
      Again, I would like to create an actor with components for it. And, to pause the game, the only logic we need is to dispatch an event namely "PlayerPausedGame".

      I found two ways to deal with it:
      1. Create an actor with a render component (R for short) and a script (S for short). The R is responsible for detecting clicks.
      When clicked, R doesn't dispatch "PlayerPauseGame"; it simply tells the S that the button is clicked. Then the S will dispatch "PlayerPausedGame".

      2. Create an actor only with R. The R is responsible for detecting clicks.
      When clicked, R directly dispatch "PlayerPauseGame".

      Again, I am not sure which one is better. Or maybe there is another better way that I haven't found?
    • The render component should not be responsible for detecting clicks, it should only render. You should have a separate component for detecting clicks, which in turn dispatch the PlayerPauseGame event.

      -Rez