Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

PlayerPrefs.SetInt or GetInt make strange decisions

Discussion in 'Scripting' started by HVutov, Apr 25, 2015.

  1. HVutov

    HVutov

    Joined:
    Mar 16, 2015
    Posts:
    18
    Hello i have simple get and set
    Code (CSharp):
    1. for (int i = 0; i < 20; i++)
    2.         {
    3.             PlayerPrefs.SetInt("Inventory " + i, inventory.Items[i].itemID);
    4.         }
    Code (CSharp):
    1. for (int i = 0; i < 8; i++)
    2.         {
    3.             addItem(PlayerPrefs.GetInt("Inventory " + i));
    4.         }
    I add items by item ID these are the ids' 0,1,2,3,4,5,6,6,0,1 at save.
    When i load them they are 0,1,2,3,4,5,6,6 the strange is that i dont have the last 0 and 1 it seems they are overwrote but the two id(6) are not overwrote so i dont know what happends


    Edit: they cant be overwrite because i set the Key with loop index so strange
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Your two loops have different conditionals (i < 20 and i < 8). Is that intended?
     
    HVutov likes this.
  3. HVutov

    HVutov

    Joined:
    Mar 16, 2015
    Posts:
    18
    Oh man thank you so much i forgot to change it