/**
  * Create a generic-purpose reference.
  * @param $referenceName
  * @param TES5GlobalScope $globalScope
  * @param TES5MultipleScriptsScope $multipleScriptsScope
  * @param TES5LocalScope $localScope
  * @return \Ormin\OBSLexicalParser\TES5\AST\Object\TES5ObjectProperty|TES5PlayerReference|TES5Reference
  */
 public function createReference($referenceName, TES5GlobalScope $globalScope, TES5MultipleScriptsScope $multipleScriptsScope, TES5LocalScope $localScope)
 {
     //Papyrus compiler somehow treats properties with ,,temp" in them in a special way, so we change them to tmp to accomodate that.
     if (preg_match('#temp#', $referenceName)) {
         $referenceName = preg_replace("#temp#i", "tmp", $referenceName);
     }
     if (strtolower($referenceName) == "player") {
         return $this->createReferenceToPlayer();
     }
     if (preg_match("#([0-9a-zA-Z]+)\\.([0-9a-zA-Z]+)#i", $referenceName, $matches)) {
         $mainReference = $this->createReference($matches[1], $globalScope, $multipleScriptsScope, $localScope);
         $propertyReference = $this->objectPropertyFactory->createObjectProperty($multipleScriptsScope, $mainReference, $matches[2]);
         //Todo rethink the prefix adding
         return $propertyReference;
     }
     $property = $localScope->getVariableByName($referenceName);
     if ($property === null) {
         $property = $globalScope->getPropertyByName($referenceName);
         //todo rethink how to unify the prefix searching
         if ($property === null) {
             foreach ($this->special_conversions as $special_conversion_name => $special_type) {
                 if ($special_conversion_name == $referenceName) {
                     $property = new TES5Property($referenceName, $special_type, $referenceName);
                     break;
                 }
             }
             if ($property === null) {
                 if (!$globalScope->hasGlobalVariable($referenceName)) {
                     $property = new TES5Property($referenceName, TES5BasicType::T_FORM(), $referenceName);
                 } else {
                     $property = new TES5Property($referenceName, TES5BasicType::T_GLOBALVARIABLE(), $referenceName);
                 }
             }
             $globalScope->add($property);
         }
     }
     return new TES5Reference($property);
 }
 /**
  * Create the ,,read reference".
  * Read reference is used ( as you might think ) in read contexts.
  * @param $referenceName
  * @param TES5GlobalScope $globalScope
  * @param TES5MultipleScriptsScope $multipleScriptsScope
  * @param TES5LocalScope $localScope
  * @return TES5Referencer
  */
 public function createReadReference($referenceName, TES5GlobalScope $globalScope, TES5MultipleScriptsScope $multipleScriptsScope, TES5LocalScope $localScope)
 {
     $rawReference = $this->referenceFactory->createReference($referenceName, $globalScope, $multipleScriptsScope, $localScope);
     if ($rawReference->getType() == TES5BasicType::T_GLOBALVARIABLE()) {
         //Changed to int implementation.
         return $this->createObjectCall($rawReference, "GetValueInt", $multipleScriptsScope);
     } else {
         return $rawReference;
     }
 }