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

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Level design/ Code questions from a beginner
« on: April 04, 2010, 10:30:40 PM »
hi all,
first things first...im a complete beginner and these are my Q's to annikk.exe, and now everyone whose interested, about the real basics of making a level. i hope it helps anyone else interested in doing so, answer some of the more basic elements of design.

this is a continuation of some correspondence between myself and anikk.exe about my attempts at a first level, of anything, ever!
im moving it over from PM to public thread so everyone can see what ive been asking, running into, and the helpful solutions being given.
everyone and anyone please feel free to add their own take on things.
ill be adding to this thread whenever i hit any problems/ questions/ etc about why my code isn't working or what i would like to achieve with my level and what is needed to do it.

as i said, this is all very new to me so please excuse my ignorance.

My initial questions were 2;

---

Q1-the more important one relates to the win conditions. in your example, you set the condition that a certain asteroid has to be taken to win. however, i want to make a level where every asteroid has to be taken, not just a certain one, and i cant figure out how to change the code accordingly.

Reply -
Hmm, I guess what I would do is skip the function OnAsteroidTaken section entirely (delete or comment it out), and instead create a loop in your function LevelLogic() as follows:

Code:

while GameRunning() do

if GetEmpire(1):GetNumOwnedAsteroids() == 99999 then
Pause()
MessageBox("You have won")
WaitDialog()
Unpause()
Quit(true)
end

if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have lost")
WaitDialog()
Unpause()
Quit(false)
end


Just replace "99999" with however many asteroids are in your level.  :>

Loops like this aren't always a suitable way of setting up the win/lose condition, let me know if this method isn't going to work for the level you're making.

I tried this and it didn't work. so far i have 12 asteroids, including my own, so i typed in 12 where it said, but no luck so far.

---

Q2-
the other question is more aesthetic. ive played around with the background colour and it immediately got me thinking, is it possible to create a constantly unduataing/ pulsating loop or cycle of colours?

reply -
The command to change the background is:

SetBackdropColour(red,green,blue)

So for the red green and blue values, if youhave SetBackdropColour(255,255,255) that's white.  (0,0,0) is black.  (255,0,0) is red, and so on.

You can use variables too.  Check this out:

Code:

while GameRunning() do

rcolour = GetAsteroid(0):GetNumSeedlings(1)

if rcolour > 255 then
rcolour = 255
end

SetBackdropColour(rcolour,0,0)
coroutine.yield()
end

That code will continually check how many seedlings the player has on Asteroid ID 0, and vary the amount of red in the background accordingly.  I also put a small If statement in there, to make sure we never try to set a value of 300 or something like that - the values for the backdrop colour are only supposed to go up to 255.

So what if you want to create cyclical patterns, like in Day & Night?
One way to do it is to use mathmatical functions to create a variable that goes up and down based on the Game Time.
Here's an example of how you can do this;

Code:

while GameRunning() do

-- first we record the time
time = GetGameTime()

-- we can divide the time by a number - or multiply it - to slow down or speed up the pulses.
time = time / 3

-- now to get the pulsing effect:
x = math.sin(time)

-- x is now a value that ranges up and down between -1 and 1 over time.


-- for this example we want a value that ranges between 0 and 1.
-- so lets modify x a bit.

x = x + 1
-- now x ranges between 0 and 2
x = x / 2
-- now it ranges between 0 and 1

x = x * 255
-- now it ranges between 0 and 255

SetBackdropColour(0,0,x)
-- this will make the background pulse between black and blue.  :>

coroutine.yield()
end


Hopefully this makes things clearer :>

---

So, those were my first Q's.
I've yet to try the colour cycle but will be doing so today and will post my results up here.

In addition...

The player is always empire 1.  :>
Empire 0 is the greys, or "unclaimed" asteroids.  If you don't explicitly set an asteroid to belong to another empire it will default to belonging to Empire 0.

GetEmpire is an example of a "function".  the GetEmpire() function needs a number or variable in the brackets, or it won't work.  Functions either need some variables passed to them, or do not.  In this case we DO need to give it a number because the function needs to know which Empire we are referring to.

GetNumOwnedAsteroids() doesn't need a variable passed to it - it's a function you run on an AI or empire and it simply returns how many asteroids that empire owns.

---

Thanks to Annikk. for your help and support. and inspiration to give this thing a try.
:)

AWS

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #1 on: April 04, 2010, 10:34:59 PM »
one thing ive noticed is that whenever i get an error message when trying to load the level im working on, is the dialog box telling me 'cant load level' obscures the error message box behind it, that gives me the info as to what is causing the error. i have to peer right up to the screen to try and work out what the text says and for the most part, i can never work out what it says!

anyone else have this issue with the 2 dialog boxes on top of each other?


AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #2 on: April 04, 2010, 11:55:41 PM »
3 things -

1- what does the 'r' refer to in 'rcolour'. i see that in some of annikks code there is 'g' colour. what is the difference and why?

Code:

while GameRunning() do

rcolour = GetAsteroid(0):GetNumSeedlings(1)

if rcolour > 255 then
rcolour = 255
end

SetBackdropColour(rcolour,0,0)
coroutine.yield()
end


---
for the pulsing effect.

while GameRunning() do

-- first we record the time
time = GetGameTime()

-- we can divide the time by a number - or multiply it - to slow down or speed up the pulses.
time = time / 3

-- now to get the pulsing effect:
x = math.sin(time)

-- x is now a value that ranges up and down between -1 and 1 over time.


-- for this example we want a value that ranges between 0 and 1.
lets modify x a bit.

x = x + 1
-- now x ranges between 0 and 2
x = x / 2
-- now it ranges between 0 and 1

x = x * 255
-- now it ranges between 0 and 255

SetBackdropColour(0,0,x)
-- this will make the background pulse between black and blue.  :>

coroutine.yield()
end[/color]

2- exactly why, or how, does the (0,0,x) part make it change between black and blue? i was hoping to have a range of say, 5 colours, that gradually, after every 45 seconds of game time, merge into the next colour, and so on. i would need to use the GameTime function for this.

---

3- to add asteroids ive merely been copying and pasting the previous code, so im ending up with lots of repititious code. i see that there is another way of doing this to avoid the ugliness and lengthiness of my approach. how do you add many asteroids, while still placing them where you want, without all the repetitive copy and pasting of the same code?

---

AWS

« Last Edit: April 05, 2010, 12:03:13 AM by AWS »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #3 on: April 05, 2010, 02:48:34 AM »
more questions... :)


   t = 1600

   coordx = {}
   coordy = {}
   roidradius = {}

-What is the t = 1600 doing? is that just setting a particular letter and number value for later use? or is it specific to something?
-What are the coord and roidradius with those brackets doing?


      coordx = x
      coordy = y
   
   
      t = t + 294.5
      
      a.SendDistance = (roidradius * 7) + 1500

-What is this calculation?
Im looking for a way to set each asteroids' send distance to a percentage of the planet's size. ive got some small planets with absurdly huge distances while some big planets have almost no distance even though ive set them to what i think is right, it doesnt seem to be paying attention to it in game. hence this question.

-What is the AI Grace timer? i assume it's a minmum time before the enemy can attack you, is this correct? if so, are the values in seconds? eg.Globals.AI.GraceTimer=(120) or (9999)

AWS

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #4 on: April 05, 2010, 03:35:24 AM »
Suggest to make a cup of tea before reading this.  It will take a while, as I have answered each question In Full :>



Quote
Code: [Select]
while GameRunning() do

rcolour = GetAsteroid(0):GetNumSeedlings(1)

if rcolour > 255 then
rcolour = 255
end

SetBackdropColour(rcolour,0,0)
coroutine.yield()
end

1- what does the 'r' refer to in 'rcolour'. i see that in some of annikks code there is 'g' colour. what is the difference and why?

rcolour is just a variable i created in order to have something by which to refer to the amount of Red in the background colour.
You can see where I create it initially:

rcolour = GetAsteroid(0):GetNumSeedlings(1)

...and then where I use it later - instead of a fixed number - to set the amount of Red in the background colour:

SetBackdropColour(rcolour,0,0)


So you see, you can create a variable with a name of your choosing simply by "declaring" what it's value is.
In this example we created a variable called rcolour when we wrote that it should be equal to the number of Seedlings belonging to player 1 on Asteroid ID 0.

The reason I chose to call it "rcolour" is because it's a nice shorthand way of writing "the amount of red".  I could just as easily have called it "redamount", or simply "red", and it would work fine.


Another important thing to understand is that All Variables Equal Nil Until You Declare Otherwise.
Nil is not the same thing as 0.
Nil means "no value".

This can be useful, for example if you want to check if something has happened.  If say, the player moves a certain number of seedlings to an asteroid, you can create a trap for this with a "if, then, else" command, and the result will be to declare a variable like this: Fluffy = 0.
Then later on you can check If Fluffy == Nil and if that is true, then you will be able to say that the player hasn't moved that number of seedlings to the asteroid yet.  But if the value of Fluffy was not nil, but 0, then we know that the player HAS moved that number of seedlings to the target asteroid.

For practical purposes it's often useful to invert it, and say if the value of Fluffy is NOT equal to Nil, then do something... else do nothing.  You do that by using ~= instead of ==.
So:
== Is Equal To
~= Is NOT Equal To



Oh and by the way, gcolour as you may have guessed by now was simply the variable I created in order to control the amount of Green in the background colour.  :>
So it would have been like this:

SetBackdropColour(rcolour,gcolour,bcolour)








Quote
2- exactly why, or how, does the (0,0,x) part make it change between black and blue? i was hoping to have a range of say, 5 colours, that gradually, after every 45 seconds of game time, merge into the next colour, and so on. i would need to use the GameTime function for this.

(0,0,x) is key for the following reason: the 0,0 is fixed, but x is a variable.  That means its value can change during the course of play.  As opposed to the 0,0 which are fixed and will stay the same through the whole game.

To understand the whole, you have to understand each of the parts.

When the game loads, it runs all of the commands in function LevelSetup().  Then the game begins, the player may start to give orders to their seedlings etc, and the function LevelLogic() part of the level kicks in.

The While GameRunning() do command is used right at the start of the function LevelLogic() section.
The end of the While GameRunning() do section is signified by:

coroutine.yield()
end


This command basically says "While the game is running, continually run the commands in this section".


So take a moment to imagine this: The game is continously running these commands, and depending on the number of commands it has to run it may do so several hundred or thousand times a second.

Now we start to imagine the commands we are putting into this section in a different way - it is as if they are tiny slices of time.

Each "game cycle", as I like to refer to them as, we declare that the variable time is equal to the Game Time.
So imagine as the game constantly refreshes the value of the time, each cycle increasing it by a tiny tiny fraction of a millisecond.

Now we have a variable that we can plug into a function.  :>

Immedietely, we could do this:

SetBackdropColour(time,time,time)

So that would mean when the game starts, it sets the value of time and it's basically 0 because the Game Time on the very first game cycle will be pretty much 0.  So it would then set the backdrop command to near enough (0,0,0) which is Black.  It would set the backdrop to (0,0,0) because the value of time is 0 and we are setting it as (time,time,time) in the command we used.


But then, as the game goes on, say after one minute (ie 60 seconds), the value of time is constantly refreshed and is now way up at 60.  That means we'll be getting a backdrop(60,60,60) which is dark grey!  You will actually be able to see the background colour becoming gradually whiter and whiter as the game time goes up, and the value of the time variable goes up.

After about 4 minutes the background will be completely white... and once the game time is over 255 seconds the behaviour may be unpredictable :P



Now we have a variable called time that increases as time goes by.
This is useful for lots of things, but there are some circumstances where we want a variable that goes up and down as time goes by... rather than just increasing forever.

To make a variable that does this, we need to use some clever maths.  That's where the math.sin function comes in.

Hmm.  I have realised just now that I picked a bit of an unfortunate variable name "x".  Lets pretend it was actually called "bcolour" - that will be less confusing...

So the complete function LevelLogic() code would be like this:

Code: [Select]
function LevelLogic()
  while GameRunning() do

    -- first we record the time
    time = GetGameTime()

    -- we can divide the time by a number - or multiply it - to slow down or speed up the pulses.
    time = time / 3

    -- now to get the pulsing effect:
    bcolour = math.sin(time)

    -- bcolour is now a value that ranges up and down between -1 and 1 over time.


    -- for this example we want a value that ranges between 0 and 1.
    -- lets modify bcolour a bit.

    bcolour = bcolour + 1
    -- now bcolour ranges between 0 and 2

    bcolour = bcolour / 2
    -- now it ranges between 0 and 1

    bcolour = bcolour * 255
    -- now it ranges between 0 and 255

    SetBackdropColour(0,0,bcolour)
    -- this will make the background pulse between black and blue.  :>

    coroutine.yield()
  end
end





Do you remember in maths class drawing graphs of Y = Sin(X) ?  Perhaps not, but if you plot this equation on a graph then this is what it will look like:






It's a wavy line.  It pulses as a perfect spectral wave, free from spikes and jitters!  Beautiful to crazy mathematician types, and very useful for creating pulsing effects in levels.

So how do we use this crazy beast?  Well, like all mathematical formulas, you basically just plug in the numbers you want and away you go.



Y = Sin(X)

..becomes..

bcolour = Sin(time)



So now we are basically saying that the up and down motion on that graph is equal to bcolour.  The X-Axis on the graph is time, or in our case literally our variable called time.

So what you _actually_ get for bcolour from that command, is a value that goes between 1 and -1.  The very top of the curve on the graph is 1, and the very bottom is -1, with 0 being the horizontal axis.  Try to look at the graph and visualise this - horizontal is time, vertical is resulting value of bcolour.  You need to understand this in order to understand how the pulsing effect works.


Then we just do a bit more arithmetic on the variable to modify the number to be more useful, and we are able to create a variable with a value that ranges between 0 and 255.  :>

Then, finally, we simply plug that variable into the command like so:

SetBackdropColour(0,0,bcolour)

And voila, at the bottom of the curve (bcolour = 0) we will get (0,0,0) which is black, and at the top of the curve (bcolour = 255) we will get (0,0,255) which is blue.  :>






Quote
3- to add asteroids ive merely been copying and pasting the previous code, so im ending up with lots of repititious code. i see that there is another way of doing this to avoid the ugliness and lengthiness of my approach. how do you add many asteroids, while still placing them where you want, without all the repetitive copy and pasting of the same code?

You can add asteroids in lots of different ways.
You can place them one by one by writing out their positions and attributes individually.
Or you can use the inbuilt AddAsteroidRing(number of Asteroids, X-coordinate of the center, Y-coordinate of the centre, overall radius of the ring, width of the ring)

The way I did it in Day & Night, and also for Infected Empire, is to use a for loop.
That basically says, "for this number of times, run these commands" - similar to the "While" loop we talked about earlier, but it also lets you use "this" as a variable.  So you can count which pass you are on.
So in Day & Night the For loop looked like this:

for i=1,21 do

So I'm saying, "run all of the below commands, and each time you run them, increment "i" by one, until you reach 21, then stop".
The "1" refers to the number to start counting FROM.  Sometimes its more useful to start counting 0,1,2,3,4,5,6... instead of 1,2,3,4,5,6...


This leads perfectly onto the next question....



Quote
4- What is the t = 1600 doing? is that just setting a particular letter and number value for later use? or is it specific to something?

...then, for the commands nestled inside my For loop, I plugged in the mathematical formula for a spiral, and used the "t" value as the "period", or the amount to go further round the spiral before plopping the next asteroid down.

So I made my asteroids coordinates with this spiral command:

x = math.cos(t) * t
y = math.sin(t) * t


and then each time it runs through the For loop, it also does this:

t = t + 275

t is the amount further round the spiral we shall travel, before we lay another an asteroid thusly:

a = AddAsteroidWithAttribs(x,y,s,e,sp)

x and y for each asteroid are thus calculated based on the period t which is incremented on every pass of the For loop, i.


To be honest this was quite advanced - maybe it would be better to make some basic maps first before you start worrying about procedural generation :P





Will start a new post to answer the rest.
« Last Edit: April 05, 2010, 07:02:50 PM by annikk.exe »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #5 on: April 05, 2010, 04:06:39 AM »
 :-\ sorry!

i have another question.

ive been trying to get this win condition you suggested, annikk, to work. so far ive tried two versions.
one results in an instant 'you have lost' message, the other, the one below, results in an instant 'you have won' message! seems weird, imo! the error that it displays is
'Attempt to yield across metamethod/ C-call boundary', in both cases.

the code causing the instant win dialog box is;

while GameRunning() do

   if GetEmpire(2):GetNumOwnedAsteroids() == 0 then
      
   Pause()
   MessageBox("you have won.")
   WaitDialog()
   Unpause()
   Quit(true)
   end

   if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
   Pause()
   MessageBox("You have lost")
   WaitDialog()
   Unpause()
   Quit(false)
   end

coroutine.yield()
end


