- Home /
 
               Question by 
               Vosheck · Mar 28, 2020 at 10:58 AM · 
                reflectionexpression  
              
 
              How to make a system that can be both manually controlled and automatized through a sorto of a simplified coding system?
Hi. I'm making a game that would feature a sort of simplified coding in which the player would steadily automate various parts of the game's management.
Mockup of what I'm trying to make
Here's some pseudocode using pseudo-reflection that will hopefully clarify things further:
 public class ProductionScript:MonoBehaviour{
      public int targetNumberOfProductionFacilities;
      void onGameTick(){  BuildOrDestroyProductionFacilities(targetNumberOfProductionFacilities)}
      public void ModifyTargetNumber(int number){//called from UI
       targetNumberOfProductionFacilities=number;
     }
 }
  public class VariableRepresentation{ public FieldInfo variableInfo; }
  public class VisualScriptingManager:MonoBehaviour{
     public VariableRepresentation variableRepresentationPrefab;
      List<VariableRepresentation> variableRepresentations=new List<VariableRepresentation>();
    void InstantiateVariableRepresentation(EventData underMouseClick){
     variableRepresentations.Add(Instantiate(variableRepresentationPrefab));
      variableRepresentations[variableRepresentations.Count-1].variableInfo=Assembly.GetVariable(underMouseClick.getComponent<ProductionScript>().targetNumberOfProductionFacilities) //hardcoded for demonstration
  }
    void onGameTick(){
      foreach (VariableRepresentation rep in variableRepresentations) {
             rep.variableInfo.SetValue(Calculate(variableRepresentations()));
             //this would solve the math of whatever configurations the player saved and would
              update the value of the variable in question, wherever it is located
     }
       }
I might be completely wrong in assuming that reflection is the way to go for this sort of a system. A few people have suggested an expression tree or a virtual machine. What would an elegant way to make a system like this? I don't want to waste time researching something that is unable or unlikely to create a system like this.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                