### Author Topic: Level design/ Code questions from a beginner  (Read 16515 times)

0 Members and 1 Guest are viewing this topic.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #30 on: April 12, 2010, 12:58:20 AM »
Quote
1-Globals.Mines.SpeedPower (float) - this sets the speed power of a mine, it says, but what is 'speed power' as opposed to 'speed' or 'explosion power'? and would it be a value btween 0 and 1 only?

I would imagine it is how much the "speed" attribute of the asteroid contributes to the speed of a mine that is born there.  Just guessing though.

Quote
2-what is a 'float' value? and what is an 'int' value?

A "float" value means "floating point".  What it's really talking about is the decimal point.  Most of the "float" commands are looking for values between 0 and 1.  EG 0.5 or 0.3444 or 0.8663458238484 etc

An "int" means "integer", which is a Whole Number.  3 is an integer.  So is 7.  12.5 is NOT an integer.

Quote
3-ok, i want to have it so the enemy maxes out trees, etc on the roid theyre on, before exapnding out. but without lots of complicated coding to check lots of other variables (ahem!). is there a simple way to just say, '80% of the time, the enemy will max out current asteroid before expanding'? (also having that expanding code too).** this one isnt essential to me for now but it would be nice to have the code available for later use.**

I'm not aware of a simple way.  It can be achieved with the right code though, I'm sure.  :>

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0
• Posts: 274
##### Re: Level design/ Code questions from a beginner
« Reply #31 on: May 05, 2010, 06:37:48 PM »
HELLO! me again...
i have a question...

how do you make an asteroid have noone on it? simple quesiton really, but obviously 0 is the greys, 1 is me, and 2 is the enemy, so what is blank/ nothing/ undesignated/ uninhabited roid?

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #32 on: May 05, 2010, 07:19:34 PM »
0 is uninhabited, or "barren", which is also the greys.

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0
• Posts: 274
##### Re: Level design/ Code questions from a beginner
« Reply #33 on: May 05, 2010, 11:34:55 PM »
so theres no way to have an uninhabited roid without it basically belonging to the greys? so, the only way to have a properly barren planet is to put the roid on 0 seeds and no trees etc?

ok...thanks annikk.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #34 on: May 06, 2010, 03:40:07 PM »

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0
• Posts: 274
##### Re: Level design/ Code questions from a beginner
« Reply #35 on: May 07, 2010, 07:29:52 PM »
big problem ...

ok, when testing my new map i can get so far then it freezes on me. every time. i obviously have no idea why this should be and would very grateful if someone can help me figure out why this is happening. so far, it seems to be about the point when ive taken 2 roids, ie, i own 3 in total. this is my experience of it, and its happened wiht different planets, not the same 3. its weird.

if anyone has experienced this themselves before please enlighten me as im sure theres nothing wrong code-wise. however, seeing as it wouldnt exist without the code, i can only assume something is happening in there that im not aware of.

anyone care to take a look?

thanks
AWS

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #36 on: May 08, 2010, 04:39:35 PM »
Are you missing a coroutine.yield() somewhere?

I'll take a look if you want.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #37 on: May 09, 2010, 01:52:34 AM »
Here's the problem:

Code: [Select]
` 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 * 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`

Here's my theory.  Lets follow the steps for Rcolour.

It begins as Game Time, which is 0.  Sin Game Time is therefore also 0.  math.Sin(GetGameTime()) = 0
After a while, game time time has advanced enough that the Sin wave has reached the top of its curve, and math.Sin(GetGameTime()) = 1
The same amount of time passes again, and the wave has reached the bottom of its curve, math.Sin(GetGameTime()) = 0 again
Eventually, enough game time will pass and math.sin(GetGameTime()) = -1

You actually have GetGameTime() / 275, but this just means it takes longer for the bug to occur.

Here's what's happening.  math.Sin(GetGameTime()) is eventually producing negative numbers, when it first dips below the horizontal centre line on the graph it will be producing -0.1, -0.2, -0.3, etc...

You are then trying to multiply that here:
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'

If rcolour = -0.1, then rcolour * 35 = -3.5

Then you use this command:

SetBackdropColour(rcolour,0,10)

In the circumstances we have just explored, you are now trying to set the Red component of the backdrop colour as -3.5!
You can't have negative numbers for background colour.  This is why it crashes after a period of time, when the Sin wave has gone from 0 to 1, back down to 0 again, and starts to become negative.

To fix this, you need to make the number positive every time.

Suggest adding these lines to do this:

