Global Variables

Good afternoon,

I am trying to create a new ActorRef, however I want it to be a global variable.

I tried declaring it as var TracerRef :ActorRef[Any] = _

However it is staying null when required in different actorRefs.

Could you kindly guide me on how to tackle this query please ?

Thanks a lot and good day :slight_smile:

Good day to you,

it would be really helpful if you could provide more context.

Are you using akka? Where do you define var TracerRef? What does the rest of your program look like?

All I can say based on that one line of code is that you declare an uninitialized variable TracerRef, that will remain uninitialized until you assign a value to it, for example:

// somewhere in your code you will have to assign a value, something like
TracerRef = actorContext.spawn("newActor")

To put it differently: why do you expect this variable to have a value if you do not assign a value?