GMS 2 Handling version of objects?

Discussion in 'Programming' started by Munch, May 14, 2019.

  1. Munch

    Munch Member

    Joined:
    May 14, 2019
    Posts:
    4
    What is better practice?

    Currently I am giving an object different values, depending on the sprite I choose.
    For example an object "car", that has the variable weight and speed, which get set depending on the sprite it gets.

    or

    do I create one parent object (with standard variable / functions) and an child object for every sprite/car I have with already set variables?

    or something completely different?
     
  2. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    676
    There are plenty of ways to do it.

    Personally I would store all the car data in an array or grid (and you can create the grid by importing a .csv file) and just have one object for cars with each car being a different instance of the same object but with stats and sprites dependant upon its index in the array/grid.
     
    Munch likes this.
  3. Munch

    Munch Member

    Joined:
    May 14, 2019
    Posts:
    4
    Alright, thanks!

    And what if some would have different functions?
    For example:
    95 cars just drive straight forward
    3 drive in circle
    1 follows another object
    1 makes a left turn every 10 seconds

    Would I code every function into the car object and save them as boolean values in the data grid?
    Or would I create child-objects for every extra function?
     
  4. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    676
    Yeah you could use states for the different functions and go from there, all inside the same object.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice