Can I change whatever I want in a game_state copy?

For example I have a copy of the game_state (game_state_copy) and want to change a certain firewalls stabiltiy.
Can I just change it like this:

unit = game_state_copy.contains_stationary_unit(location)
unit.stability = 30

Can I do this and if not, how would I go about doing so?

Yes if your game_state_copy is a deep copy.

but does this actually change it in the game_state_copy?
Doesn’t it just change a variable containing a copy of that unit?
What I mean is, if I were to do this somewhere else in my code:

unit2 = game_state_copy.contains_stationary_unit(same_location_as_before)

would it show me a damaged unit?

contains_stationary_unit() returns a boolean as to whether or not the location… contains a stationary unit there. I believe it is also called from game_state.game_map

To access a unit on the game map, just use the location directly (i.e. unit = game_state.game_map[location][0]). The [0] is because a stack of units are returned (and you probably only cared about the first one). Python will (unless I’m wrong) always return to you a reference, so any changes you make to “unit” will directly change the game map.

Note that you can do whatever you want with the game state and the game map, including the original AFAIK. Only the placement moves appended in the attempt_spawn() function are what the game engine will care about, it’s not going about the game map making sure what you have matches what it has.

Ok thanks alot, this helps.
Im not going to use it now, however I’m pretty sure contains_stationary_unit() actually returns a unit and not a boolean, but doesn’t matter.

I see. It returns the firewall when true and False when false, as well as being called from game_state. Ty Python.

In general, however, if you wanted things that were not stationary (or units selected for removal), the above method for access is true.

1 Like