Appendix 2 - How Spread Value Numbers Stuff
Spread value gives the ID numbers according to the order the objects were created in, starting with the newest.
So if you create 5 objects, and you later create a 6th, then object #1 becomes object #2. Object #2 becomes Object #3, and so on. All the IDs shift along one.
This can be a pain if you have specific conditions that you want to run for a certain object.
One example is a game I made a while ago where there are several signposts. Depending on their ID number, a different message pops up when you touch them (it works the same way as the 'Naming' example we did above).
But if I created a new Signpost, all the IDs for the previous ones shifted and became wrong!
You can get around this using a simple formula when you spread a value. I'll do it in words first, then as you would do it in an expression, then as a whole event:
Number of Signposts - ID of Signpost + Starting Value
-
So if we're spreading a value of '1' in our signposts, the expression would be:
nObjects(Signpost) - ID(Signpost) + 1
-
Wooyay. Now we apply this in our spreading condition like this:
- Start of Frame
--- Spread '1' in ID of Signpost
--- Set ID of Signpost to 'nObjects(Signpost) - ID(Signpost) + 1'
And that successfully reverses the order of your Spread Values, so they don't shift when a new object is added later. Because it spreads a value according to normal rules, and then inverts it straight afterwards with the formula we did.