# Actor doesn't seem to manage State \[Beginner Help\]

**URL:** <https://discuss.akka.io/t/actor-doesnt-seem-to-manage-state-beginner-help/6556>\
**Category:** Akka Libraries\
**Tags:** akka-typed, scala\
**Created:** [May 22, 2020, 2:31am UTC](https://discuss.akka.io/t/actor-doesnt-seem-to-manage-state-beginner-help/6556 "2020-05-22T02:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsadeh](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/nsadeh/32/1982_2.png) [@nsadeh](https://discuss.akka.io/u/nsadeh)\
**Post date:** [May 22, 2020, 2:31am UTC](https://discuss.akka.io/t/actor-doesnt-seem-to-manage-state-beginner-help/6556/1 "2020-05-22T02:31:17Z")

</div>

I am new to Akka and to Scala and I built a small system to check whether a Sudoko configuration is valid: [https://github.com/nsadeh/Sudoko/blob/master/src/main/scala/sudoko/Main.scala](https://github.com/nsadeh/Sudoko/blob/master/src/main/scala/sudoko/Main.scala). It basically follows this guide: [https://developer.lightbend.com/guides/akka-quickstart-scala/define-actors.html](https://developer.lightbend.com/guides/akka-quickstart-scala/define-actors.html).

The issue right now is that the state of PartConstructor does not update, that is, it stays the empty state it is initialized in the whole time. I do not understand why, I am essentially following the same pattern as the Greeter bot actor in the example.

---

<div class="post-metadata">

**Author:** ![davidogren](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/davidogren/32/917_2.png) [@davidogren](https://discuss.akka.io/u/davidogren)\
**Post date:** [May 22, 2020, 2:22pm UTC](https://discuss.akka.io/t/actor-doesnt-seem-to-manage-state-beginner-help/6556/2 "2020-05-22T14:22:14Z")

</div>

In the functional style of Akka, you manage your state by returning a Behavior with the new state. Note in the example:

```auto
else {
        message.from ! Greeter.Greet(message.whom, context.self)
        bot(n, max) //This is the important bit, it's returning a new Behavior with the new n value
      }

```

Also, the corresponding explanation:

> Note how this Actor manages the counter by changing the behavior for each `Greeted` reply rather than using any variables. No concurrency guards such as `synchronized` or `AtomicInteger` are needed since an actor instance processes one message at a time.

Whereas, you are just returning `Behavior.same`

I can try to come up with a more detailed explanation over the weekend if this doesn’t make sense to you, but hopefully it can get you pointed in the right direction. Also note that if this is confusing to you, you can also adopt the objected oriented style as discussed here: [Style guide • Akka Documentation](https://doc.akka.io/docs/akka/current/typed/style-guide.html) . In that model, you keep your state in the object.