Code: [Select]
`rcolour = rcolour * rcolour  -- square rcolour, if it is negative this will make it positivercolour = math.sqrt(rcolour) -- now take the square root of it`

You would need to do the same with gcolour and bcolour if you want to use those variables too.
« Last Edit: May 09, 2010, 01:57:05 AM by annikk.exe »

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0
• Posts: 274
##### Re: Level design/ Code questions from a beginner
« Reply #38 on: May 09, 2010, 01:50:04 PM »
thanks annikk. i have a couple of Q's from your reply however..
1-how did you find that was the problem?
2-i added your suggested 2 lines at the middle of this section (see below), is that the best place for it? does it matter where in this section it is placed?
3-will this not make the pulsating background colour jarred and no longer smooth? that was my intention with the high 275 number, to enable a long smooth colour fade/ transition. if it's this large number that is causing the problem, but the 2 lines you added will rectify that, will the curve still be smooth?

eg..
Code: [Select]
`while GameRunning() do 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 = 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 = 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 * 40  -- 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`...

thanks again for the invaluable help. ill test it out later today and see what happens!
ps - i dont fully understand why or how it reaches into a negative number when it wasnt doing so before (in my previous level, binary).  by my understanding then, there must be a threshold where one can overdo the number and it will trigger a negative number. 275 seems to be over that threshold, whereas my previous number wasnt. apologies for my lack of mathematical comprehension once again.

EDIT - just tried it and it still locks up. do i have to do something else with these lines? or are they just in the wrong place?
« Last Edit: May 09, 2010, 02:10:17 PM by AWS »

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #39 on: May 09, 2010, 02:25:17 PM »
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.

Code: [Select]
` 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 positivercolour = 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

Code: [Select]
`rtime = GetGameTime()`Suppose GetGameTime() returns 50.
rtime will thefore be 50.
Code: [Select]
`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:

Code: [Select]
`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...
Code: [Select]
`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.

Code: [Select]
`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.
Code: [Select]
`SetBackdropColour(rcolour,0,10)`
So after 50 sec of game time this would give a colour of (27,0,10)

Example B

Code: [Select]
`rtime = GetGameTime()`Suppose GetGameTime() returns 210.
rtime will thefore be 210.

Code: [Select]
`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.

Code: [Select]
`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...
Code: [Select]
`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.

Code: [Select]
`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.
Code: [Select]
`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

Code: [Select]
`rtime = GetGameTime()`Suppose GetGameTime() returns 210.
rtime will thefore be 210.

Code: [Select]
`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.

Code: [Select]
`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.
Code: [Select]
`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.  :>
« Last Edit: May 09, 2010, 03:51:59 PM by annikk.exe »

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #40 on: May 09, 2010, 02:41:56 PM »
I am not sure why Binary Black does not crash, but this map does.

Maybe I am wrong about it being caused by negative numbers in the backdrop colour.  :>

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0
• Posts: 274
##### Re: Level design/ Code questions from a beginner
« Reply #41 on: May 09, 2010, 06:09:28 PM »
i follow that. it makes sense to me now. thank you.
im one of those people that although i can understand things eventually but i have to go through every step in the plainest language possible!

anyway, ill see if that orientation works and let you know.

what makes you now question if that solution will work after all?

EDIT - i edited where the code went and again, no joy im afraid.
i guess your thought was right about it not being the rcolour after all. although its good to have that code in there anyway.

« Last Edit: May 09, 2010, 06:20:56 PM by AWS »

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Level design/ Code questions from a beginner
« Reply #42 on: May 09, 2010, 07:05:11 PM »
Quote
what makes you now question if that solution will work after all?

Well, I checked the code for Binary Black, and that should produce negative numbers for the backdrop colour too.  But it doesn't crash.

So it must be something else...

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0
• Posts: 274
##### Re: Level design/ Code questions from a beginner
« Reply #43 on: May 09, 2010, 07:26:28 PM »
makes sense.
interesting teaser this one.
ive played this enough times now to note that it is ocurring at the the same time every time. i havent timed it on a stopwatch or anything but i know its happening after the same duration of time.
unless its something being triggered by the production/ accrual of something else, eg, number of seedlings reaches a certain number then something fatal occurs because of it, it must be time based, like you thought.

i keep going through the code but im reaching the stage where ill have to go through every little detail one by one and test it each time. which is VERY arduous.
any bright ideas there annikk?
ps, where are you in the world, are on east coast usa (like me) or in uk (my home country) or elsewhere? (i just ask to have an idea of your time zone for replies, you see...

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0