- Home /
Semi Generic With References
I'm stuck trying to make this setter function work well. For the life of me, I can't figure it out. I know c# doesn't do return by reference. In C# 7 they added it but don't have that. Trying to do it in a 'safe' way but dunno if that's possible. I've tried adding a ref parameter for Stat and one for value but nothing worked :/
 Stat stat = target.GetComponent<StatManager>().getStat(statType);
 stat.Set(modType, valType, (modAmount * modStat + baseAmount));
 public class Stat {
 
   // Variables here
 
    public void Set(ModifyType modType, ValueType valType, int modAmount) {
       int value = baseValue;
       switch (type) {
          case ValueType.MIN:
             value = minValue;
             break;
          case ValueType.BASE:
             value = baseValue;
             break;
          case ValueType.MOD:
             value = modValue;
             break;
          case ValueType.MAX:
             value = maxValue;
             break;
          default:
             // Error occurred, shouldn't happen
             break;
       }
 
       switch (modType) {
          case ModifyType.ADD:
             value += modAmount;
             break;
          case ModifyType.SUBTRACT:
             value -= modAmount;
             break;
          case ModifyType.MULTIPLY:
             value *= modAmount;
             break;
          case ModifyType.DIVIDE:
             value /= modAmount;
             break;
          case ModifyType.SET:
             value = modAmount;
             break;
          default:
             // Error occurred, shouldn't happen
             break;
       }
    }
 }
I've made this look a lot better in my code but this gets my point across. Normally I would use just some pointers but my mind is failing me since I have to manipulate the data structure but I want to do it generically.
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Make a public variable with a private setter appear in inspector 3 Answers
Get and Set difference 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                