edited April 2014 in ORK Scripting
Whenever I use ORK.Game.Variables.getFloat(), I get a null reference exception.

I type something like this:
if(ORK.Game.Variables.getFloat("stance") == 3) {Debug.Log ("hi");}
Am I trying to use this wrong or do I need to do something else first in order to access the data via script?
Post edited by MarkRMichaels on
  • I get these errors:
    No ORK Project Asset found!
    UnityEngine.Debug:LogWarning(Object)
    ORKFramework.DataHandler:LoadProject(ORKProjectAsset)
    ORKFramework.DataHandler:LoadData()
    ORKFramework.DataHandler:set_ProjectAsset(ORKProjectAsset)
    ORKFramework.DataHandler:Initialize(ORKProjectAsset, Type[])
    ORKFramework.ORKCore:Initialize(ORKProjectAsset, Type[])
    ORKFramework.ORK:Init(ORKProjectAsset) (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:179)
    ORKFramework.ORK:.ctor(ORKProjectAsset) (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:91)
    ORKFramework.ORK:Instance() (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:107)
    ORKFramework.ORK:get_Game() (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:412)
    IntelligenceStanceUsed:Update() (at Assets/Scripts/IntelligenceStanceUsed.cs:16)

    No ORK Project Asset found!
    UnityEngine.Debug:LogWarning(Object)
    ORKFramework.DataHandler:LoadProject(ORKProjectAsset)
    ORKFramework.DataHandler:LoadData()
    ORKFramework.ORKCore:Initialize(ORKProjectAsset, Type[])
    ORKFramework.ORK:Init(ORKProjectAsset) (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:179)
    ORKFramework.ORK:.ctor(ORKProjectAsset) (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:91)
    ORKFramework.ORK:Instance() (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:107)
    ORKFramework.ORK:get_Game() (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:412)
    IntelligenceStanceUsed:Update() (at Assets/Scripts/IntelligenceStanceUsed.cs:16)

    NullReferenceException: Object reference not set to an instance of an object
    ORKFramework.ORK.Init (.ORKProjectAsset project) (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:265)
    ORKFramework.ORK..ctor (.ORKProjectAsset project) (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:91)
    ORKFramework.ORK.Instance () (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:107)
    ORKFramework.ORK.get_Game () (at Assets/ORK Framework/gameplay_source_code/gameplay_source_code/ORK Framework Gameplay/Framework/ORK.cs:412)
    IntelligenceStanceUsed.Update () (at Assets/Scripts/IntelligenceStanceUsed.cs:16)

  • That's because you don't use a Game Starter (with your ORK Project asset) to initialize ORK first.

    Also, the function is GetFloat and not getFloat :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • I am confused. I have an ORK Game Starter in my scene with my ORKProject asset added. Do I need to meet some other restriction?

    For example, if my game is already running and I add the script to my prefab afterwards, it still breaks.


    Here's the complete script:
    using UnityEngine;
    using ORKFramework;
    using System.Collections;

    public class IntelligenceStanceUsed : MonoBehaviour {

    float stance = 0;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update ()
    {
    stance = ORK.Game.Variables.GetFloat ("stance");
    if (stance == 2)
    {
    Debug.Log ("hi");
    }

    }
    }
  • Tested your script and it's working on my end.
    If a game starter with an ORK project asset is in the scene, this should work fine.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.