title: how to add a points system to an app preferences DataStore Jetpack Compose
body: <p>I'm working on a <strong>Quiz app</strong> and I'm trying to <strong>add a points system</strong> to the app so that <strong>everytime the user gets a question right he gets a +1pts</strong>.
  and for storing the points I use <strong>jetpack compose preferences Datastore</strong>.
  the problem is whenever I want to add a point to the already saved points it doesn't work.</p>
  <blockquote>
  <p>this is my PointsData</p>
  </blockquote>
  <pre><code>class PointsData(private val context: Context) {
      //create the preference datastore
      companion object{
        private val Context.datastore : DataStore&lt;Preferences&gt; by preferencesDataStore(&quot;points&quot;)
          val CURRENT_POINTS_KEY = intPreferencesKey(&quot;points&quot;)
      }
      //get the current points
      val getpoints: Flow&lt;Int&gt; =context.datastore.data.map { preferences-&gt;
          preferences[CURRENT_POINTS_KEY] ?: 0
      }
      // to save current points
      suspend fun SaveCurrentPoints(numPoints : Int){
          context.datastore.edit {preferences -&gt;
              preferences[PointsData.CURRENT_POINTS_KEY] = numPoints
          }
      }
  }
  </code></pre>
  <blockquote>
  <p>save points methode</p>
  </blockquote>
  <pre><code>class SavePoints {
      companion object {
          @Composable
          fun savepoints(numPointsToSave : Int) {
              val context = LocalContext.current
              val scope = rememberCoroutineScope()
              val datastore = PointsData(context)
  
              LaunchedEffect(1) {
                  scope.launch {
                      datastore.SaveCurrentPoints(numPointsToSave)
                  }
              }
          }
      }
  }
  </code></pre>
  <p>and whenever i want to get the number of points from my DataStore i use</p>
  <pre><code>val pointsdatastore = PointsData(context)
  val currentpoints = pointsdatastore.getpoints.collectAsState(initial = 0)
  //display it as text for example
                  Text(text = currentpoints.value.toString(), fontSize = 30.sp, fontWeight = FontWeight.Bold,
                      color = Color.White)
  </code></pre>
  <p>and to do the operation i want (add +1 o the already existing points i do this</p>
  <pre><code> val pointsdatastore = PointsData(context)
      val currentpoints = pointsdatastore.getpoints.collectAsState(initial = 0)
  SavePoints.savepoints(numPointsToSave =  currentpoints.value + 1)
  </code></pre>
  <p>but it doesn't seem to work because the number of points always stays 1.</p>
  <p><strong>if you know whats the problem please help</strong>.</p>