So - in light of this, in order to make my eventual finished map more interesting, i wanted about 2 or 3 different enemies. this will no doubt have an impact on the coding of the win condition.
erm... any help with that one?

 :-[

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #6 on: April 05, 2010, 04:22:05 AM »
I'm still working on the other questions but the most likely reason for an instant win is that the terms of the If statement are being met.

Does Empire 2 own any asteroids during the first millisecond of the game?

If you post the entire level code in "[ code]" tags I'll check it for you :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #7 on: April 05, 2010, 04:33:22 AM »
this is the whole thing so far. it feels kinda naked, revealing ALL the code, but it's certainly nothing special. some of the globals are pulled directly from one of your maps without me really knowing what it means!  ::)
asteroids 4 and 10 have 0 as the owner, all the rest have 2. id like to add 1 or 2 more enemy races before its finished. but all the roids are inhabited on game start.

Code: [Select]
function LevelSetup()

-- Set Global Values
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(1)
Globals.G.EnemyFactionsMax=(1)
Globals.Asteroids.SpawnCap=100
Globals.Asteroids.SeedlingCap=5000
Globals.Asteroids.MinSendDistance=0.5
Globals.Asteroids.MaxSendDistance=0.5
Globals.AI.GraceTimer=(120)

SetBackdropColour (101,250,155)


-- Asteroid 0 - my starting asteroid
a = AddAsteroidWithAttribs(0,0, 0.8,0.6,0.7)
a.Owner = 1
a.TreeCap = 5
a:SetRadius(550)
a.SendDistance = 2100

a:AddSeedlings(77)
a.Moveable = False


-- Asteroid 1 - winning asteroid --1st Giant Planet
b = AddAsteroidWithAttribs(7000,1500, 0.6,0.8,0.2)
b.Owner = 2
b.TreeCap = 7
b:SetRadius(995)
b.SendDistance = 1500
s = b:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
b:AddSeedlings(39)
b.Moveable = False


-- Asteroid 2
b = AddAsteroidWithAttribs(1500,1900, 0.2,0.3,0.1)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(450)
b.SendDistance = 650

b:AddSeedlings(20)
b.Moveable = False

-- Asteroid 3
b = AddAsteroidWithAttribs(-1600,-850, 0.1,0.5,0.8)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(250)
b.SendDistance = 250

b:AddSeedlings(10)
b.Moveable = False

-- Asteroid 4
b = AddAsteroidWithAttribs(-1700,2100, 0.5,0.5,0.1)
b.Owner = 0
b.TreeCap = 3
b:SetRadius(450)
b.SendDistance = 600

b:AddSeedlings(25)
b.Moveable = False

-- Asteroid 5
b = AddAsteroidWithAttribs(2500,800, 0.1,0.4,0.6)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(150)
b.SendDistance = 100

b:AddSeedlings(18)
b.Moveable = False

-- Asteroid 6
b = AddAsteroidWithAttribs(3200,2200, 0.1,0.3,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(400)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 7
b = AddAsteroidWithAttribs(2000,-2900, 0.2,0.3,0.5)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(200)
b.SendDistance = 7000

b:AddSeedlings(4)
b.Moveable = False

-- Asteroid 8
b = AddAsteroidWithAttribs(1900,-900, 0.4,0.2,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(420)
b.SendDistance = 600

b:AddSeedlings(0)
b.Moveable = False

-- Asteroid 9
b = AddAsteroidWithAttribs(2900,-2100, 0.4,0.3,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(350)
b.SendDistance = 1000


-- Asteroid 10
b = AddAsteroidWithAttribs(-2900,-1900, 0.4,0.4,0.6)
b.Owner = 0
b.TreeCap = 3
b:SetRadius(200)
b.SendDistance = 700

b:AddSeedlings(0)
b.Moveable = False

-- Asteroid 11
b = AddAsteroidWithAttribs(-1800,-2600, 0.4,0.3,0.4)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(320)
b.SendDistance = 700

b:AddSeedlings(15)
b.Moveable = False

-- Asteroid 12
b = AddAsteroidWithAttribs(100,-3100, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 200

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 13
b = AddAsteroidWithAttribs(-3300,-1200, 0.4,0.3,0.4)
b.Owner = 0
b.TreeCap = 4
b:SetRadius(320)
b.SendDistance = 600

b:AddSeedlings(15)
b.Moveable = False

-- Asteroid 14
b = AddAsteroidWithAttribs(800,3100, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 15 -- 2nd Giant planet
b = AddAsteroidWithAttribs(-5500,-4500, 0.8,0.7,0.8)
b.Owner = 2
b.TreeCap = 7
b:SetRadius(995)
b.SendDistance = 1500
s = b:AddDysonTree()
s:LevelUp()
s:LevelUp()
b:AddSeedlings(7)
b.Moveable = False

-- Asteroid 16
b = AddAsteroidWithAttribs(-2800,2400, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False

end


function LevelLogic()


-- Greeting
Timer = GetGameTime() + 3


while GetGameTime() < Timer do

coroutine.yield()
end

Pause()
MessageBox("Greetings... ")
WaitDialog()
Unpause()


end


-- Victory Trigger

while GameRunning() do

if GetEmpire(2):GetNumOwnedAsteroids() == 0 then

Pause()
MessageBox("you have won.")
WaitDialog()
Unpause()
Quit(true)
end

if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have lost")
WaitDialog()
Unpause()
Quit(false)
end

coroutine.yield()
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #8 on: April 05, 2010, 04:56:27 AM »
Ok the reason why that doesn't work properly is that your winning/losing code is outside of the function LevelLogic().  It is outside it because it appears AFTER the "end" that closes off the function LevelLogic().

Here's a fixed version.  :>


Code: [Select]
function LevelSetup()

-- Set Global Values
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(1)
Globals.G.EnemyFactionsMax=(1)
Globals.Asteroids.SpawnCap=100
Globals.Asteroids.SeedlingCap=5000
Globals.Asteroids.MinSendDistance=0.5
Globals.Asteroids.MaxSendDistance=0.5
Globals.AI.GraceTimer=(120)

SetBackdropColour (101,250,155)


-- Asteroid 0 - my starting asteroid
a = AddAsteroidWithAttribs(0,0, 0.8,0.6,0.7)
a.Owner = 1
a.TreeCap = 5
a:SetRadius(550)
a.SendDistance = 2100

a:AddSeedlings(77)
a.Moveable = False


-- Asteroid 1 - winning asteroid --1st Giant Planet
b = AddAsteroidWithAttribs(7000,1500, 0.6,0.8,0.2)
b.Owner = 2
b.TreeCap = 7
b:SetRadius(995)
b.SendDistance = 1500
s = b:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
b:AddSeedlings(39)
b.Moveable = False


-- Asteroid 2
b = AddAsteroidWithAttribs(1500,1900, 0.2,0.3,0.1)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(450)
b.SendDistance = 650

b:AddSeedlings(20)
b.Moveable = False

-- Asteroid 3
b = AddAsteroidWithAttribs(-1600,-850, 0.1,0.5,0.8)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(250)
b.SendDistance = 250

b:AddSeedlings(10)
b.Moveable = False

-- Asteroid 4
b = AddAsteroidWithAttribs(-1700,2100, 0.5,0.5,0.1)
b.Owner = 0
b.TreeCap = 3
b:SetRadius(450)
b.SendDistance = 600

b:AddSeedlings(25)
b.Moveable = False

-- Asteroid 5
b = AddAsteroidWithAttribs(2500,800, 0.1,0.4,0.6)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(150)
b.SendDistance = 100

b:AddSeedlings(18)
b.Moveable = False

-- Asteroid 6
b = AddAsteroidWithAttribs(3200,2200, 0.1,0.3,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(400)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 7
b = AddAsteroidWithAttribs(2000,-2900, 0.2,0.3,0.5)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(200)
b.SendDistance = 7000

b:AddSeedlings(4)
b.Moveable = False

-- Asteroid 8
b = AddAsteroidWithAttribs(1900,-900, 0.4,0.2,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(420)
b.SendDistance = 600

b:AddSeedlings(0)
b.Moveable = False

-- Asteroid 9
b = AddAsteroidWithAttribs(2900,-2100, 0.4,0.3,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(350)
b.SendDistance = 1000


-- Asteroid 10
b = AddAsteroidWithAttribs(-2900,-1900, 0.4,0.4,0.6)
b.Owner = 0
b.TreeCap = 3
b:SetRadius(200)
b.SendDistance = 700

b:AddSeedlings(0)
b.Moveable = False

-- Asteroid 11
b = AddAsteroidWithAttribs(-1800,-2600, 0.4,0.3,0.4)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(320)
b.SendDistance = 700

b:AddSeedlings(15)
b.Moveable = False

-- Asteroid 12
b = AddAsteroidWithAttribs(100,-3100, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 200

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 13
b = AddAsteroidWithAttribs(-3300,-1200, 0.4,0.3,0.4)
b.Owner = 0
b.TreeCap = 4
b:SetRadius(320)
b.SendDistance = 600

b:AddSeedlings(15)
b.Moveable = False

-- Asteroid 14
b = AddAsteroidWithAttribs(800,3100, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 15 -- 2nd Giant planet
b = AddAsteroidWithAttribs(-5500,-4500, 0.8,0.7,0.8)
b.Owner = 2
b.TreeCap = 7
b:SetRadius(995)
b.SendDistance = 1500
s = b:AddDysonTree()
s:LevelUp()
s:LevelUp()
b:AddSeedlings(7)
b.Moveable = False

-- Asteroid 16
b = AddAsteroidWithAttribs(-2800,2400, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False

end


function LevelLogic()


-- Greeting
Timer = GetGameTime() + 3


while GetGameTime() < Timer do

coroutine.yield()
end

Pause()
MessageBox("Greetings... ")
WaitDialog()
Unpause()


-- Victory Trigger

while GameRunning() do

if GetEmpire(2):GetNumOwnedAsteroids() == 0 then

Pause()
MessageBox("you have won.")
WaitDialog()
Unpause()
Quit(true)
end

if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have lost")
WaitDialog()
Unpause()
Quit(false)
end

coroutine.yield()
end




end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #9 on: April 05, 2010, 05:16:11 AM »
Quote
Code: [Select]

   coordx = {}
   coordy = {}
   roidradius = {}


5- What are the coord and roidradius with those brackets doing?

That's me initialiasing a data structure called an Array.

An array is like a variable that has multiple different slots.

So for example, Fluffy[15] refers to a variable called Fluffy, with the value at slot number 15.



Here's a simple example of using arrays:

Code: [Select]
Fluffy = {}

for i = 1,5 do

Fluffy[i] = GetAsteroid(i):GetNumSeedlings(1)

end

That runs a For loop 5 times, and each time it makes the corresponding slot of Fluffy equal to the number of seedlings on Asteroid ID i.

So Fluffy[3] will be equal to the number of seedlings belonging to the player present on Asteroid ID 3.
So Fluffy[4] will be equal to the number of seedlings belonging to the player present on Asteroid ID 4.
and so on.

Arrays are useful for some more advanced stuff.




Quote
Code: [Select]
a.SendDistance = (roidradius * 7) + 1500
6- What is this calculation?  Im looking for a way to set each asteroids' send distance to a percentage of the planet's size. ive got some small planets with absurdly huge distances while some big planets have almost no distance even though ive set them to what i think is right, it doesnt seem to be paying attention to it in game. hence this question.

Earlier on in the code, I did some maths to calculate the radius of each asteroid based on its distance from the centre of the galaxy, and its energy, strength and speed.
The result of this maths is summarised in the variable roidradius which I then used to set the radius of each asteroid, like this:

a:SetRadius(roidradius)


I then decided I wanted to base the Send Distance of the asteroid off it's radius - seems pretty sensible.  So I did a.SendDistance = roidradius but of course that means that the Send Distance is tiny.  So I changed it to be a.SendDistance = roidradius * 10 and that was much more like it.
There was a problem though - very large asteroids had ridiculously huge send distances, and tiny asteroids had tiny send distances.
So to make it a bit more balanced in that regard, I changed it to a.SendDistance = (roidradius * 7) + 1500 and this means large asteroid send distances are not quite so huge, and tiny asteroids have a guaranteed minimum of 1500.  This seemed to work good.  :>



Quote
7- -What is the AI Grace timer? i assume it's a minmum time before the enemy can attack you, is this correct? if so, are the values in seconds? eg.Globals.AI.GraceTimer=(120) or (9999)

The Grace Timer is the amount of time until the default, inbuilt AI is allowed to start "using" an asteroid.
If you set a Global Grace Timer, the AI will be unable to do anything at all, until the timer is up.

If you set Globals.AI.GraceTimer=(99999) the AI will never get to use any asteroids and is effectively switched off.

You can also set grace timers on individual asteroids, this can be useful sometimes if you want some AI-owned asteroids to remain inactive until a certain point.
« Last Edit: April 06, 2010, 01:58:56 AM by annikk.exe »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #10 on: April 05, 2010, 05:43:00 AM »
 :o
well, that was indeed very thorough. thank you very much.

i copied back your revised code and tried to load- guess what, no cigar!it wont load. with those 2 end's at the end, an error pops up saying '236: <eof> expected near 'end' ' -so i go to line 236, remove the end, and of course, i have no closing 'end' for the function section, and it wont load. bit a catch 22 there.

seems im a little stuck with this. of course, until i can sort this out i cant get on with fathoming that pulsating business. (to be honest, maths was not my strong point at school. far far from it...)

also, am i right in thinking that if i do a GetGlobalAsteroids with SendDistance, i can set up my own sum for setting the distance of all the asteroids without having to manually do each one?
something like,

a.SendDistance = GetGlobalAsteroidsRadius * 7 + 1500
to use your figures.

that doesnt look right to me after all, but i hope you can what im trying to do with it - im trying to say, find all the asteroids' radii, then set the send distance with the following sum.

---
i think ill have that tea now...
AWS

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #11 on: April 05, 2010, 05:49:05 AM »
Proof-read the first reply and fixed lots of errors.  Try the updated code in it!  :>

I will test all of the code I put in here later tonight, and fix any bits that don't work.

njursten

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
Re: Level design/ Code questions from a beginner
« Reply #12 on: April 05, 2010, 06:13:49 AM »
FYI, I'd keep the win/loss logic in the OnAsteroidTaken function. There's no point in rechecking the number of owned asteroids if there's hasn't been a change of ownership for an asteroid. If you want it to depend on the number of seedlings left you'd need to move it to the LevelLogic function though.

Too damn much text in here so I didn't read it all, but if annikk didn't tell you: To see the error message when a level fails to load, press the ~ key (left of 1 key). You'll see a list of all error messages since the game was started. You can enter commands here also, but it's not that useful. You can check variable values and stuff like that though.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #13 on: April 05, 2010, 06:21:56 AM »
Quote
   -- Asteroid 1 - winning asteroid --1st Giant Planet
   b = AddAsteroidWithAttribs(7000,1500, 0.6,0.8,0.2)

This will not work well.. the asteroid is placed too far away.  Try 6000,1500 maybe?

This was preventing the level from loading on my computer.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #14 on: April 05, 2010, 06:38:59 AM »
Asteroid 8 was also preventing the level from loading for me.  I had to remove the command b.Moveable = true


Here it is, confirmed working:


Code: [Select]
function LevelSetup()

-- Set Global Values
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(1)
Globals.G.EnemyFactionsMax=(1)
Globals.Asteroids.SpawnCap=100
Globals.Asteroids.SeedlingCap=5000
Globals.Asteroids.MinSendDistance=0.5
Globals.Asteroids.MaxSendDistance=0.5
Globals.AI.GraceTimer=(120)

SetBackdropColour (101,250,155)


-- Asteroid 0 - my starting asteroid
a = AddAsteroidWithAttribs(0,0, 0.8,0.6,0.7)
a.Owner = 1
a.TreeCap = 5
a:SetRadius(550)
a.SendDistance = 2100

a:AddSeedlings(77)
a.Moveable = False


-- Asteroid 1 - winning asteroid 1st Giant Planet
b = AddAsteroidWithAttribs(6000,1500, 0.6,0.8,0.2)
b.Owner = 2
b.TreeCap = 7
b:SetRadius(995)
b.SendDistance = 1500
s = b:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
b:AddSeedlings(39)
b.Moveable = False


-- Asteroid 2
b = AddAsteroidWithAttribs(1500,1900, 0.2,0.3,0.1)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(450)
b.SendDistance = 650

b:AddSeedlings(20)
b.Moveable = False


-- Asteroid 3
b = AddAsteroidWithAttribs(-1600,-850, 0.1,0.5,0.8)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(250)
b.SendDistance = 250

b:AddSeedlings(10)
b.Moveable = False


-- Asteroid 4
b = AddAsteroidWithAttribs(-1700,2100, 0.5,0.5,0.1)
b.Owner = 0
b.TreeCap = 3
b:SetRadius(450)
b.SendDistance = 600

b:AddSeedlings(25)
b.Moveable = False


-- Asteroid 5
b = AddAsteroidWithAttribs(2500,800, 0.1,0.4,0.6)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(150)
b.SendDistance = 100

b:AddSeedlings(18)
b.Moveable = False

-- Asteroid 6
b = AddAsteroidWithAttribs(3200,2200, 0.1,0.3,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(400)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False


-- Asteroid 7
b = AddAsteroidWithAttribs(2000,-2900, 0.2,0.3,0.5)
b.Owner = 2
b.TreeCap = 3
b:SetRadius(200)
b.SendDistance = 7000

b:AddSeedlings(4)
b.Moveable = False



-- Asteroid 8
b = AddAsteroidWithAttribs(1900,-900, 0.4,0.2,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(420)
b.SendDistance = 600

b:AddSeedlings(0)



-- Asteroid 9
b = AddAsteroidWithAttribs(2900,-2100, 0.4,0.3,0.5)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(350)
b.SendDistance = 1000


-- Asteroid 10
b = AddAsteroidWithAttribs(-2900,-1900, 0.4,0.4,0.6)
b.Owner = 0
b.TreeCap = 3
b:SetRadius(200)
b.SendDistance = 700

b:AddSeedlings(0)
b.Moveable = False

-- Asteroid 11
b = AddAsteroidWithAttribs(-1800,-2600, 0.4,0.3,0.4)
b.Owner = 2
b.TreeCap = 4
b:SetRadius(320)
b.SendDistance = 700

b:AddSeedlings(15)
b.Moveable = False

-- Asteroid 12
b = AddAsteroidWithAttribs(100,-3100, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 200

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 13
b = AddAsteroidWithAttribs(-3300,-1200, 0.4,0.3,0.4)
b.Owner = 0
b.TreeCap = 4
b:SetRadius(320)
b.SendDistance = 600

b:AddSeedlings(15)
b.Moveable = False

-- Asteroid 14
b = AddAsteroidWithAttribs(800,3100, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False

-- Asteroid 15 -- 2nd Giant planet
b = AddAsteroidWithAttribs(-5500,-4500, 0.8,0.7,0.8)
b.Owner = 2
b.TreeCap = 7
b:SetRadius(995)
b.SendDistance = 1500
s = b:AddDysonTree()
s:LevelUp()
s:LevelUp()
b:AddSeedlings(7)
b.Moveable = False

-- Asteroid 16
b = AddAsteroidWithAttribs(-2800,2400, 0.4,0.5,0.4)
b.Owner = 2
b.TreeCap = 2
b:SetRadius(210)
b.SendDistance = 500

b:AddSeedlings(11)
b.Moveable = False



end


function LevelLogic()


-- Greeting
Timer = GetGameTime() + 3


while GetGameTime() < Timer do

coroutine.yield()
end

Pause()
MessageBox("Greetings... ")
WaitDialog()
Unpause()


-- Victory Trigger

while GameRunning() do

if GetEmpire(2):GetNumOwnedAsteroids() == 0 then

Pause()
MessageBox("you have won.")
WaitDialog()
Unpause()
Quit(true)
end

if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have lost")
WaitDialog()
Unpause()
Quit(false)
end

coroutine.yield()
end




end

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #15 on: April 05, 2010, 08:46:30 AM »
Argh! thank you for getting it to load! i wonder why it mattered that certain asteroids were too far away. its going to be expanded in all directions so im not sure how the spacing works then. thanks again. i think ill leave it now till tomorrow.


annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #16 on: April 05, 2010, 03:53:55 PM »
No worries.  Let us know how you get on :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #17 on: April 05, 2010, 07:17:52 PM »
this is the whole thing so far. it feels kinda naked, revealing ALL the code, but it's certainly nothing special. some of the globals are pulled directly from one of your maps without me really knowing what it means!  :)

Don't worry about copying my globals.  I copied mine from someone else's map too when I was learning!  :>  Totally allowed.

Also I noticed I missed out this question:

Quote
So - in light of this, in order to make my eventual finished map more interesting, i wanted about 2 or 3 different enemies. this will no doubt have an impact on the coding of the win condition.
erm... any help with that one?

Well you need to define in your own words what the condition of winning should be.
So for example, in my own words, the win/lose conditions at the moment are:

  • If Empire 2 doesn't own any asteroids, the Player wins.
  • If the Player doesn't own any asteroids, the Player loses.


So basically figure out what you would prefer it to be.  Here's my suggestion:

  • If the player owns all the asteroids, the player wins.
  • If the player owns 0 asteroids, the player loses.


So now we simply convert this to code:


Code: [Select]
If GetEmpire(1):GetNumOwnedAsteroids() == 99999 then
Quit(true)
end

If GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Quit(false)
end

Just change 99999 to however many asteroids are in your level.  You can also add Pause() and MessageBox() commands to taste.  :>
« Last Edit: April 05, 2010, 07:22:42 PM by annikk.exe »

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Level design/ Code questions from a beginner
« Reply #18 on: April 06, 2010, 05:59:49 PM »
Many thanks to annikk.exe and njursten for helping out here!

I've had a look but couldn't tell; is there anything unanswered that I can help with?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #19 on: April 06, 2010, 06:07:59 PM »
Think we've covered everything so far Alex.. :>  Just waiting to hear how AWS is doing with it.  Hopefully my huge amount of words hasn't scared him off.. :P

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #20 on: April 07, 2010, 07:01:22 AM »
:) nope. no scaring away i assure you. far from it. im extremely grateful this is such a friendly place and peoples quesitons, not just mine by any means, aren't shot down for being a noob, or whatever.

ive been taking in some sunshine since i last posted because its been getting up to the high 80's F/30C so i thought i should get some much needed vitamin d.
BUT - after going over the lovely sin wave graph and the associated code to make the background change colour, i plugged in the first half of it (the stuff before the graph, and it all worked perfectly. i was so pleased that it didnt require umpteen number of reloads, change one number, error, quit, edit, reload, etc. it was quite nice to see it work first time for a change.

so..after watching my creation wave between several colours for a few minutes, i went on the next bit about setting the colour variable to sin(time), the bit after the graph..
the
y = Sin(X)

..becomes..

bcolour = Sin(time)

bit.
i put that in with the previous code and instead, while the level loaded ok, the background just stayed white. so, im not sure how the second part of your instructions are meant to tie in with the first half, but the first bit works and the second, as i did it, didn't. i thought that maybe some of the prior code needed to be removed and the above code put in somethings place.
but thats ok for now. im just pleased ive got this far. im going to have a play with setting all the RGB values, not just one, with the code and see how that plays out.

i will say though that im going to have more Q's quite soon so.. be warned!  :-\

thanks once again to one and all.

ps- i did find the ~ key for the error log. its useful :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #21 on: April 07, 2010, 03:59:28 PM »
y = Sin(X)

..becomes..

bcolour = Sin(time)

It should actually be bcolour = math.sin(time)  :>


edit - just spent some time figuring out what it is you might have done.
I think what has probably happened is you have placed this additional code outwith the bounds of the While GameRunning() do loop.  So it's not being run on each game cycle - in theory it will run when the While loop ends, which can only happen when the game is no longer running... so basically code placed below the end of a While GameRunning() do loop will never run.

It's also possible that you are inadvertantly overwriting the value of a variable or something like that.  If you can't get it to work, post your function LevelLogic() up, and I'll have a look :>
« Last Edit: April 07, 2010, 04:15:05 PM by annikk.exe »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #22 on: April 10, 2010, 04:04:36 AM »
:)
lol
im very happy!

i did this code, erm, kind of, by myself. and it gives the effect i want. of course, if i could tweak it to my preferred level of absolute perfection, i would do so, but for now, considering it's taken me a bloody long time, and lots of questioning to get this far, im really very pleased with it. heres the code that gives a seemingly random background colour wave. it changes with enough variation over time to satisfy me for now. i think it's a bit quick still, and is in need of more subtlety (less garishness), but thats for the near future.

heres the code...

while GameRunning() do

   rtime = GetGameTime()    -- setting the variable 'time' to whatever the game time is
   rtime = rtime / 12     -- taking that 'time' variable and dividing it by n.  divide slows down. multiply speeds up.
   gtime = GetGameTime()
   gtime = gtime / 6
   btime = GetGameTime()
   btime = btime / 24


   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 * 195  -- 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 * 235
   bcolour = math.sin(btime)
   bcolour = bcolour * 165

   --rcolour = math.sin(rtime)
   --gcolour = math.sin(gtime)
   --bcolour = math.sin(btime)


   SetBackdropColour(rcolour,gcolour,bcolour)

   coroutine.yield()
   end   

ignore the comments, thats just for me, trying to make sense of it all! but as you can see, ive commented out that 'y = math.sin(time)' stuff, as that made it fade immediately to black, and nothing else. however, with it removed, it does what i wanted so there you go! :)

ofcourse, i fully expect that a constantly changing background isnt for everyone, or even anyone!, but i wanted to see what could be done with it, and im learning exactly that, in its simplest form.

if i could, i would like to able to have it be more 'random' with the colour range, because as you can see, i have to set the ranges of the wave in stone. a varying variable like that might do more of what i would ideally want.

so...i thought i would post my latest, and happiest, discoveries!

AWS

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #23 on: April 10, 2010, 07:54:58 AM »
Awesome dude :>  Thanks for letting us know !  Really cool to see people making new stuff :>

Regarding the commented out bit.... at that point you already have your rcolour, gcolour and bcolour variables ready to plug into the SetBackdropColour... if you try to math.sin them again you will end up with a value between 1 and -1 again.  So basically the colour will have been 0,0,0 which is black... or at most, 1,1,1 which is still basically black :P


Remember:

math.sin(ANY NUMBER, EVEN A HUGE ONE) = a value between 1 and -1.


May I try out your code? :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #24 on: April 10, 2010, 11:06:06 PM »
Awesome dude :>  Thanks for letting us know !  Really cool to see people making new stuff :>



May I try out your code? :>

of course...ive taken enough from yours that i think its only fair! ::)
(i was going to ask your permission to use your long AI coding on my map to see how it works?!)


EDIT - code now works properly.-thanks. so, first ever level mk.1 is now complete!!
mk.2 will be 'with additions' (ie, more roids and some more globals code for less randomness!) :)
« Last Edit: April 10, 2010, 11:45:01 PM by AWS »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #25 on: April 11, 2010, 02:58:49 AM »
 ::)

right...
i have some Q's that id be interested in hearing the answer to. and, somewhat crucially, how it would be applied in an example.

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?
2-what is a 'float' value? and what is an 'int' value?
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.**

thats all for now... :)
thanks.

AWS

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #26 on: April 11, 2010, 05:31:20 AM »
well...after much frustrating nonsense and testing..i still cant decide what my map is actually like!! but i reckon its near completion so soon enough there will be another map gracing this fine forum for anyone daring enough to take it on.

in the meantime i have two questions..

1-is it possible to 'sticky' a particular thread on the forums, so that i can access it quickly without having to search through and find it each time? like, some sort of dashboard in ones profile where you can store a few threads for continued personal reference. that would be a nice feature if it isnt one??
- moderators, could it be added?

2-how do i upload a map here?
before i do that though,  if anyone is interested in testing my map  ???, pointing out any major issues, please let me know, on here or in a pm. id be really happy to release a map that people will enjoy so any testers will be welcome. let me know folks...
but, until someone can point out how to upload the single .lua file, all i can think of is to copy and paste all my code, which isnt good!

?

AWS

 :D

njursten

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
Re: Level design/ Code questions from a beginner
« Reply #27 on: April 11, 2010, 08:29:08 PM »
When writing a post there is link called "Additional Options...". Press that one and a new field will appear where you can select a file.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #28 on: April 12, 2010, 03:19:57 AM »
When writing a post there is link called "Additional Options...". Press that one and a new field will appear where you can select a file.

thank you.

Mihhaelo

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 67
Re: Level design/ Code questions from a beginner
« Reply #29 on: April 12, 2010, 07:15:58 AM »
Quote
Argh! thank you for getting it to load! i wonder why it mattered that certain asteroids were too far away. its going to be expanded in all directions so im not sure how the spacing works then. thanks again. i think ill leave it now till tomorrow.

When the game opens up a file, it sets up the map. When it does this it scans through all the planets to make sure they are "connected" to the other planets. If the maximum send-distance, maxasteroidneighbour distance, etc is too low in the globals and it is unable to connected a planet to at least one other planet it will refuse to load. You can get around this by changing the values in globals or by manually setting SendDistance values so that every planet is within range of each other. As long as planets are connected, you can go upto silly coordinates like, -100000,-100000  :D

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #30 on: April 12, 2010, 08: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
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #31 on: May 06, 2010, 02:37:48 AM »
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
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #32 on: May 06, 2010, 03:19:34 AM »
0 is uninhabited, or "barren", which is also the greys.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #33 on: May 06, 2010, 07:34:55 AM »
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
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #34 on: May 06, 2010, 11:40:07 PM »
Your understanding is correct.  :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #35 on: May 08, 2010, 03:29:52 AM »
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
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #36 on: May 09, 2010, 12:39:35 AM »
Are you missing a coroutine.yield() somewhere?

I'll take a look if you want.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #37 on: May 09, 2010, 09:52:34 AM »
Received your level code via PM.
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 positive
rcolour = 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, 09:57:05 AM by annikk.exe »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #38 on: May 09, 2010, 09: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, 10:10:17 PM by AWS »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #39 on: May 09, 2010, 10: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 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


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, 11:51:59 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #40 on: May 09, 2010, 10: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
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #41 on: May 10, 2010, 02:09:28 AM »
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 10, 2010, 02:20:56 AM by AWS »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #42 on: May 10, 2010, 03:05:11 AM »
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
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #43 on: May 10, 2010, 03:26:28 AM »
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
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #44 on: May 10, 2010, 03:39:59 AM »
RIGHT!
i commented out ALL the colour changing code. everything. it still crashes after that same time period passes.
SO - it must be something else by definition. but what, i know not.

...the search continues...  ???

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #45 on: May 10, 2010, 03:44:22 AM »
Am trying to figure it out also.  I thought perhaps it was because you are treating player 0 as an AI player, but I changed all the references to player 0 and his asteroids to player 3, and it still crashes.

It seems to crash shortly after the grace timer is up, I'd estimate about 400 seconds in.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #46 on: May 10, 2010, 03:56:37 AM »
Bizarrely, it seems to be some of the asteroids in LevelSetup() causing the problem...


The first 5 are fine.  Going to check the others now


Edit - wait, nope... still crashes with only the first 5 asteroids.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #47 on: May 10, 2010, 04:02:41 AM »
see..i also suspected the grace timer might have been the issue.
i changed it to 1024 (which i think equates to 17mins real time) and am running the game as i type. it seems to be at least part of the issue because its been going for a long time, longer than usual.
this might be it...

...

EDIT - game still running, after at least 15mins....am waiting for the crash but its not happening.
HAHA...just as i typed that, it crashes!!! ::)
SO, my conclusion is that its the grace timer. that change made a difference but it still crashed after the 17mins.
i will comment it out and see if it goes all the way....

...
« Last Edit: May 10, 2010, 04:10:36 AM by AWS »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #48 on: May 10, 2010, 04:07:33 AM »
I think it has something to do with your globals.

I've changed them to this:


Code: [Select]
   -- Set Global Values
   Globals.G.Asteroids=(0)
   Globals.G.EnemyFactionsMin=(1)
   Globals.G.EnemyFactionsMax=(1)
--   Globals.Asteroids.SpawnCap=88
--   Globals.Asteroids.SeedlingCap=3333
--   Globals.Asteroids.MinSendDistance=0.5
--   Globals.Asteroids.MaxSendDistance=0.5
   Globals.AI.GraceTimer=(360)
   Globals.Structures.FlowerProbability=(0.07)
--   Globals.Mines.GrowTime=(0.59)
--   Globals.StructuresDefense.MaxDamage=1
--   Globals.StructuresDefense.MinDamage=0.5
   Globals.Asteroids.MinCoreHealth=50
   Globals.Asteroids.MaxCoreHealth=500


No crash yet.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #49 on: May 10, 2010, 04:11:34 AM »
Also this bit is wrong:

Code: [Select]
   -- Asteroid 13 - 3rd West north
   b = AddAsteroidWithAttribs(-5200,-2750, 0.5,5,0.5)


annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #50 on: May 10, 2010, 04:13:00 AM »
Just completed the map.

Pretty sure it's the globals.  Not sure which one though.

Is the seed cap set too high maybe..?  (3333)
Is the Mine Grow Time global the cause of the problem?  (perhaps its bugged command?)

I know not.
« Last Edit: May 10, 2010, 04:16:19 AM by annikk.exe »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #51 on: May 10, 2010, 04:15:23 AM »
well...
the 5 Strength attribute is changed now!!
you completed it??? already?? blimey....
so, after editing those things out, and not the grace timer, it worked?
hm....
im not sure the Mine Grow timer is bad because i changed it to 10 and it took longer to grow than what i had it on before.. 0.59.


annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #52 on: May 10, 2010, 04:16:59 AM »
Comment them out one at a time until you figure out which one is causing the trouble.  :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #53 on: May 10, 2010, 04:18:32 AM »
ok...im editing out the grace timer just by itself first. all others left in.
ill check back in a mo...

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #54 on: May 10, 2010, 04:26:06 AM »
interesting, with the grace timer edited out, it still crashed after usual time frame.
ill edit out the first inyour list of edits, the spawn cap... (which, when not specifically defined, defaults to a cap of 40)

NOPE. crashed.

next is seedling cap...
NO. took longer to crash this time.

next is mine grow time. (ive skipped the min and max send distances for now as i dont believe they are responsible for it. but if i have to, ill do them at the end)...
NO. crashed.

next is max and min defense damage. ive edited this out together...
« Last Edit: May 10, 2010, 05:14:43 AM by AWS »

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #55 on: May 10, 2010, 05:56:24 AM »
on a side note...how would i code the following script...

the flower probability can only begin to be applied once the roid has been maxed out. ie, no flowers before all trees are planted.

?

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #56 on: May 10, 2010, 06:13:46 AM »
well, after editing out the min and max defense values...the game has been going for over 30mins just fine...ill confirm upon completion of game.

fingers crossed

 :P

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #57 on: May 10, 2010, 07:03:40 AM »
hurray!
it turned out to just be those 2 values.
Code: [Select]
--Globals.StructuresDefense.MaxDamage=1
--Globals.StructuresDefense.MinDamage=0.5

interesting. i dont know why that should happen but there it is.

now, seeing as the level developed into being way way too easy...lots more adjustment is needed. feels good to the first proper run through done though.

thanks for taking a look annikk. invaluable as always.

 ;D

Bonobo

  • Achiever
  • Old Oak
  • ****
  • Thank You
  • -Given: 139
  • -Receive: 12
  • Posts: 670
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #58 on: May 10, 2010, 09:51:31 AM »
[..] as the level developed into being way way too easy [..]

Heh, then it must be just right for me :D

You guys continue to baffle me. Though I'm not a programmer, eons ago when in uiversity I took a few initial lessons in several programming languages and thus I can understand just a few teeny weeny little bits of those code snippets in your dev threads which I nevertheless read with interest as to understand the thinking behind your levels and well, I guess the philosophy of this language and programming.

Thank you.

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #59 on: May 10, 2010, 10:59:33 AM »
[..] as the level developed into being way way too easy [..]

Heh, then it must be just right for me :D

You guys continue to baffle me. Though I'm not a programmer, eons ago when in uiversity I took a few initial lessons in several programming languages and thus I can understand just a few teeny weeny little bits of those code snippets in your dev threads which I nevertheless read with interest as to understand the thinking behind your levels and well, I guess the philosophy of this language and programming.

Thank you.
:)
i assure you bonobo that i know very little of the real technical stuff behind all this coding. i kind of wish i did a bit more. i once took a 10-week web desgin course a few years ago and we touched on some basic coding (Flash, javasrcipt, css, html etc) but you only have to look at one of annikk's clear and legible explanations of a question asked to see the real knowledge. great to see and wonderful to have some access to.
when his gravity engine is finally finished, one hallowed day from now, it will be amazing to behold.
im still yet to feel confident enough to start lifting some of his AI code from his current levels. but i would like to start incorporating some of it soon. i like the thought of being able to tweak it to suit my needs.
hehe...we'll see eh...

 8)

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #60 on: June 22, 2010, 05:32:54 AM »
to anyone who knows, alex, annikk, ???

may i ask a question?

sometimes when i start a custom map of mine, it decides to give the player and the enemy very similar colours. 9 times out of 10, it will give, say a medium blue for me and a slightly lighter blue for the enemy, making identification that much harder. its not a super big deal, BUT, after a while , i begin to wonder why it does this, why only sometimes do i get a nice lime green pitched against a scary red, and how the code for such things is done?

any ideas anyone??? i could really do with having a greater team colour differentiation.


AWS

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #61 on: June 22, 2010, 04:12:08 PM »
Colour assignments for enemy empires are random.
The player can choose their own colour from the main menu.

Controlling the colours of enemy empires is on my wish list for new scripting commands... :>

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: Level design/ Code questions from a beginner
« Reply #62 on: June 22, 2010, 11:34:56 PM »
oh excellent. then it is also now on my list.
i also had a thought that it might be worth exploring howto mae the send distance not radial, but rather eliptical. it might make for a more narrative style of level design. not personally my cup of tea, heavy narrative levels, but it crossed my mind about having say, an oval shaped radius rather than a purely circular one.
?

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Level design/ Code questions from a beginner
« Reply #63 on: June 24, 2010, 05:39:53 PM »
Sorry - unlikely to happen! Empire colours is much more likely though.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #64 on: June 24, 2010, 06:52:41 PM »
Eliptical send distances would make some of the maths for the AI engine a lot more complicated.. :p

Here's hoping for specifiable empire colours.. :>

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #65 on: June 30, 2010, 04:52:40 AM »
Hello every body  :D

I wonder how it's done
We have a number 1 and number 10 and
I want that he between that numbers choose a number
and put in to Z or something
but it must always on a time of 10sec or more..... be change or something
with that output Z

i hope it will work xD

then put you the z on a energy, strength or speed
AddAsteroidWithAttribs(x, y, energy, strength, speed)

and that is a idea as for the fun " a unstable asteroid"

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #66 on: June 30, 2010, 08:19:18 PM »
Yeah, that should be possible...

1. Create an asteroid.
2. Pick a time interval.
3.Every 10 secs. or whatever, change the attributes of the asteroid.

(click to show/hide)

EDIT AGAIN :Code works now.

PROS: This code can be used for all your asteroids, can have any interval and can destabilize all of the asteroids attributes at once, or none, or whatever.
CONS: The timing is a little unreliable, because the block to change the attributes are not always checked at exactly the right time, hence checking >=, not ==. Higher intervals will make the discrepancy less obvious.

EDIT YET AGAIN: math.random() must have arguments that are integers. If you want it to randomize between 0-1, then use math.random(), otherwise use math.random(lower number multiplied by a power of ten to make it an integer, higher number multiplied by a power of ten to make it an integer)/the power of ten that you used. EG - math.random(50, 75)/100 would output between 0.5 and 0.75. math.random(500, 755)/1000 would output between 0.5 and 0.755.
« Last Edit: June 30, 2010, 09:05:48 PM by Pilchard123 »

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #67 on: July 01, 2010, 03:06:46 AM »
hmmm it dont work something i forgotten
can you help my?

(click to show/hide)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #68 on: July 01, 2010, 09:03:55 PM »
Yeah, there's a few things wrong there.

Your LevelSetup() code:
(click to show/hide)

LevelSetup() is perfectly ok, although you might want to add globals to it, like your how many asteroids and empires you want, so I'd change your LevelSteup() to be:
(click to show/hide)

LevelLogic() is a little more broken.
Your code:
(click to show/hide)

This should really be something like:

(click to show/hide)

An explanation:
GetGameTime() cannot have anything in the brackets. In your code GetGameTime(10) was invalid. Assuming you want to have asteroid 0 change every 10 seconds, you would use Roid0UnstableTimer = GetGameTime() + 10.
In the if...then statement, you would also use Roid0UnstableTimer = GetGameTime() + 10.

Also, you wrote it so that there was nothing to say when to check if the time should be checked. Eufloria would never evaluate if GetGameTime >=10, so the asteroid would not change. Placing it in a while GameRunning() do block meant that it would be checking nearly all the time.


In case that doesn't make sense, I'll make a template thingy and post it.

EDIT: HERE IT IS[/code]
« Last Edit: July 01, 2010, 10:02:48 PM by Pilchard123 »

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #69 on: July 02, 2010, 02:10:52 AM »
XD i am a men if 21years xD

hmmm i do understand but somethings go wrong, i have a rerror
can not load "(0)"
resoures/maps/totall.lau:9: unexpect symbol near')'

but i see its not working also?
can you send a lua file?

(click to show/hide)
« Last Edit: July 02, 2010, 02:16:50 AM by w4tc »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #70 on: July 02, 2010, 04:27:33 AM »
Globals.G.Asteroids=() is wrong. It should be Globals.G.Asteroids=(4) because there are 4 asteroids in your map. If there was a different number of asteroids, for instance 21, then you would use Globals.G.Asteroids=(21).

That's the only thing I can see wrong with it, but when I fix that, either my game crashes, or I get a message complaining about a zero-length vector, and I don't know what they are.

So, I'd ask annikk, Alex or Rudolf. They'll understand how the unstable asteroids work, and might be able to help you.

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #71 on: July 02, 2010, 04:58:50 AM »
I change it to to four
and also here a game crashs
I hope that annikk, Alex or Rudolf can help us

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #72 on: July 02, 2010, 04:49:37 PM »
You need a coroutine.yield() to close off your While loop.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #73 on: July 02, 2010, 09:52:15 PM »
Oh yeah...I'll just go and add that to the template...

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #74 on: July 03, 2010, 01:15:06 AM »
but i dont see the change???
I think that AddAsteroidWithAttribs(3000,0, 0.3,0.3,0.3) takes priority over the othere code of change of unstable asteroids level logic?

or must the output code putting in the value of energy speed or strength
and how??
« Last Edit: July 03, 2010, 04:57:21 AM by w4tc »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #75 on: July 03, 2010, 10:48:34 PM »
What does your code look like now?

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #76 on: July 03, 2010, 11:46:41 PM »
Here is the code, nut i dont see the change :o
so i was thinking that the lines of AddAsteroidWithAttribs(4000,0, 0.3,0.3,0.3) ect.
we have a output of a changing loop

(click to show/hide)


but must it not put it in the value of speed strongor energy?
like something like this

(click to show/hide)



(click to show/hide)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #77 on: July 04, 2010, 12:11:15 AM »
Yep, I know what's wrong.

Every time the while GameRunning()...do loop runs, the timer is reset, and so never runs out. So, the process that happens is this.

Game is running. Set timers to CurrentTime + 3 and CurrentTime + 1. Check timers. Timers have not run out, reset timers. Restart loop. Game is running. Set timers to CurrentTime + 3 and CurrentTime + 1. Check timers. Timers have not run out, reset timers. Game is running. Set timers to CurrentTime + 3 and CurrentTime + 1. Check timers. Timers have not run out, reset timers. Game is running. Set timers to CurrentTime + 3 and CurrentTime + 1. Check timers. Timers have not run out, reset timers. And so on, forever.

What you need to do is put the first

Roid0UnstableTimer = GetGameTime() + 3
Roid2UnstableTimer = GetGameTime() + 1


OUTSIDE the loop, so it looks like this:
Code: [Select]
function LevelLogic()
Roid0UnstableTimer = GetGameTime() + 3
Roid2UnstableTimer = GetGameTime() + 1

while GameRunning() do
--in this example, the energy of asteroid 2 changes to a random value between 0 and 1, roughly every second,
--and the speed of asteroid 0 changes to a random value between 0.5 and 0.75 roughly every 3 seconds.

-- everything until the next comment must be inside a loop that will never stop until the level ends, like while GameRunning() do...end.

if GetGameTime() >= Roid0UnstableTimer then
GetAsteroid(0):SetSpeed(math.random(50, 75)/100)
Roid0UnstableTimer = GetGameTime() + 3
end

if GetGameTime() >= Roid2UnstableTimer then
GetAsteroid(0):SetEnergy(math.random(50, 75)/100)
Roid2UnstableTimer = GetGameTime() + 1
end

coroutine.yield()
--this is the next comment. Carry on as normal. put everything else here.
end
end

You do want asteroid 0 to be the only one that changes, do you? Because that is what ill happen at the moment.

Fixed LUA file attached.

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #78 on: July 04, 2010, 12:33:53 AM »
Hmm Yes, it is now clear
Yesterday I had quite the time trying things.
then I thought that something not good was something to the output

COOL and it works realy :o omg thx alot buddy

Edit : it is nice also lol xD
so i have just try it with the SetRadius of the asteriod xD
and it works xD ......
but i see my fault
See first the img


So what is hapend here?
my first set was  a:SetRadius(650)
its in the lvl setup
but later... he see the loop of Unstable SetRadius..

(click to show/hide)
« Last Edit: July 04, 2010, 07:09:18 AM by w4tc »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #79 on: July 04, 2010, 02:22:38 AM »
Right. I can see at least one problem, and one thing that you really shouldn't do.

The problem is that trees will stay where they are after they are planted, so if an asteroid moves or changes size, the tree will not move to fit with this. The next patch should fix the problem with moving asteroids, and possibly this too, but maybe not. For now, just don't have asteroids that change size and have a treecap of more than 0.

Things you shouldn't do:
Make asteroids that small. how you have your math.random set up, it will make asteroids with sizes of between 6 and 7 units. I'm guessing you want between 600 and 700 units, so just get rid of the /100 part.

Also, I used the names Roid0SpeedUnstableTimer and Roid2EnergyUnstableTimer because they described what they did. Roid0SpeedUnstableTimer is how I made it. It was a Timer that made the Speed of Asteroid 0, Unstable.

If you are using that style of variable because that is what I used, just realize that you don't have to. It is not vital to the correct functioning of the code. If you are using it because you want to, then carry on, but I thought I had better let you know.

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #80 on: July 04, 2010, 03:41:39 AM »
hmm yes xD i was forgoten change the number to 1 xD
hmm indeed so we must wait on the next patch

hmm yes xD i was forgoten change the number to 1 xD
hmm indeed so we must wait on the next patch

Edit: what i see is also if the change of asteriod radius is to roughly i thing
is it possible for slow it down?

example:
we have a radius
code :

(click to show/hide)

so what means the code
He chooses now a number between 600 and 700
or number of the radius is now at the moment 600
and he choose 610
so it means that he will immediately change to 610 so we can see that fast and roughly
than is the coming question it is possible to delay this as like 601...602..603.. till he is on 610?

but this would only be very useful if the next patch at work
« Last Edit: July 04, 2010, 06:11:21 AM by w4tc »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #81 on: July 04, 2010, 06:12:53 AM »
Yeah, probably. I'll have to think about that though.

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #82 on: July 05, 2010, 04:25:43 AM »
I was just try something but it did not work  :(

so I will just explain better:
I want a black hole with an asteroid:
the mean position is, if there is any seed's or lisermine comes on the asteroid
it will instantly disappear
called a black hole or a fake asteroid....

so i tried make the fake asteroid with the option : if  there is seed or lisermine
it will automatically be sent to another asteroid that we do not look to see

(click to show/hide)

but this is not working properly, probably because I've done something wrong?
So I go searching for code, I found the code : Die()

It sounds like, if something seeds comes up the fake asteroid that it immediately be killed

and it seems better for my idea
but this did not work at all xD
and I do not know how to do this

Edit

(click to show/hide)

I hope i give now more info to help me



Edit : I do not understand it anymore  ???
I also tried :
(click to show/hide)
« Last Edit: July 05, 2010, 10:13:52 AM by w4tc »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #83 on: July 05, 2010, 06:24:27 PM »
I think I know how to do both of them. Just working on it now.

EDIT:

For black holes, insert the following code into your LevelLogic():

GetAsteroid(black hole asteroid id):RemoveSeedlings(0, GetAsteroid(black hole asteroid id):GetNumSeedlings(0))   --kills all grey seedlings
GetAsteroid(black hole asteroid id):RemoveSeedlings(1, GetAsteroid(black hole asteroid id):GetNumSeedlings(1))   --kills all player seedlings

Add more lines like that if you have enemy empires, but replace the numbers in green with the ids of the empires. You can also make it safe for an empire by leaving that line out. For example:

GetAsteroid(1):RemoveSeedlings(0, GetAsteroid(1):GetNumSeedlings(0))
GetAsteroid(1):RemoveSeedlings(1, GetAsteroid(1):GetNumSeedlings(1))
GetAsteroid(1):RemoveSeedlings(3, GetAsteroid(1):GetNumSeedlings(3))


If you want there to be an effect around the edge of the black hole, then add this code:

GetAsteroid(black hole asteroid id):AddSeedlings(5, 0, 1, 1, 1)

For this to work, the black hole must kill grey seedlings.

WARNING! If you use the effect code, make the black hole visible, at lease while you are testing the level. Sometimes it does not kill seedlings, I don't know why, and will crash.
« Last Edit: July 05, 2010, 10:13:04 PM by Pilchard123 »

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #84 on: July 06, 2010, 07:27:57 AM »
If you want there to be an effect around the edge of the black hole, then add this code:

--------------------------------------------------------------------------------
GetAsteroid(black hole asteroid id):AddSeedlings(5, 0, 1, 1, 1)


---
But you just addseeldlings, a affect around the edge of the black hole is must be different?

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #85 on: July 06, 2010, 10:33:09 PM »
A picture of the effect that you get if you use the code I gave you are attached (You also get a buzzing noise, and it moves, but that's a bit hard to show in a still picture...). What it does is add the seedlings, then instantly kill them, making a 'fuzzy' effect around the edge of the asteroid.

Also attached is the *.lua file that makes this level.

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #86 on: July 09, 2010, 10:21:18 AM »
At annikk
i yours level map you say this ( level fluffy's comet )

Code: [Select]
-- These are the "default" values.  If you set density to 0,
-- the asteroid will not be included in gravity calculations.
-- [b]If you set the density very high, and your asteroid's
-- radius is extremely small, you are creating a black hole.[/b]
-- Once you have set these, use a = AddAsteroidWithAttribs
-- below it, and plug the variables in, rather than numbers.

But how?  you creating a black hole i use density  ... but it dont work


(click to show/hide)

must i also putting this :

(click to show/hide)

can you give me a push?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #87 on: July 09, 2010, 06:13:17 PM »
Yes, you must include the gravity variables.  You do them FIRST.  Then you add the actual asteroid once you have declared them.

So for each asteroid, first use this template:
(click to show/hide)

I will do an example one to show you.

(click to show/hide)







You enter the gravity variables that you want, THEN you create the asteroid.






Normally when we create asteroids, we use numbers like this:

(click to show/hide)



But for the purposes of the gravity engine, you must do it this way instead:


(click to show/hide)
...then you can also add whatever other properties you would like for the asteroid.
EG:
(click to show/hide)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #88 on: July 09, 2010, 06:27:24 PM »
Here's a few examples of asteroids, along with a description of each.

EDIT - THESE ARE KIND OF INCORRECT... SEE NEXT PAGE



This asteroid starts off at coordinates 1500,1250.  It is not moving to start with.  It has a radius of 250 and a density of 1 - fairly standard.
(click to show/hide)




This asteroid starts at coordinates 0,0.  It is drifting slowly east.  It is much larger than the first asteroid, but its density is lower - perhaps this is a gas giant.
(click to show/hide)



This is a tiny asteroid which has a high density - perhaps it is made of meteroic iron.  :>  It is hurtling south at quite a pace.

(click to show/hide)



This is an example of a black hole.  The asteroid only has a radius of 1 - basically invisible in-game - but its density is extremely high, so it will still have an enormous gravity well.
(click to show/hide)
« Last Edit: July 09, 2010, 08:08:51 PM by annikk.exe »

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #89 on: July 09, 2010, 07:31:03 PM »
Is this a good?
Becaus the level will not loading... Hmm

(click to show/hide)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Level design/ Code questions from a beginner
« Reply #90 on: July 09, 2010, 07:47:24 PM »
I don't think so - you need to add this code before you add asteroids:


Code: [Select]
        AccelerationX = {}
AccelerationY = {}
MomentumX = {}
MomentumY = {}
density = {}
CoordX = {}
CoordY = {}
roidradius = {}
Timer = 0
G = 0.1

But I could be wrong - I'm not annikk. You can change the variable G to any value that you like. If it is higher, gravity will be stronger on the whole map.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #91 on: July 09, 2010, 08:00:22 PM »
Pilchard is correct - that is why the level does not load.

However, you also won't get any gravity unless you include the code for the gravity engine :P


Note that the previous asteroid templates I posted use numbers for the array slots - that was incorrect.  In the gravity engine, you specify the slots with a variable called roid

So instead of CoordX[0] = 1000

You use this:
roid = 0
CoordX[roid] = 1000
« Last Edit: July 09, 2010, 08:23:52 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #92 on: July 09, 2010, 08:13:07 PM »
Fixed templates.


This asteroid starts off at coordinates 1500,1250.  It is not moving to start with.  It has a radius of 250 and a density of 1 - fairly standard.
(click to show/hide)




This asteroid starts at coordinates 0,0.  It is drifting slowly east.  It is much larger than the first asteroid, but its density is lower - perhaps this is a gas giant.
(click to show/hide)



This is a tiny asteroid which has a high density - perhaps it is made of meteroic iron.  :>  It is hurtling south at quite a pace.

(click to show/hide)



This is an example of a black hole.  The asteroid only has a radius of 1 - basically invisible in-game - but its density is extremely high, so it will still have an enormous gravity well.
(click to show/hide)
« Last Edit: July 09, 2010, 08:20:58 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #93 on: July 09, 2010, 08:16:28 PM »
The best thing to do is to download the template file, then try playing it immedietely.


Then, open it up in a text editor, and try to change some of the values in LevelSetup() such as the initial momentum (for example, try changing the value of MomentumX[roid]).  Then try to play the level again and see what has changed.  :>




As I have a bit more free time now, I will be providing better support for people learning to use the gravity engine from now on.

Shall we perhaps continue this discussion in the other thread?

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #94 on: July 14, 2010, 05:10:37 AM »
I was trying use : if and than
but it not realy works xD
But i dont whats go wrong
if i play the game no errors but if i take that asteroid there comes not a new asteroid

hmm...

(click to show/hide)
« Last Edit: July 14, 2010, 05:27:30 AM by w4tc »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #95 on: July 14, 2010, 10:01:55 AM »
Two problems.


First, this line:

if id == 1 and owner == 1 then

The id and owner bits relate to function OnAsteroidTaken() and you cannot use them in function LevelLogic() in the way that you are trying to.



Second, as you will probably now try to just move the commands to a function OnAsteroidTaken(), let me save you some bother and tell you that it won't work either.  Here's why:

AddAsteroidWithAttribs (2000 ,2000, 1, 1, 1)

You can only add asteroids during LevelSetup.  Asteroids you add at any other time are buggy and unusable.
Also, you had some syntax errors on that line.  There's a space that shouldn't be there, and you forgot to add a =

Here's an alternative way to do it.  You create the hidden asteroid right from the start, but you set its radius to 0 and hide it from the player.  That way you can't see it, although you will still see the UI "send arrow" interacting with it.  Players will be unable to travel there, although seeds can still path there - so bear this in mind when planning the layout of your levels.
Then, when you want to "add" the asteroid into play, you simply set its radius to something normal, and reveal it to the player.






Here's some untested code which should do what you need:


Code: [Select]
function LevelSetup()

-- Set Global Values
Globals.G.Asteroids=(2)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)


-- Asteroid 0 - starting asteroid
a = AddAsteroidWithAttribs(0,0, 0.7,0.6,0.5)
a.Owner = 1
a.TreeCap = 1
a:SetRadius(250)
a.SendDistance = 2500
a:AddSeedlings(90)

-- Asteroid 2 - lege asteroid
a = AddAsteroidWithAttribs(-2500,0, 1,1,1)
a.TreeCap = 5
a:SetRadius(900)
a.SendDistance = 5000

-- Asteroid 3 - Fluffy's special hidden asteroid
special = AddAsteroidWithAttribs(2000,2000, 1,1,1)
special.TreeCap = 0
special:SetRadius(0)
special.SendDistance = 10000
special:Hide(1)

once = false

end


function LevelLogic()

special.SendDistance = 0

while GameRunning() do

if GetEmpire(1):OwnsAsteroidID(1) and once == false then

once = true

special.TreeCap = 5
special:SetRadius(600)
special.SendDistance = 3800
special:Reveal(1)

end

coroutine.yield()
end


end
« Last Edit: July 14, 2010, 10:05:31 AM by annikk.exe »

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Level design/ Code questions from a beginner
« Reply #96 on: July 15, 2010, 01:28:30 AM »
I've just fixed adding and removing asteroids at runtime.

w4tc

  • Achiever
  • Shrub
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 170
Re: Level design/ Code questions from a beginner
« Reply #97 on: July 15, 2010, 05:31:27 AM »
How do you mean, Alex?

Cool annikk it working
Also with this code :o

Code: [Select]
if GetEmpire(1):OwnsAsteroidID(1) and GetEmpire(1):OwnsAsteroidID(3) and once == false then
but if i put more of that hidden asteroid
can i do this? But I try this to tomorrow,now I must go sleep
goodnight everyone

Code: [Select]
-- Asteroid 5 - Fluffy's special hidden asteroid
special = AddAsteroidWithAttribs(2000,2000, 1,1,1)
special.TreeCap = 0
special:SetRadius(0)
special.SendDistance = 10000
special:Hide(1)

second= false

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Level design/ Code questions from a beginner
« Reply #98 on: July 15, 2010, 08:54:58 AM »
I mean that in the next update if you add asteroids outside of the level setup it will work. you will also be able to remove them. you'll also be able to tell when they were clicked by the player and do stuff as a result.

So now you guys have got input, drawing, and text, I expect to see some full games coming out soon! :p

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Level design/ Code questions from a beginner
« Reply #99 on: July 16, 2010, 01:49:43 AM »
Cool annikk it working
Also with this code :o

Code: [Select]
if GetEmpire(1):OwnsAsteroidID(1) and GetEmpire(1):OwnsAsteroidID(3) and once == false then
but if i put more of that hidden asteroid
can i do this?

You can, but you need to use new variables; "special" and "once" already refer to specific things.
Try making some, "specialtwo" and "oncetwo"
Then "specialthree" and "oncethree", and so on.





Quote
But I try this to tomorrow,now I must go sleep
goodnight everyone

Code: [Select]
-- Asteroid 5 - Fluffy's special hidden asteroid
special = AddAsteroidWithAttribs(2000,2000, 1,1,1)
special.TreeCap = 0
special:SetRadius(0)
special.SendDistance = 10000
special:Hide(1)

second= false


Ok so as an example, this line:

Code: [Select]
special = AddAsteroidWithAttribs(2000,2000, 1,1,1)
Should be something like this:

Code: [Select]
specialfive = AddAsteroidWithAttribs(2000,2000, 1,1,1)
Then, of course, you would change the other bits that refer to Asteroid ID 5 to that same variable.

Code: [Select]
specialfive.TreeCap = 0
specialfive:SetRadius(0)
specialfive.SendDistance = 10000
specialfive:Hide(1)




Likewise with your "once" variable.  You should do a seperate If statement with a seperate boolean variable for every asteroid that you are hiding.
« Last Edit: July 16, 2010, 06:03:01 PM by annikk.exe »