News Forums Sample Projects, How To’s, and Code Samples Custom code to change int value in memory

This topic contains 1 reply, has 2 voices, and was last updated by  prime 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33263

    Worempie
    Participant

    Hi

    I have a question about using RAIN in a custom piece of code. I want to make a GUI button that whenever you press it the variable curEnergy gets an extra 10 points in value. Right now I have it like this:

    GUI.Box (new Rect (0, 0, Screen.width / 2, 100), “”);
    {
    if (GUI.Button(new Rect (50, 10, Screen.width / 3, 20), “Get Energy”)){
    Debug.Log(“Clicked the button with text”);
    AIRig selectedObjectAI = selectedObject.GetComponentInChildren<AIRig>();
    selectedObjectAI.AI.WorkingMemory.SetItem<int>(“curEnergy”, 10);
    }

    this piece of code set’s the value to 10 instead of adding 10 to the existing amount. How do I fix this?

    #33265

    prime
    Keymaster
    selectedObjectAI.AI.WorkingMemory.SetItem<int>("curEnergy", selectedObjectAI.AI.WorkingMemory.GetItem<int>("curEnergy") + 10);
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.