1. Well, you said that it didn't crash immediately. So that made me think it probably wasn't something in LevelSetup().
So I was able to skip over the whole of function LevelSetup() and just look through the much shorter function LevelLogic()
You said after a while, the game crashes. I noticed your fading background thing and studied the code you have used, and realised that it would eventually try to set the backdrop colour to a negative number. I theorised that that must be what was causing the crash.
Hopefully I'm right. :>
2. No, that won't work. You need to wait until you've set rcolour with math.sin
If you do it before, you're just changing the value of rcolour for the previous cycle. It will be given a brand new value (possibly negative!) in the next lines.
Instead of what you have, here's what I'd suggest.
rtime = GetGameTime() -- setting the variable 'time' to whatever the game time is
rtime = rtime / 275 -- taking that 'time' variable and dividing it by n. divide slows down. multiply speeds up.
gtime = GetGameTime()
gtime = gtime / 275
btime = GetGameTime()
btime = btime / 275
rcolour = math.sin(rtime) -- setting the variable 'rcolour' to wave up and down. like this the range is now -1 to 1. 1 being the peak of the wave and -1 being the trough. with the horizontal axis as 'time', in this case the 'time' variable.
rcolour = rcolour * rcolour -- square rcolour, if it is negative this will make it positive
rcolour = math.sqrt(rcolour) -- now take the square root of it
rcolour = rcolour * 35 -- setting the range of 'rcolour' from 0 to 255. in this case the 'r' referring to 'red'. do the same with 'g' and 'b'
--gcolour = math.sin(gtime)
--gcolour = gcolour * 233
--bcolour = math.sin(btime)
--bcolour = bcolour * 17
SetBackdropColour(rcolour,0,10) -- makes the background change between colours. 0 is black/min. 255 is white/max
3.
Nope, not at all. It will be just the same as it was before, except that where it used to try to set the background colour to say, (-10,0,10) it will now correctly set it as (10,0,10).
Lets look at 2 examples of Rcolour to see what I mean.
Follow this carefully and you should understand what's going on. :>
Example A
rtime = GetGameTime()Suppose GetGameTime() returns 50.
rtime will thefore be 50.
rcolour = math.sin(rtime)
ok, we're setting a value for rcolour here. It's equal to Sin of rtime. rtime = 50, so math.sin(50) = 0.766
Now we use my new commands, and you will see that ultimately do not change the number in this case:
rcolour = rcolour * rcolour
ok, so rcolour is 0.766. So to find the new value, we just do 0.766 * 0.766
= 0.587
Next we take the square root...
rcolour = math.sqrt(rcolour)
math.sqrt(0.587) = 0.766
Notice how the value didn't change at all from this operation!
Now we do your final step to turn it into a value we can usefully use for colour.
rcolour = rcolour * 35 -- setting the range of 'rcolour' from 0 to 255. in this case the 'r' referring to 'red'. do the same with 'g' and 'b'
ok, well Rcolour at the moment = 0.766
So the new value for rcolour = 0.766 * 35
rcolour = 26.8
Then we plug this into your backdrop colour.
SetBackdropColour(rcolour,0,10)
So after 50 sec of game time this would give a colour of (27,0,10)
Example B
rtime = GetGameTime()Suppose GetGameTime() returns 210.
rtime will thefore be 210.
rcolour = math.sin(rtime)
ok, we're setting a value for rcolour here. It's equal to Sin of rtime. rtime = 210, so math.sin(210) = -0.5
NOTICE THAT THE NUMBER IS NEGATIVE THIS TIME!!!!!!!
Now we use my new commands, and this time you will see why they are useful.
rcolour = rcolour * rcolour
ok, so rcolour is -0.5
So to find the new value, we just do -0.5 * -0.5
= 0.25 (NOT Negative anymore!!!)
Next we take the square root...
rcolour = math.sqrt(rcolour)
math.sqrt(0.25) = 0.5
Now we've turned our -0.5 into a 0.5
This will prevent the crash.
Now we do your final step to turn it into a value we can usefully use for colour.
rcolour = rcolour * 35
ok, well Rcolour at the moment = 0.5
So the new value for rcolour = 0.5 * 35
rcolour = 17.5
Then we plug this into your backdrop colour.
SetBackdropColour(rcolour,0,10)
So after 50 sec of game time this would give a colour of (18,0,10)
Lets also just quickly look at what happens at the moment, WITHOUT my added code:
Example C
rtime = GetGameTime()Suppose GetGameTime() returns 210.
rtime will thefore be 210.
rcolour = math.sin(rtime)
ok, we're setting a value for rcolour here. It's equal to Sin of rtime. rtime = 210, so math.sin(210) = -0.5
NOTICE THAT THE NUMBER IS NEGATIVE THIS TIME!!!!!!!
<<<Skipping my commands to show you why it crashes>>>
Now we do your final step to turn it into a value we can usefully use for colour.
rcolour = rcolour * 35
ok, well Rcolour at the moment = -0.5
So the new value for rcolour = -0.5 * 35
rcolour = -17.5
Then we plug this into your backdrop colour.
SetBackdropColour(rcolour,0,10)
So after 50 sec of game time this would give a colour of (-18,0,10)
You can't have -18 red! CRASH. :>