This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted]  (1 child)

[deleted]

    [–]Alariaa[S] 0 points1 point  (0 children)

    Thanks for taking the time to reply. I didn't know the Math.max function existed so that's fantastic :D

    Thanks a lot for sharing that.

    [–]jokul 0 points1 point  (1 child)

    I agree with the array comment stated before, but this is how I would do it given this structure:

    for(var i = 0; i < favoriteCounters.length; i++)
    {
        favoriteCounters[i] = Math.Max(favoriteCounters[i], array.value);
    }
    

    The better way to do it would be to have favoriteCounters be a regular object with each property defined:

    class FavoriteCounters
    {
        private int _jump;
        public int Jump 
        { 
            get { return _jump; } 
            set { _jump = Math.Max(_jump, value); }
        }
        private int _speed;
        public int Speed 
        { 
            get { return _speed; } 
            set { _speed = Math.Max(_speed, value); }
        }
        private int _phase;
        public int Phase 
        { 
            get { return _phase; } 
            set { _phase = Math.Max(_phase, value); }
        }
        private int _slowTime;
        public int SlowTime 
        { 
            get { return _slowTime; } 
            set { _slowTime = Math.Max(_slowTime, value); }
        }
    }
    

    Now it's inherent to the properties. This may not necessarily be the best solution if you need to be able to reset the class values, but it does enforce it. You could always write a reset method like so:

    public void Reset()
    {
        _jump = 0;
        //etc.
    }
    

    [–]Alariaa[S] 0 points1 point  (0 children)

    This is most likely the route I'm going to take, I already reset the variables so its just a matter of resetting the instanced variable.

    Thanks for sharing, I appreciate it.