CODE BREAKDOWN - Green text can be altered in your levels.
Roid0SpeedUnstableTimer = GetGameTime() + 3
Roid2EnergyUnstableTimer = GetGameTime() + 1
This sets up the timers for changing the attributes of the asteroids. The general formula is
Timervariablename = GetGameTime() + IntervalInSeconds. IntervalInSeconds can be randomized.
while GameRunning() do...end
Makes sure that the instability code is always running. You can change it if you know how(eg. If you want to make an asteroid that stabilizes all the others when captured), but to be on the safe side, only use while...do loops that will always be running, like while GameRunning() do, or while gamewon == 0, if you are following annikk's guide.
if GetGameTime() >= Roid0SpeedUnstableTimer then...end
Checks whether the timer has run out, and the asteroid should change.
GetAsteroid(0):SetSpeed(...)
Picks which asteroid to change and which attribute to change.
Roid0SpeedUnstableTimer = GetGameTime() + 3
Resets the timer for that attribute.
HOW TO USE math.random() IN LUA.
math.random() will return a value from 0-1.
If you want to specify a range, then it is more complicated. Because math.random() can only take integral arguments, you must do this. (It's quite ugly for such a simple outcome. F=ma ftw.) In this example, I will make it output numbers between 0.456 and 0.78912.
First, take the number with the most decimal places. (0.78912)
How many decimal places does it have? (5)
Multiply it by 10^LargestNumberOfDecimalPlaces (This would be 100000 in our example, and gives us an answer of 78912, an integer. math.random() understands this.)
Multiply the other number by 10^LargestNumberOfDecimalPlaces (45600)
Now put these in math.random() like so: math.random(smallestnumber, largestnumber). (math.random(45600, 78912))
Add '/10^LargestNumberOfDecimalPlaces, so you now have math.random(smallestnumber, largestnumber)/10^LargestNumberOfDecimalPlaces. (math.random(45600, 78912)/100000)
Put this in SetAttribute(here). (SetSpeed(math.random(45600, 78912)/1000000))
Job done. Yay.