Transmitting info from algocore to algo_strategy

I don’t know if this is the correct way to do this, but I’m trying to access some gamestate data from the first action frame of the previous turn. I have managed to extract the data I need, but I have stored it in a variable located in the start(self) function in algocore. I want to use this variable in my algo_strategy program. How should I go about doing this?

What I did is create another function that is called every action frame and then stores/tracks relevant data. You could do the same but only call the function on the first action frame.

Keep in mind that the AlgoStrategy class inherits from AlgoCore, so data stored in AlgoCore is accessible by AlgoStrategy.

Thus, you could simply store it as a self.______ variable name and then use it the same way in AlgoStrategy, etc.

1 Like

I understand that things from algocore can be accessed from algostrategy, but I’m still a bit unsure about how (I’m fairly new to classes and stuff)

So if I had a variable self.spawn_location located in algocore, and I wanted to access it from algo_strategy, it would be something like this?:
def on_turn(self, turn_state):
if self.spawn_location == condition:
(output)

or would I have to call self.spawn_location somewhere earlier?
(note: the variable I want is stored under start(self), under the elif stateType == 1: statement. I don’t think this is where variables are supposed to be stored in order to be called from algo_strategy)

That should work as long as long as you define self.spawn_location before you call it, just like a normal variable. This is why, generally speaking, it is good practice to initialize class variables (variables with self) inside your __init__ function. Then you can assign it inside whatever function has access to the data to you want to store.

If you create the variable inside start(self) it should still work, since it is being stored under the class. However, as written above this will almost certainly lead to bugs and errors quickly. You should declare variables inside __init__ and then use them in your class.

1 Like

I think I understand now. I’ll keep the initialising class variables tip in mind in the future. Thanks for your help!