ID:2069685
 
(See the best response by Lummox JR.)
Problem description:
So i was making a turn based strategy, when i realised, that some calculations involving multiple objects and multiple variables becoming too complicated, so it would be convenient to write the changes to the object vars, but have a recording of the object on the previos turn.

Here is and example of what im talking about. Say we have two turfs with grass and rabbits. Each turn amount of grass increases for 50%, rabbits eat units of grass twice of their amount, and some of those rabbits may choose to go to an adjacent turf. So when i calculate the amount of grass, i might get confused, wether im adding 30% before or after taking 2*rabbits. More over, the migrating rabbits should only eat grass on a turf they are leaving, but if the turf they arrive will be processed after the turf they are leaving, they eat grass on both of those turfs.

So instead of all that i decided that all those calculations should involve the state of the turf ot the previos turn, wich is unchanged, and only the current state is.

Firstly i tried defining a datums as vars of every atom, wich would hold all of the vars instead of atoms, so i can have two datums all the time - current and previos. The idea looked convenient, so i tried it, but when i defined var/datum/dating/current in /atom it appeared that i cant change the type of this var it a /turf/land or somthing.

Code:
/datum/dating
//some procs here, no vars yet
/datum/dating/land
var
rabbits
grass

/atom/var/datum/dating/current
/turf/land
//this is a duplicate definition obviosly
var/datum/datum/dating/land/current
//and in the next two cases im not overriding var, but defining a new class or somthing like that, i'm not sure
/datum/datum/dating/land/current
datum/datum/dating/land/current


Of course there are other ways to record the state of an atom:
1) create the same atom and copy vars into it
2) make an associated list like var/current = list("var1name" = x)
3) dont define the type of the datum after var/ and use ':' operator all the time

The problem is that now they all seem like a workaround to me (including the first attempt) so im asking, wich one of them is the most decent, or maybe there is a better one, or there is a way to redefine variable type.
Best response
Instead of trying to record data and work with old data, maybe you could consider keeping track of changes another way. Since you're primarily concerned with the delta (change) for many of these cases, maybe have a way to record how much change you want to make, and then perform the changes in one shot.
Thank you! Its really a good idea, though i still need to store the delta value somewhere, working with it is much simplier.