Euflorium: The Eufloria Community

Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: AWS on April 04, 2010, 10:30:40 PM

Title: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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?

Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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

Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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:



(http://www.aaroncake.net/forum/uploaded/eng.zahir/2008551448_sine_wave.png)


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.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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?

 :-[
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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 :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: njursten 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.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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.

Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on April 05, 2010, 03:53:55 PM
No worries.  Let us know how you get on :>
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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:



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



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.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: Alex 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?
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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 :)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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 :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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? :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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!) :)
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: njursten 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.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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.
Title: Re: Level design/ Code questions from a beginner
Post by: Mihhaelo 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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?

 ???
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on May 06, 2010, 03:19:34 AM
0 is uninhabited, or "barren", which is also the greys.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on May 06, 2010, 11:40:07 PM
Your understanding is correct.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on May 09, 2010, 12:39:35 AM
Are you missing a coroutine.yield() somewhere?

I'll take a look if you want.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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?
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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.

Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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...
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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... :)
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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...  ???
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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....

...
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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)

(http://img263.imageshack.us/img263/8279/upsf.png)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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.

Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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...
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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...
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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.

?
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: Bonobo 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.
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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)
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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... :>
Title: Re: Level design/ Code questions from a beginner
Post by: AWS 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.
?
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on June 24, 2010, 05:39:53 PM
Sorry - unlikely to happen! Empire colours is much more likely though.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.. :>
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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"
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 01, 2010, 03:06:46 AM
hmmm it dont work something i forgotten
can you help my?

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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 (http://www.dyson-game.com/smf/index.php?topic=846.0)[/code]
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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)
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 02, 2010, 04:49:37 PM
You need a coroutine.yield() to close off your While loop.
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 02, 2010, 09:52:15 PM
Oh yeah...I'll just go and add that to the template...
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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??
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 03, 2010, 10:48:34 PM
What does your code look like now?
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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)
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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)
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 04, 2010, 06:12:53 AM
Yeah, probably. I'll have to think about that though.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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)
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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?
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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?
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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)
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 09, 2010, 07:31:03 PM
Is this a good?
Becaus the level will not loading... Hmm

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 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.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 09, 2010, 08:16:28 PM
The best thing to do is to download the template file (http://www.dyson-game.com/smf/index.php?action=dlattach;topic=810.0;attach=431), 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 (http://www.dyson-game.com/smf/index.php?topic=810.0)?
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 15, 2010, 01:28:30 AM
I've just fixed adding and removing asteroids at runtime.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc 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
Title: Re: Level design/ Code questions from a beginner
Post by: Alex 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
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe 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.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 16, 2010, 05:12:30 AM
Wooooot that working :o

I think anything I had read but I suspect that I'm reading it wrong
That you can add leaf's on the asteroid, but I think I've had an exchange with flower
but flower and leafs are not the same xD
But is there a opportunity that you only can add leafs on the astgeroids?

Adding Edit xD ( or some thing ) xD :
oh yes, before I forget there is a possibility as a dead asteroids him back to life?
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 16, 2010, 04:19:53 PM
Leaf?  I'm not aware of any leaves...

If you kill an asteroid with Die() then I think it's not possible to ressurect it.
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 16, 2010, 05:39:06 PM
Perhaps you mean the grass, w4tc? In which case, no, that needs to come with a tree.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 16, 2010, 06:04:56 PM
Glad to hear you got it sorted, by the way :>  Always exciting when you get a new mechanic working for the first time!
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 16, 2010, 11:15:37 PM
Perhaps you mean the grass, w4tc? In which case, no, that needs to come with a tree.

Hmm, yes, thit will be cool xD if there also exists a code :D
it is for my level map... little spoilers it about sickness....


Glad to hear you got it sorted, by the way :>  Always exciting when you get a new mechanic working for the first time!
did that about me or Alex? and what do you mean with that xD?


But the next question
If i discover a new asteroid, there must be appear a textbox

is that like this example?
Code: [Select]
function OnAsteroidRevealed(id, owner)
       if id == 1 then MessageBox("Asteroid "..id.." was discovered by faction "..owner..".") end
end
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 16, 2010, 11:45:23 PM
YEp.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 17, 2010, 12:25:20 AM
Glad to hear you got it sorted, by the way :>  Always exciting when you get a new mechanic working for the first time!
did that about me or Alex? and what do you mean with that xD?

That was in response to you.  :>

"Glad to hear you got it sorted"  ->  I am glad that you managed to get it working.
"Always exciting when you get a new mechanic working for the first time!" -> Parts of a level that "do something" are called "mechanics".  The word "mechanic" is used in the same way as the likes of "quantum mechanics".  I am saying that it is exciting when you get a new bit to work properly.  :>

Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 17, 2010, 05:00:28 AM
Whoee ;D Thx annike
Title: Re: Level design/ Code questions from a beginner
Post by: Sniped50 on July 18, 2010, 12:13:58 AM
Hey guys...
I'm currently working on a small, highly experimental level which uses gravity in nearly all of it's asteroids. But I'm having a few problems with the AI. I'm trying to keep it from attempting to send seedlings to the central asteroid (where all the seedlings instantly die), but it's refusing to do so. At the moment I'm stumped, and this should be a very simple procedure. Plus I'd like to make it a little more aggressive without having to resort to something as complex as annikk's Infected AI. A little help please?
Title: Re: Level design/ Code questions from a beginner
Post by: Mihhaelo on July 18, 2010, 01:23:11 AM
Quote
Hey guys...
I'm currently working on a small, highly experimental level which uses gravity in nearly all of it's asteroids. But I'm having a few problems with the AI. I'm trying to keep it from attempting to send seedlings to the central asteroid (where all the seedlings instantly die), but it's refusing to do so. At the moment I'm stumped, and this should be a very simple procedure. Plus I'd like to make it a little more aggressive without having to resort to something as complex as annikk's Infected AI. A little help please?

Put the following code at the start of your map. It will make the AI more aggressive and expansive.

(click to show/hide)

I don't think it's possible to prevent the AI from going to an asteroid if they can physically reach the asteroid, you'll probably have to think of a workaround. You could code it, so AI seedlings lost to the center are respawned elsewhere. You can also manually tell the AI to move seedlings away, once an asteroid gets within a certain range.
Title: Re: Level design/ Code questions from a beginner
Post by: Sniped50 on July 18, 2010, 07:31:33 AM
Hmm... Thanks Mihhaelo. That code definitely works. It will need a bit of tweaking so the AI doesn't use up all it's seedlings and leave it's asteroids vulnerable to attack, but it's an improvement from the extremely lazy empire (read: can't even be bothered to get seedlings to other roids before I've conquered half the system) I had before.

As for the other issue...
Quote
I don't think it's possible to prevent the AI from going to an asteroid if they can physically reach the asteroid, you'll probably have to think of a workaround.

A pity. I probably might make it so that any seedlings sent there are respawned on the home planet, but that just seems like a really ugly way to work around it, and if I told the AI to move away if the central asteroid was within their send distance, then the entire inner orbit would remain utterly deserted, save for my empire. That doesn't particularly help fix the difficulty issues I had prior to upgrading my globals. :P

Plus, I also worked out that Eufloria doesn't like killing lots of seedlings at once, and will crash if this is the case. Basically, send too many seedlings to the central roid at once, they all die, and Eufloria dies. Presumably from a broken heart...  :'(

I upgraded to v2.05 like, literally hours ago. Maybe that has something to do with it, because I never saw Eufloria crash like that on this map...
Title: Re: Level design/ Code questions from a beginner
Post by: Mihhaelo on July 18, 2010, 09:10:12 AM
Quote
Plus, I also worked out that Eufloria doesn't like killing lots of seedlings at once, and will crash if this is the case. Basically, send too many seedlings to the central roid at once, they all die, and Eufloria dies.

I once had an issue with deleting seedlings as well. My code basically said "Are there 10 seedlings on this planet? If yes delete them". I found by adding a 1 second delay between scans fixed the crashes.

I can only assume that deleting seedlings is not instant and there is a slight delay when the seedlings are told to die, and that on occasion they will still be around when your code takes another pass. So your code ends up trying to delete them when they are not there.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 18, 2010, 08:39:48 PM

I was just asked about these days about this code:

Code: [Select]
function OnAsteroidRevealed(id, owner)
       if id == 1 then MessageBox("Asteroid "..id.." was discovered by faction "..owner..".") end
end

but that's not really mean thing I want
it is similar, if you explore every aseroid than any other text on it, but with this, the text is always the same ones
but I do not see how I can change than  ???
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 18, 2010, 08:42:25 PM
If you mean that the box tells you which asteroid was discovered, and by who, then use

Code: [Select]
function OnAsteroidRevealed(id, owner)
     MessageBox("Asteroid "..id.." was discovered by faction "..owner..".")
end
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 19, 2010, 02:57:44 AM
no, that not what i mean
what i mean is you if you discovered asteroid 1 then tells the box ( example ) : "Oohh cool a fresh asteroid but something is gone wrong here"
and you discover a new asteroid 3 " now we see there is a full FlowerDefense but why? "
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 19, 2010, 03:56:57 AM
something I do not understand

i have this code
that the Owner 1 and 2 there are not in the right position ???

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 19, 2010, 06:51:34 AM
no, that not what i mean
what i mean is you if you discovered asteroid 1 then tells the box ( example ) : "Oohh cool a fresh asteroid but something is gone wrong here"
and you discover a new asteroid 3 " now we see there is a full FlowerDefense but why? "



Code: [Select]
function OnAsteroidRevealed(id, owner)

if id == 3 then
MessageBox("Asteroid "..id.." was discovered, and belongs to empire "..owner..".")
elseif id == 4 then
MessageBox("Asteroid "..id.." was discovered, and this asteroid belongs to empire "..owner..".")
elseif id == 5 then
MessageBox("Asteroid "..id.." was discovered, and this super-fluffy-happy asteroid belongs to lucky empire number "..owner..".")
else
MessageBox("Asteroid "..id.." was discovered, and this miscellaneous asteroid belongs to empire "..owner..".")
end

end

Something like this, perhaps?
Remember, in an OnAsteroidRevealed function, owner is the person who owns the asteroid that was discovered, NOT the person who discovered it.
[edit - I might be wrong about that...]
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 19, 2010, 07:32:17 AM
something I do not understand

i have this code
that the Owner 1 and 2 there are not in the right position ???

(click to show/hide)

I can not understand well what is wrong
but if I level game, then are the players are not in the right place ???


PS : Thx alote annikk :D
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 19, 2010, 04:08:31 PM
Remember the grid isn't how you would naturally imagine it, it looks like this:

(http://www.hpruk.com/annikk/2.PNG)


Check your coords against this map and you should be able to see where everything will be.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 20, 2010, 01:50:42 AM
sorry anikk but i dont see noting wrong in the coords, that it has nothing to do with the asteroids?
but it is the players place..
so i tried and i add now Moveable = False ect
now it player 1 that oke, but not player 2 ....

img 1 : it wath i see on the game level
img 2 : is my drawing, how the asteroids should be standing

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 20, 2010, 03:45:58 AM
OK, you need to set asteroid 0 owner to 0. Then you have it right - the only problem is the camera, which is broken at the moment and I have just fixed it so that will come in the next update. In the meantime change your first two asteroids around.

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 20, 2010, 06:35:56 AM
help me plz, I am now at almost appropriate to speak to give  :'( :'(
i have change my test level for to make it easy

so i make this :  
(click to show/hide)

and he always gives an error code but I want a coord or More Than 10 000 or 5000..
its come from a another test and that works, but what I do is just change the coordinates and and have alwhy a rerror???

Edit : or must i also set asteroid 0 owner to 0?
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 20, 2010, 06:49:35 AM
At the moment that crashes because the game is trying to find a path between those asteroids and it can't because they're so far apart and there are no other asteroids to make a path between them. Add some more asteroids - or you can start the asteroids closer to gether and move them apart in the first part of the level logic.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 20, 2010, 04:14:48 PM
Add the following Globals:


Code: [Select]
Globals.G.MaxAsteroidNeighbourDist=80000
Globals.Asteroids.MinSendDistance=80000
Globals.Asteroids.MaxSendDistance=80000


Then, if you set Send Distances for your asteroids, do it in function LevelLogic like this:

GetAsteroid(0).SendDistance = type a number
GetAsteroid(1).SendDistance = type a number
GetAsteroid(2).SendDistance = type a number
GetAsteroid(3).SendDistance = type a number
GetAsteroid(4).SendDistance = type a number



DO NOT set these send distances in function LevelSetup.  Do it in function LevelLogic.


This should fix your issue.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 21, 2010, 09:27:22 PM
thx annikk
but in the past that was not?
strange

now I do a calculation for set point of Core Health
the volume is equal to the Core Health
but it is told that I have an error on the line 31 but it is blank
only on line 32 is this: "getasteroid (0): = Radius SetRadius"

edit on the post i have see that i forgot to put the "()' from the CoreHealth
so now it haves a error on the line 32
a unexpected symbol or something, but i dont see it what it is

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: Eufloria Admin on July 21, 2010, 09:38:10 PM
Code: [Select]
a.Moveable = false
end

getasteroid(0):SetRadius() = Straal

There's your problem.
You tried to reference asteroid ID 0, but you did it OUTSIDE the function levelsetup.

You need to move the command to either function LevelSetup or function LevelLogic.  You can't have it hanging in between them.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 21, 2010, 10:08:24 PM
so i have put it in the LevelLogic
and change
Code: [Select]
getasteroid(0):SetRadius()= Straal to 
Code: [Select]
getasteroid(0):SetRadius(): Straalnow i get a new error :"Resours/maps/nieuw.lua:36: function arguments expected near 'if' "

Code: [Select]
function LevelLogic()
getasteroid(0):SetRadius(): Straal

if Straal > 200 == then
V = ( 4 * 3 ) * 3,14159265 * ( straal * straal * straal )
V = GetAsteroid(0):SetCoreHealth()
end

end
Title: Re: Level design/ Code questions from a beginner
Post by: Eufloria Admin on July 21, 2010, 10:13:36 PM
Uh, yea... your syntax is wrong, too.

Code: [Select]
getasteroid(0):SetRadius() = Straal
Should be:

Code: [Select]
GetAsteroid(0):SetRadius(Straal)
Title: Re: Level design/ Code questions from a beginner
Post by: Eufloria Admin on July 21, 2010, 10:19:30 PM
Unless you were trying to read the radius and record it into the variable Straal, which, actually, is what it looks like you were trying to do.


In that case, you would do it this way.


Find this code:
Code: [Select]
-- Asteroid 0 - starting asteroid
a = AddAsteroidWithAttribs(-2000,0, 0.7,0.6,0.5)
a.Owner = 1
a.TreeCap = 1
a:SetRadius(250)
a.SendDistance = 2500
a:AddSeedlings(90)
a.Moveable = false


Replace with:
Code: [Select]
-- Asteroid 0 - starting asteroid
a = AddAsteroidWithAttribs(-2000,0, 0.7,0.6,0.5)
a.Owner = 1
a.TreeCap = 1
Straal = 250
a:SetRadius(Straal)
a.SendDistance = 2500
a:AddSeedlings(90)
a.Moveable = false





Then do this:


Find code:
Code: [Select]
end

getasteroid(0):SetRadius() = Straal

function LevelLogic()


if Straal > 200 == than
V = ( 4 * 3 ) * 3,14159265 * ( straal * straal * straal )
V = GetAsteroid(0):SetCoreHealth()
end

end



Replace with:
Code: [Select]
end

function LevelLogic()


if Straal > 200 == then
V = ( 4 * 3 ) * 3.14159265 * ( Straal * Straal * Straal )
GetAsteroid(0).CoreHealth(V)
end

end


Note that in this level as it is right now, your IF statement will always return true.
Title: Re: Level design/ Code questions from a beginner
Post by: Eufloria Admin on July 21, 2010, 10:23:27 PM
Also, because it always returns True, it is going to try to set Asteroid 0's core health to 589,048,621

Not quite sure where you're going with this.. :>  What are you hoping to create?
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 21, 2010, 10:45:08 PM
Also, because it always returns True, it is going to try to set Asteroid 0's core health to 589,048,621

Not quite sure where you're going with this.. :>  What are you hoping to create?

I trying want to determine/ setting Core Health whit calculation of the volume of it and later whit the Perimeter
and combine so that the "correct value" following the size and volume

Code: [Select]
core health to 589,048,621whooeeeeps xD i must 4/3 xD


it have now a error of unexpected symbol near 'then' "
on the line of
Code: [Select]
if Straal > 200 == then false
Code: [Select]
function LevelLogic()


if Straal > 200 == then false
V = ( 4 / 3 ) * 3.14159265 * ( Straal * Straal * Straal )
GetAsteroid(0).CoreHealth(V)
end

end
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 21, 2010, 11:40:07 PM
What is that "false" doing after the "then"?
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 21, 2010, 11:44:22 PM
What is that "false" doing after the "then"?

oeps sorry, its fixed
but it gaves the same error

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 22, 2010, 02:20:31 AM
CoreHealth is a field, so you need to assign values directly to it rather than calling it like a function - for this you use the dot and equals:

GetAsteroid(0).CoreHealth = V

If it were a function, you would have to use the colon and brackets. Here is an example:

GetAsteroid(0):GetFlower(1) -- returns a Flower belonging to faction 1 (the player) or nil if no such flower exists.

Look up whether members are fields or functions in the reference (http://www.dyson-game.com/smf/index.php?topic=212.msg1913#msg1913).
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 22, 2010, 03:51:36 AM
i tried but he the same error on the line of this :

if GetAsteroid(0):GetRadius() > 200 == then

but i tried also
if GetAsteroid(0):Radius() > 200 == then
if GetAsteroid(0):GetRadius() > 200 == then
if GetAsteroid(0):SetRadius() > 200 == then
hmmmm if GetAsteroid(0).SetRadius() > 200 == then

Code: [Select]
function LevelLogic()

if GetAsteroid(0):SetRadius() > 200 == then
V = ( 4 / 3 ) * 3.14159265 * ( Straal * Straal * Straal )
GetAsteroid(0).CoreHealth = V
end

end

Edit : but there was a thing that i have change on that line if .....than
and the loading of hte game take a little longer than normale but the same error....
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 22, 2010, 04:18:52 AM
Ah, use

Code: [Select]
function LevelLogic()

[b]if GetAsteroid(0).Radius > 200  then[/b]
V = ( 4 / 3 ) * 3.14159265 * ( Straal * Straal * Straal )
GetAsteroid(0).CoreHealth = V
end

end

Radius is an attribute (?...annikk?), not a function, so you use a period, not a colon. Also, you had '==' after your test, which you should never do, because it will cause an error.

You do realise that code will only run once don't you?
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 22, 2010, 05:12:14 AM
annikke.exe!  That use of the sin function gave me a great idea for a level, but I'm not nearly skilled enough to put it into effect.  What if you used a sin function to create a level with seasons, it would put an interesting twist on the level!  During the winter phase, I was thinking the trees could die off, then in the spring they can be plated again and in the summer they produce at a fast rate (maybe add lines to level the trees up to full instantly once it hits summer).  Along with the seasons, the background color could change with it to represent the changing seasons.  I don't know if it's possible to do this, but I think it would make for a challenging level!
Title: Re: Level design/ Code questions from a beginner
Post by: Bonobo on July 22, 2010, 06:30:05 AM
Amazing ideas, Terrial. There have already been user-created maps with day/night lighting and increasing/reduced send distances.

But please, folks, whenever you create maps w/ changing background colours, please make them so that the seedlings always stand out, contrast-wise or something like that. I've seen levels where it was impossible to see whether there were seedlings around an asteroid when zoomed out.
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 22, 2010, 06:35:01 AM
Haha thanks, I just love this game so much and it has so much potential.  I also just really enjoy the fact the the whole game is based on plants. (If I weren't going to be an engineer and it were a practical thing for me to do I would love to become a Horticulturist)

Also ideas just pop into my head all the time, I've had more like this but I've forgotten them, I'll have to start writting them down if you guys like them.
Title: Re: Level design/ Code questions from a beginner
Post by: Bonobo on July 22, 2010, 06:50:08 AM
Terrial, I think ideas are ALWAYS welcome here in this forum, and you’ll find a lot of friendly and helpful people here.

Perhaps this has to do with the nature of the game, as you talk of the game being based on plants. Well, there is some shooting and conquering and all, since we humans seem to need such, but all in all the game is definitely something other than the usual war & shooting games. I love it for the same reason. Might be a nice idea, though, to bring the possibility of co-operation w/ other factions into it, somehow. But I guess that might be quite hard … friendliness could, e.g., be communicated by visiting a new asteroid and leaving it immediately after having found that it's inhabited already, but that would have to happen before getting killed :D
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 22, 2010, 06:53:45 AM
Well, you could make a tribute system by creating a trigger that may be used with the right click where if you right click, say 10 of your seeldings are given to another empire (killed and respawn as the other empire)  Or alternatively, you could create a trigger by having some roids FAR out in the distance where nobody can get to them with 1 seedling and based on which asteroid the seedling is on, it could change a setting in the game.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 22, 2010, 06:57:05 AM
aarggg ok i change here and there
so it not working enymore
i change only now from straal to radius becaus it straal is just dutch for Radius
but normale
is it
i set me radius of asteriod 0 to 250
Code: [Select]
a:SetRadius(250)so
it but be like : if radius of asteroid 0 greater than the number 200 is than
( we put than a calculation volume and the volume is equal to SetCoreHealth of the same asteriod )
( the code of volume is V= (4/3) * Pi * radius³ ( to the third Square-algebra) BUT that number must come from that asteroid)
so
than must it be something like this :
Code: [Select]
V = ( 4 / 3 ) * 3.14159265 * ( GetAsteroid(0).Radius  * GetAsteroid(0).Radius  * GetAsteroid(0).Radius  )
than the output is the SetCoreHealth of that asteroid so it must

it should xD hmmm lol : 65 449 846,95
so that is realy to mutch xD So it must divide by a number that I take is 685,000( but I do not know how to do it)
but that is not so important at the moment


than the "full versie"
this is more important :
but some reason that not working i get the same thing 90....


Code: [Select]
if GetAsteroid(0).Radius > 200  then
V = ( 4 / 3 ) * 3.14159265 * ( GetAsteroid(0).Radius  * GetAsteroid(0).Radius  * GetAsteroid(0).Radius  )
GetAsteroid(0).SetCoreHealth = V
end
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 22, 2010, 07:08:39 AM
about that  day/night it exists level : Night_Stalkers you can only move in day light link : http://www.dyson-game.com/smf/index.php?topic=789.0 (http://www.dyson-game.com/smf/index.php?topic=789.0)
Title: Re: Level design/ Code questions from a beginner
Post by: Bonobo on July 22, 2010, 08:58:59 AM
Right, and IIRC you can also only plant during daylight.

(Must. Update. List. Of. Maps.)
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 22, 2010, 05:49:50 PM
w4tc.

Here is the list of fields and functions. (http://www.dyson-game.com/smf/index.php?topic=212.msg1913#msg1913)

CoreHealth, not SetCoreHealth, is a field. SetCoreHealth doesn't exist, so trying to call it will cause an error.

As I said in my previous post:

CoreHealth is a field, so you need to assign values directly to it rather than calling it like a function - for this you use the dot and equals:

GetAsteroid(0).CoreHealth = V

That is the syntax and field name you require. Just copy that line and use it.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 22, 2010, 09:48:31 PM
annikke.exe!  That use of the sin function gave me a great idea for a level, but I'm not nearly skilled enough to put it into effect.

The way you do it is by making a continuously-updated variable (using a loop).


So start out with your function LevelLogic() and lets make a loop:


(click to show/hide)




Hopefully you follow what is going on so far.  We've created a loop that will run indefinitely.
Next, lets make a variable to represent the up-and-down wavy motion we get with sin:


(click to show/hide)



Now we have a continously updating value.
fluffy will slowly roll between the values 1 and -1 as time goes by.

Here's a way to visualise what's going on:

(http://upload.wikimedia.org/wikipedia/en/8/89/Unfasor.gif)

Imagine the circle is a clock, and as it turns it represents time going by.

On the line above, the horizontal axis represents the value of fluffy.




Maybe we want the pulses to go faster...
(spot the difference here!)


(click to show/hide)

After 1 second, we'll be taking the math.sin of 2.5, instead of 1.
So it will rush through the cycles faster.  Adjust to taste.  :>



Now, drifting between 1 and -1 is all well and good, but perhaps we'd like to change the background colour between 0 and 255.  How to do that?
Well, all we do is run some maths on fluffy and we can convert the minimum value (-1) to 0 and the maximum value (1) to 255.
How to do that?

Like this:


(click to show/hide)


So with that bit of maths, now we have a constantly-updating variable with a suitable range to use for background colour.  :>

Finally, lets hook our variable up to control background colour:





(click to show/hide)


Now our background colour will range between totally black (0,0,0) and totally white (255,255,255).



Maybe we want it to fade between totally black and totally red.  Then we would replace the existing background colour command with this one:

Code: [Select]
SetBackdropColour(fluffy,0,0)


Hope this makes it clearer.  Let me know if there's anything you don't understand :>
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 23, 2010, 02:37:15 AM
heh heh, when i said I'm not skilled enough, i meant I don't know all of the functions to kill off, and only allow planting during a certain phase, and make the trees hit max level during the summer phase.  I understand the math just fine.
Title: Re: Level design/ Code questions from a beginner
Post by: Bonobo on July 23, 2010, 02:52:37 AM
But me here, w/ near zero programming knowledge, I am happy to learn about this, thx @Annik. The visualisation from Wikipedia makes a lot clear to me. Been so long since I went to school …
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 23, 2010, 04:57:48 AM
sorry alex but it not working, I dare not even post about i for that you be angry or something :$
So, I've changed things so that it is easy to start

I start just for manually change ( like the post : http://www.dyson-game.com/smf/index.php?topic=848.0 )

Code: [Select]
function LevelLogic()
mycorehealth = 100
GetAsteroid(0).CoreHealth = mycorehealth
end
But i dont work. I think that this problem be solved first, then we can make further steps?

the full code ( 2 roids + that funtcion )
(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 23, 2010, 07:07:01 AM
try putting it in parenthesis, i don't know why but that might help.  Also try it without spaces between the = sign.  That's how I've been going about trying to get the syntax to work, just trying every possible combination! haha
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 23, 2010, 07:34:54 AM
I discovered something cool, but not currently have what I need
The count on to its value, but not the value that I've made in

Code: [Select]
function LevelLogic()
mycorehealth = 100
GetAsteroid(0).CoreHealth="mycorehealth"
end

Also count upo whit and stops on 90Corehealth
Code: [Select]
GetAsteroid(0).CoreHealth='mycorehealth'
Also tried whit :

Code: [Select]
GetAsteroid(0).CoreHealth=(mycorehealth)
Even
Code: [Select]
GetAsteroid(0).CoreHealth=100
Code: [Select]
GetAsteroid(0).CoreHealth=(100)
Code: [Select]
GetAsteroid(0).CoreHealth(100)
with no result, i gave always 90
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 23, 2010, 10:54:50 AM
So I started trying to make that seasons level.  I can't get the colors to change because I don't know how to make the game count up and restart.  (I couldn't figure out how to make the sin function work to change it between four different colors)

He's what I have so far if anyone wants to take a crack at it:
Pay no attention to the asteroids, they are just there to look pretty.

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 23, 2010, 04:24:26 PM
Although you have stated this..

Code: [Select]
GetAsteroid(0).CoreHealth = 100

...you have forgotten this one:


Code: [Select]
GetAsteroid(0).MaxCoreHealth = 100

You need to change both.  :>




Like this:

Code: [Select]
function LevelLogic()
mycorehealth = 100
GetAsteroid(0).CoreHealth = mycorehealth
GetAsteroid(0).MaxCoreHealth = mycorehealth
end
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 23, 2010, 04:34:40 PM
Terrial,

Avoid nesting While loops.  Instead, use a series of If statements, like this [pseudocode]:


Code: [Select]
If colortimer is more than [i]this[/i], but less than [i]this[/i], then
  -- season 1
elseif colortimer is more than [i]this[/i], but less than [i]this[/i], then
  -- season 2
elseif colortimer is more than [i]this[/i], but less than [i]this[/i], then
  -- season 3
elseif colortimer is more than [i]this[/i], but less than [i]this[/i], then
  -- season 4
end



Also, the method you are using to make a timer will result in VERY fast seasons.  I think lua runs at 60 or 100 fps, so you will get 1 season per 1-2 sec.  :P
Instead, I would suggest tying your counter to the game time - this is a much more reliable way to set things up.  Use a mechanism something like this:


Code: [Select]
timer = GetGameTime()

for i = 0,100 do
  if timer > 400 then
    timer = timer - 400
  end
end

colortime = timer
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 24, 2010, 01:05:54 AM
sorry alex but it not working, I dare not even post about i for that you be angry or something :$
So, I've changed things so that it is easy to start

I start just for manually change ( like the post : http://www.dyson-game.com/smf/index.php?topic=848.0 )

Code: [Select]
function LevelLogic()
mycorehealth = 100
GetAsteroid(0).CoreHealth = mycorehealth
end
But i dont work. I think that this problem be solved first, then we can make further steps?

the full code ( 2 roids + that funtcion )
(click to show/hide)

Oh DUDE - my mistake! As annikk.exe says it's MaxCoreHealth you want.

Sorry. Also regarding my last post, I was mega stressed out when I wrote that, sorry it was a little terse.

 :-*
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 24, 2010, 01:17:58 AM
You need to change both.  :>

but thank you so much! annikk!

@Alex :
(click to show/hide)

omg xD I was 3 days long search how it works
but we are there to help each other :D !
That's no problem alex, thats understandably xD :-*

Now we will the next steps.

Hmm but i have a question when during the game:
I through : if roid X number of seeds greater than 200 on a asteroid then
so i want change TreeCap on that roid
so that the treecap changing to more or less in cap
but must i beter put it in a
Code: [Select]
while GameRunning() do
coroutine.yield()
or not?
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 24, 2010, 01:21:13 AM
Quote
Avoid nesting While loops.

AHAHAH Wow, it's been so long since I programmed, I should have known better than to try that.

hmm, that for loop.  So does i increase 1 for every game second then?

edit: I tested it and all the colors now cycle through and restart just fine. 

Can someone tell me what the default numbers are for these values in a regular game?

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 24, 2010, 04:47:09 PM
Quote
hmm, that for loop.  So does i increase 1 for every game second then?

Nope, i increases at an arbitrarily fast pace.
The reason for that loop is that, suppose the game time is 1201 seconds.... we don't have any rules for what the colours should change to beyond 400 seconds, so we need to reduce this to a domain that we have rules for.

On the first pass of the loop, the conditions of the If statement are met, and 400 is deducted from that amount to give 801... then on the second pass, another 400 is deducted, giving, 401.  A final loop through triggers the If Statement a third time, and the value drops to 1.

This 1 falls between the limits set for the seasons.  Remember, we only mapped out 400 seconds worth of colour changes, so when we get above that, we want to start again at the beginning.

So because it's i = 0,100 that means we will get roughly 100 full cycles of 4 different seasons, which takes us above 40,000 seconds of game time, which is enough for 11 hours of play.  If you played the level for 12 hours, the seasons would stop.  :P
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 25, 2010, 02:31:21 AM
so if you made the loop go for i =0,200 then it would go for 200 cycles? 

If I were to make Globals.Structures.LevelTime1 (999999) during the winter phase of the game then would that make that level of the the tree pretty much never finish during that season? Same with the spawn rate?
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 25, 2010, 07:18:03 AM
I was working now on the effect of the backdropcolour
You will begin on roid 0 and if you go to roid 2,3 or 4 than set the SetBackdropColour to SetBackdropColour(0,0,0) that working
but if i gi back i wanne have a normale backdropcolour
I hope it the good a setpoint
but that dont work
or must i use also else? but may I  it leave blank?
here is the code :

Code: [Select]
function OnAsteroidRevealed(id, owner)

if id == 2 or id == 3 or id == 4 then
SetBackdropColour(0,0,0)
elseif id == 0 then
SetBackdropColour(255,255,255)
end

end

@annikk i like that with your red fleshing things can you a little explain how this works? :p
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 25, 2010, 07:37:39 AM
so if you made the loop go for i =0,200 then it would go for 200 cycles? 

Yes.  I figured 100 was plenty tho.  :>


Quote
If I were to make Globals.Structures.LevelTime1 (999999) during the winter phase of the game then would that make that level of the the tree pretty much never finish during that season? Same with the spawn rate?

I don't know.  Probably.  Try it.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 25, 2010, 07:50:39 AM
I was working now on the effect of the backdropcolour
You will begin on roid 0 and if you go to roid 2,3 or 4 than set the SetBackdropColour to SetBackdropColour(0,0,0) that working
but if i gi back i wanne have a normale backdropcolour

When the seedling makes its return journey, you're not revealing any asteroids.  So the elseif id == 0 then is never triggered.


You will need to do this in function LevelLogic() instead.


If you don't already have a while GameRunning() loop, make one.  Then inside it you need to put something like this:


Code: [Select]
noseeds = 0

for i = 2,4 do
if GetAsteroid(i):GetNumSeedlings(1) > 0 then
SetBackdropColour(255,255,255)
elseif GetAsteroid(i):GetNumSeedlings(1) == 0 then
noseeds = noseeds + 1
end
end

if noseeds == 3 then
SetBackdropColour(255,255,255)
end


Remember, you will need to put this code inside a while GameRunning() loop, which should be inside function LevelLogic()






Quote
@annikk i like that with your red fleshing things can you a little explain how this works? :p

There is a specific state that the Infected AI is in when it orders the gather point to attack a target asteroid.  I set a variable called rcolour when this happens, to be equal to rcolour + 180.
Inside the AI engine's while loop, there is a command to set the background to rcolour for the red component of the colour.  There is also a part that checks whether rcolour is more than 0 - if it is, it subtracts 1 from rcolour.

This means that the red fades out of the background colour over the course of about 3 seconds.  If the AI launches several attacks in quick succession, as it is prone to do when swarming out of control, the background momentarily becomes an even more intense shade of red.
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 26, 2010, 05:28:33 PM
Can someone tell me what the default numbers are for these values in a regular game?

(click to show/hide)

If you check out the file Resources/default.xml, that has some values in it that are used when no others are given in the level xml or lua.
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 26, 2010, 05:44:07 PM
Oh thank you! I never noticed that file before!

edit:

So I'm having a problem, when a tree is planted during a certain phase, it keeps the global variable from when it was planted.  For instance, if you plant a tree during the winter phase when they arn't supposed to grow, then it doesn't grow.  When the spring phase comes, it does not start to grow, instead it keeps it's time levels from when it was planted, and trees planted in spring do not change their growing behavior in the summer phase.  How can I fix this?


(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 26, 2010, 07:34:45 PM
That's not an easy one to fix.  There doesn't seem to be a provision for editing the stats of pre-existing trees.  Unless Alex knows a sneaky way to do it...

I suppose one way to do it would be to abandon the spawn timing for trees, and simply make it such that every spring, all trees level up once.  Bit of a weak solution though.  I'll have a think on this and see if I can figure out something else cool.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 26, 2010, 07:59:53 PM
Not tried this myself, but how about:


Code: [Select]
for surething = 0,400 do
a = GetEmpire(1):GetRandomAsteroid()
s = a:GetRandomDysonTree()
s.LevelTime1 = 30
s.LevelTime2 = 30
s.LevelTime3 = 30
s.LevelTime4 = 30
end

Does that let you change them?
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 26, 2010, 09:17:18 PM
Bit of a waste though. I'll see if I can put something in.
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on July 27, 2010, 02:59:37 AM

Code: [Select]
for surething = 0,400 do
a = GetEmpire(1):GetRandomAsteroid()
s = a:GetRandomDysonTree()
s.LevelTime1 = 30
s.LevelTime2 = 30
s.LevelTime3 = 30
s.LevelTime4 = 30
end

Does that let you change them?

I tried putting that in and it stopped the progression of the seasons.  Also, I think that, that random function could very possibly miss trees.

@Alex: That would be awesome if you could add something!
Title: Re: Level design/ Code questions from a beginner
Post by: Alex on July 27, 2010, 03:06:07 AM
That's why he's doing it 400 times, just to brute force it and hope all the trees get chosen... you need to be able to iterate over the trees really.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 27, 2010, 05:23:09 AM
When the seedling makes its return journey, you're not revealing any asteroids.  So the elseif id == 0 then is never triggered.

Of cours becaus we have al ready "revealing" that asteroid in the begin of the game
I gonne try it now, but first i take a stroopwafel (img : http://sannieslog.punt.nl/upload/stroopwafel.jpg (http://sannieslog.punt.nl/upload/stroopwafel.jpg)

Edit Adding on 27/07/2010
i have change this :
Code: [Select]
for i = 2,4 do
to
Code: [Select]
for i = 2,3,4 do
but it was not working only for i = 2,4 do there a possible to more than 2 roids?

Edit again xD But :D a good reason xD
I've now solved this by using:
Code: [Select]
for i = 2,4 or 3 do
Edit : Now a big problem it must something block
the colour mai change only of you send de seeds to a asteroid
if you have a now born seed.... change the colour
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 28, 2010, 09:29:19 PM
When the seedling makes its return journey, you're not revealing any asteroids.  So the elseif id == 0 then is never triggered.

Of cours becaus we have al ready "revealing" that asteroid in the begin of the game
I gonne try it now, but first i take a stroopwafel (img : http://sannieslog.punt.nl/upload/stroopwafel.jpg (http://sannieslog.punt.nl/upload/stroopwafel.jpg)

Edit Adding on 27/07/2010
i have change this :
Code: [Select]
for i = 2,4 do
to
Code: [Select]
for i = 2,3,4 do
but it was not working only for i = 2,4 do there a possible to more than 2 roids?

That new code is NOT correct.
The old one was fine.

The old one counts 2,3,4.  You're saying "count from 2 to 4".  That inevitably includes 3 too.

Here's another example:

Code: [Select]
for count = 5,10 do
This means "count from 5 to 10".
So it will count 5, 6, 7, 8, 9, 10.




Quote
Edit again xD But :D a good reason xD
I've now solved this by using:
Code: [Select]
for i = 2,4 or 3 do

No idea where you are getting this from...  why not just use the correct one that I gave you?



Quote
Edit : Now a big problem it must something block
the colour mai change only of you send de seeds to a asteroid
if you have a now born seed.... change the colour

Post your whole code.  It sounds like you've messed things up a bit.
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 29, 2010, 01:16:12 AM
FOR loops:

for a,b,c do
     --stuff here
end

in the above 'example',  a is the start number, b is the end, c is the size of the step.

If you used

for 2,3,4 do

then it would use the value 2, then stop, because 2+4 is 6, bigger than 3.

Someone should write a general LUA reference, for things like while loops, for loops, if-elseif-else blocks, etc, rather than just eufloria specific code.

I could do it next week, but if anyone else want to do it before then, be my guest.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 29, 2010, 04:19:01 AM
Oeps sorry annikk, Yesterday I had done something that was not working asteroid 3
that why
but now it works great
but i wanne now if i go to a other roid must change to black
so i tried :

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 29, 2010, 06:17:10 AM
Code: [Select]
while GameRunning() do

noseeds = 0

for  i = 2,6 do
if GetAsteroid(i):GetNumSeedlings(1) == 0 then
noseeds = noseeds + 1
end
end

if noseeds == 5 then
SetBackdropColour(0,0,0)
elseif noseeds ~= 5 then
SetBackdropColour(150,0,0)
end

coroutine.yield()
end
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on July 29, 2010, 06:20:04 AM
That code will set the background colour to red if there are no seeds on Asteroids 2, 3, 4, 5, and 6.  If there are seeds, it sets the colour to black.


The reason I am checking if noseeds is equal to 5, is because we are checking for the presence of seedlings on 5 different asteroids.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 29, 2010, 06:55:22 AM
but i wanne set more SetBackdropColour :$ that is what i mean :$ ( soory my fault )
like i trying the last code
roid 0 : SetBackdropColour(255,127,39)
roid 1 :SetBackdropColour dark blue
roid 2-4 : red
roid x : that collour
 
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 29, 2010, 07:00:41 AM
maybe i can for a 3e collour
use hmmmm like this?
hmmm i must this calculate.....
example
Code: [Select]
elseif noseeds ~= 6 then
SetBackdropColour(200,0,0)
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 29, 2010, 07:10:14 AM
Annikk, I'd streamline that code if I were you.

The last bit doesn't need the elseif, it can just be
Code: [Select]
if noseeds == 5 then
--blah
else
--more blah
end
If x==y is false, then x~=y MUST be true (don't mention cats in boxes, please), so doesn't need to be checked.

In fact, that for loop could be done away with completely, and replaced with

Code: [Select]
if #check seeds on 2# and #check seeds on 3# and #check seeds on 4# and #check seeds on 5# and #check seeds on 6# then

--blah

else

-- more blah

end

noseeds can be removed, freeing it up even more.

I've not got access to Eufloria at the moment, so can't do any speed checks, but I think that's more efficient.

EDIT: The second codeblock (no for loop) speeds it up because there are, worst-case, only four tests, whereas before, there were five inside the for loop, to check if there were seeds on that asteroid, the for loop itself, which takes time, and memory in the form of the counter variable, one to check if noseeds == 5, and if not, another(completely redundant) check to see if it was not equal to 5. There was also noseeds to deal with.

So, six ifs, two variables before, four ifs, no variables after. Sorry if that sounds grumpy, or harsh or something, it's honestly not meant to be. Just showing the changes, not trying to say ' I'm better than you. '
Title: Re: Level design/ Code questions from a beginner
Post by: Bonobo on July 29, 2010, 07:22:13 AM
[..]

If x==y is false, then x~=y MUST be true (don't mention cats in boxes, please) [..]

ROTFL I’ve let that dead cat run free 20 yrs ago and it comes to my back door every day and meeows for more zombie fodder ;D
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 30, 2010, 01:05:15 AM
but what means this? :
Code: [Select]
~=
the things that I know of:
>= greater than or equal
<= less than or equal
== eqaul

are ther more of this?
Title: Re: Level design/ Code questions from a beginner
Post by: Pilchard123 on July 30, 2010, 01:08:28 AM
It means is NOT equal to, in LUA.

So, 3 ~= 4 is true, but 3~=3 is false.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on July 30, 2010, 04:19:53 AM
also i dont understant this

Code: [Select]
if noseeds == 5 then
SetBackdropColour(255,127,39)

but the noseeds is 0 how can it set that SetBackdropColour(255,127,39)?
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on August 01, 2010, 09:58:48 PM
w4tc,


I took a look at the code you sent.


Please can you describe to me what you want it to do?  It's not clear.

For example...

The background colour starts off (255,127,39), but if you send a seedling to asteroid 3 it becomes red.
If you move the seedling back off asteroid 3, it goes back to being (255,127,39).
If you move the seedling onto asteroid 30, the background turns blue.  When you move it off again, it goes back to (255,127,39).

So what do you want to happen when you have a seedling on asteroid 3 and asteroid 30 at the same time?



Please explain, in as much detail as possible, what you would like the code to do.  Then I can help you.

Also, please stop PM'ing me; I will not reply to PM's about coding, if you want help with coding then post it here on the open forum.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 02, 2010, 12:15:02 AM
Hello Annikk
Oopes xD sorry for PM'ing you :$

There are 5 Colour's
The begin/start colour and the 4 step's or groups of colour's:

So background colour begins on (255,127,39) that is roid 0 ( colour soft organe )
The colour change only when you send your seeds to a ohter roid
[Step 1] The change the colour of roid 1-4 is : lime green
[Step 2] The change the colour of roid 5-7 is : dark red
[Step 3] The change the colour of roid 8-14  is : black
[Step 4] The change the colour of roid 15-33  is : blue

So a example
you are on roid 7  ( than is it the colour normal dark red )
if you send your seed to roid 8  than change the clour to black
if you send it back to roid 7  than it change to dark red

but if you send from roid 16  ( than is it the colour normal blue)
to roid 8  than must de colour change to black

for send at the same time :
it has nothing to do from where you send
but to where you send

example
You have just send a a seed to roid 4  than isnormale your colour lime green
you plant your seeds and you want to go, to roid 5
you send from roid 4 to roid 5 than will change the colour from limegreen to dark red

but you send also at the same time fromroid 15 to  roid 8
here at that moment will not change things becaus you have send a seed to roid 4 so it still lime green
now the seeds they come closer from  roid 4 to roid 5
they are just arrived at their destination ! so now change the colour from lime green to dark red....
woow yes :D and now the seeds of roid 15 are also arrived on  roid 8
now is it the colour black

So i hope i have now al little more clear


I have just a little question :
how can you tell that Owner 2 should not be moving with his seeds to ohtere?







Title: Re: Level design/ Code questions from a beginner
Post by: InTouch on August 02, 2010, 12:40:22 AM
Can I get some coding help? I need to make a win condition. Soo I requested a king of the hill map. You can see my thread on the front page of this section. Ok so what I need help coding is a win condition and a timer and a message on event. I need a win
/ lose condition of holding an asteroid for a set amount of minutes. Also I need a timer for each empire that starts/resumes when they take an asteroid and pauses when they don't have it. Also is there a way to make an asteroid look different from the others?
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 02, 2010, 01:46:47 AM
hmmm let me try help you,i thing you need something like this


Code: [Select]

TimerWin = GetGameTime() + 60

if TimerWin == GetGameTime()  then
Pause()
MessageBox("Victory!")
WaitDialog()
Unpause()
Quit(true)
end
end

but can you explain better, how exactly works King of the Hill?
Title: Re: Level design/ Code questions from a beginner
Post by: InTouch on August 02, 2010, 02:20:25 AM
There's a specified asteroid that you have to take and hold for a specified time. It can be left for an unlimited time
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 02, 2010, 02:30:57 AM
So if good I understand it, you must first conquer roids
and then start your timer to run for example 5 minutes and then you have won
but when the enemy comes back to conquer the counter will stop and you have to start over again.
is it that what you mean?
Title: Re: Level design/ Code questions from a beginner
Post by: InTouch on August 02, 2010, 02:43:55 AM
i only need the timer for 1 roid. the "hill" in king of the hill. and the timer just pauses when you lose the asteroid
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 02, 2010, 03:33:27 AM
I'm almost there
I just let the code you see

(click to show/hide)

But it can not realy work becaus the GetGameTime is a larger number befour it is equal
to the TimerKingoftheHill
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on August 02, 2010, 03:50:50 AM
Try this for your king of the hill, I'm pretty sure this will work:

Code: [Select]
function LevelLogic()  --holds code to run during the game

TimerWin = GetGameTime() + 9999999

while GameRunning() do

Challenger = GetAsteroid(AsteroidOfTheHillVariety).Owner


if Challenger ~= KingOfHill then
TimerWin = GetGameTime() + 60
KingOfHill = Challenger
Pause()
MessageBox("The Hill's Owner has changed!")
WaitDialog()
Unpause()
end

if TimerWin == GetGameTime() and KingOfHill == 1 then
Pause()
MessageBox("Victory!")
WaitDialog()
Unpause()
Quit(true)
elseif TimerWin == GetGameTime() and KingOfHill ~= 1 then
Pause()
MessageBox("You Have been Bested!")
WaitDialog()
Unpause()
Quit(true)
end

coroutine.yield()  --DO NOT DELETE THIS
end --EndGameRunning


end --LevelLogicEnd

edit: You will need something that makes the AI attack the Hill asteroid, or it will just be boring when you take it and they don't even try.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 02, 2010, 07:02:53 AM
Ok i have find it  ;D ( edit : i thing )


Here is the code

(click to show/hide)

Ok what you need to do here is
Roid_ofkingofthehill this must you change to a number of a asteroid
and about this : TakeARoidThatYouNotUsed

if i understand what you mean http://www.dyson-game.com/smf/index.php?topic=774.msg5985#msg5985 (http://www.dyson-game.com/smf/index.php?topic=774.msg5985#msg5985)
than i understand there is not realy a "defeated"
so what you need to do is make a asteroid
like this

(click to show/hide)

we must add the defeated trigger about the game will crash and that no good
so we have put a defeated trigger to a asteroid that we not can see ingame
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on August 02, 2010, 08:01:11 AM
I'm pretty sure I had it right.

w4tc: The way he wants the level, is everyone tries to take the asteroid that acts as the hill.  When a new person takes the hill the timer resets.  If someone manages to hold the hill for the whole timer then they are the one that wins.  So if the AI holds the hill for the whole timer then you lose.
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 02, 2010, 08:25:17 AM
Code: [Select]
So if the AI holds the hill for the whole timer then you loseHmmmm than i mis understand sorry.
So if the AI takes over the hill roids than one time too early to run?
the same as owner1? or longer

But i tried also your code, but if i take the hill roid for more than 1 min but nothing happens :S ???

Edit
I there need also a lose condition for the AI whit the same time than is it just :

(click to show/hide)

Roid_ofkingofthehill this must you change to a number of a asteroid for you King of the hill roid
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on August 02, 2010, 08:37:22 AM
hmm, I don't know why it's not working.  I have to go to work now, but maybe annike can figure something out
Title: Re: Level design/ Code questions from a beginner
Post by: InTouch on August 02, 2010, 09:51:54 AM
i tried making a test map using euclid but it throws an error saying:
Unable to load level
Resources/Maps/test.lua:117:'end'
expected (to close function at line 99)
near'<eof>'
 ??? ???
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 02, 2010, 09:57:55 AM
can you have you code?
Title: Re: Level design/ Code questions from a beginner
Post by: Terrial on August 02, 2010, 06:04:15 PM
I got the level to work.  It wasn't recognizing when the timer = the game time  I fixed it by making it <=

So I'm putting together the asteroids now.  I should have the level up later today.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on August 05, 2010, 02:51:14 AM
W4tc,

I have finally got around to reading your post properly, and building a response.

These changes should provide the functionality you described:



You'll need to make an array for this.
So you need to initialise the array first, you do that in function LevelSetup() using this command:


Code: [Select]
seednumber = {}


All the array slots start out with the value nil.  We want them to start with the value 0.  So initialise the needed slots like this:


Code: [Select]
for seedset = 1,33 do
seednumber[seedset] = 0
end




Finally, make sure you have set the initial background colour:

Code: [Select]
SetBackdropColour(255,127,39)



Next, put this code into function LevelLogic, replacing any existing while loops.




Code: [Select]

while GameRunning() do

for i = 1,4 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] then
SetBackdropColour(0,255,0)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end


for i = 5,7 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] then
SetBackdropColour(155,0,0)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end


for i = 8,14 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] then
SetBackdropColour(0,0,0)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end


for i = 15,33 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] then
SetBackdropColour(0,0,255)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end



coroutine.yield()
end


Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on August 05, 2010, 03:05:48 AM
RE King of the hill win condition.


I'm interpreting your requirements to mean the following, if this is not right, please say so:


Asteroid 0 will be the King of the Hill asteroid.

There will be two timers, they are called playertimer and aitimer.

playertimer ticks up for the player (empire 1) for every second they own the asteroid.
aitimer ticks up for the enemy (empire 2) for every second they own the asteroid.
If neither empire 1 or empire 2 own asteroid 0, no timer will tick up.

If playertimer reaches 180 sec, empire 1 (the player) wins, and the game ends.
If aitimer reaches 180 sec, empire 1 (the player) loses, and the game ends.



Is this correct?  Let me know if it is, and I'll show you how to make a win condition like this.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 05, 2010, 04:50:27 AM
OYEAAA
that is working =D

but :$ i may only change when you it send
now it also change with if there a born seed is
So there must be a way that that can block

Also :$ i have 2 questions :

how can I that Owner 2 or IA should not be moving with his seeds to ohtere roid
i want it only send a seed of owner 1 or with commend like return to fluffy ( your level ) with that waves ect :o

and i tried to make me defent and dysontree to level up but it dont works? :s
here is an example

(click to show/hide)
Title: Re: Level design/ Code questions from a beginner
Post by: InTouch on August 05, 2010, 07:23:52 AM
Quote from: annikk.exe link=topic=774.msg6072#msg6072 date=
RE King of the hill win condition.


I'm interpreting your requirements to mean the following, if this is not right, please say so:


Asteroid 0 will be the King of the Hill asteroid.

There will be two timers, they are called playertimer and aitimer.

playertimer ticks up for the player (empire 1) for every second they own the asteroid.
aitimer ticks up for the enemy (empire 2) for every second they own the asteroid.
If neither empire 1 or empire 2 own asteroid 0, no timer will tick up.

If playertimer reaches 180 sec, empire 1 (the player) wins, and the game ends.
If aitimer reaches 180 sec, empire 1 (the player) loses, and the game ends.



Is this correct?  Let me know if it is, and I'll show you how to make a win condition like this.  :>



Actually terrial has found the right code for me and we are currently working on a map using it.
I sent you a pm requesting your help with something
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on August 05, 2010, 07:35:36 AM
Replied.  Best of luck if you decide to go ahead without me, or thanks for your patience if not.  :>
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on August 05, 2010, 08:08:43 AM
OYEAAA
that is working =D

but :$ i may only change when you it send
now it also change with if there a born seed is
So there must be a way that that can block



Ok, try this code instead:


Code: [Select]
while GameRunning() do

for i = 1,4 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] and GetAsteroid(i):GetNumTrees() == 0 then
SetBackdropColour(0,255,0)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end


for i = 5,7 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] and GetAsteroid(i):GetNumTrees() == 0 then
SetBackdropColour(155,0,0)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end


for i = 8,14 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] and GetAsteroid(i):GetNumTrees() == 0 then
SetBackdropColour(0,0,0)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end


for i = 15,33 do
if GetAsteroid(i):GetNumSeedlings(1) > seednumber[i] and GetAsteroid(i):GetNumTrees() == 0 then
SetBackdropColour(0,0,255)
end
seednumber[i] = GetAsteroid(i):GetNumSeedlings(1)
end



coroutine.yield()
end


Not ideal I guess, but hopefully this will do...
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on August 05, 2010, 08:12:15 AM
Quote
how can I that Owner 2 or IA should not be moving with his seeds to ohtere roid

Script it so that when Empire 2 owns the asteroid, its send distance drops to 0.  When Empire 1 owns the asteroid, its send distance goes back to normal.
Title: Re: Level design/ Code questions from a beginner
Post by: annikk.exe on August 05, 2010, 08:14:54 AM
Quote
Code: [Select]
s= c:AddDysonTree() -- DysonTree 1


Try this instead:

Code: [Select]
s = c:AddDysonTree() -- DysonTree 1
Dunno if it will make a difference... but maybe.. :>
Title: Re: Level design/ Code questions from a beginner
Post by: w4tc on August 15, 2010, 11:01:21 PM
sorry annikk that code dont work :$
about this : http://www.dyson-game.com/smf/index.php?topic=774.msg6100#msg6100