function LevelLogic()
while GameRunning() do
-- later on we'll put some commands here!
coroutine.yield()
end
end
function LevelLogic()
while GameRunning() do
-- later on we'll put some commands here!
coroutine.yield()
end
-- CODE PLACED HERE WILL NEVER RUN
end
That is because the condition of the while loop is "while the game is running". The game is always running! :> The game is only considered to have ended when the player quits, or a Quit() command is triggered, causing the player to return to the menu.function LevelLogic()
while GameRunning() do
-- if player 1 has conquered whole galaxy then
-- Quit(true)
-- if player 1 has lost all asteroids then
-- Quit(false)
coroutine.yield()
end
end
if GetEmpire(1):GetNumOwnedAsteroids() == 20 then
Pause()
MessageBox("You have won")
WaitDialog()
Unpause()
Quit(true)
end
if GetEmpire(2):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have won")
WaitDialog()
Unpause()
Quit(true)
end
if GetEmpire(2):GetNumOwnedAsteroids() == 0 and GetEmpire(0):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have won")
WaitDialog()
Unpause()
Quit(true)
end
if GetEmpire(2):GetNumOwnedAsteroids() == 0 and GetEmpire(3):GetNumOwnedAsteroids() == 0 and GetEmpire(0):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
function LevelLogic()
while GameRunning() do
-- if player 1 has conquered whole galaxy then
-- Quit(true)
-- if player 2 has lost all asteroids then
-- Quit(false)
coroutine.yield()
end
end
function LevelLogic()
while GameRunning() do
-- win condition
if GetEmpire(2):GetNumOwnedAsteroids() == 0 and GetEmpire(3):GetNumOwnedAsteroids() == 0 and GetEmpire(0):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have won")
WaitDialog()
Unpause()
Quit(true)
end
-- if player 2 has lost all asteroids then
-- Quit(false)
coroutine.yield()
end
end
function LevelLogic()
while GameRunning() do
-- win condition
if GetEmpire(2):GetNumOwnedAsteroids() == 0 and GetEmpire(3):GetNumOwnedAsteroids() == 0 and GetEmpire(0):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have won")
WaitDialog()
Unpause()
Quit(true)
end
-- lose condition
if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You have lost")
WaitDialog()
Unpause()
Quit(false)
end
coroutine.yield()
end
end
for i = 0,9 do
-- some code goes here
end
for i = 0,2 do
MessageBox("Hallo Fluffy")
end
for i = 0,99 do
GetAsteroid(i).SendDistance = 5000
end
GetAsteroid(0).SendDistance = 5000
GetAsteroid(1).SendDistance = 5000
for i = 0,99 do
GetAsteroid(i).SendDistance = 5000
end
GetAsteroid(0).SendDistance = 5000
GetAsteroid(1).SendDistance = 5000
GetAsteroid(2).SendDistance = 5000
GetAsteroid(3).SendDistance = 5000
GetAsteroid(4).SendDistance = 5000
GetAsteroid(5).SendDistance = 5000
GetAsteroid(6).SendDistance = 5000
GetAsteroid(7).SendDistance = 5000
GetAsteroid(8).SendDistance = 5000
GetAsteroid(9).SendDistance = 5000
GetAsteroid(10).SendDistance = 5000
GetAsteroid(11).SendDistance = 5000
GetAsteroid(12).SendDistance = 5000
GetAsteroid(13).SendDistance = 5000
GetAsteroid(14).SendDistance = 5000
GetAsteroid(15).SendDistance = 5000
GetAsteroid(16).SendDistance = 5000
GetAsteroid(17).SendDistance = 5000
GetAsteroid(18).SendDistance = 5000
GetAsteroid(19).SendDistance = 5000
GetAsteroid(20).SendDistance = 5000
GetAsteroid(21).SendDistance = 5000
GetAsteroid(22).SendDistance = 5000
GetAsteroid(23).SendDistance = 5000
GetAsteroid(24).SendDistance = 5000
GetAsteroid(25).SendDistance = 5000
GetAsteroid(26).SendDistance = 5000
GetAsteroid(27).SendDistance = 5000
GetAsteroid(28).SendDistance = 5000
GetAsteroid(29).SendDistance = 5000
GetAsteroid(30).SendDistance = 5000
GetAsteroid(31).SendDistance = 5000
GetAsteroid(32).SendDistance = 5000
GetAsteroid(33).SendDistance = 5000
GetAsteroid(34).SendDistance = 5000
GetAsteroid(35).SendDistance = 5000
GetAsteroid(36).SendDistance = 5000
GetAsteroid(37).SendDistance = 5000
GetAsteroid(38).SendDistance = 5000
GetAsteroid(39).SendDistance = 5000
GetAsteroid(40).SendDistance = 5000
GetAsteroid(41).SendDistance = 5000
GetAsteroid(42).SendDistance = 5000
GetAsteroid(43).SendDistance = 5000
GetAsteroid(44).SendDistance = 5000
-- ok i can't be bothered writing them all out.
-- hopefully you get the idea...
-- ...
GetAsteroid(97).SendDistance = 5000
GetAsteroid(98).SendDistance = 5000
GetAsteroid(99).SendDistance = 5000
for fluffy = 0,99 do
GetAsteroid(fluffy):AddSeedlings(fluffy)
end
fluffy = {}
Note the unusual shaped brackets. This creates an empty array called fluffy.function LevelLogic()
-- declare the array
fluffy = {}
while GameRunning() do
-- some commands go here later
coroutine.yield()
end
end
fluffy[0] = 2
fluffy[1] = 4
fluffy[2] = 7
fluffy[3] = 9
fluffy[4] = 5
if fluffy[0] == 2 then
MessageBox("w00t!")
end
function LevelLogic()
-- initialise arrays
red = {}
green = {}
blue = {}
-- assign values for the different slots in the arrays
red[0] = 0
green[0] = 0
blue[0] = 0
red[1] = 255
green[1] = 0
blue[1] = 0
red[2] = 0
green[2] = 255
blue[2] = 0
red[3] = 0
green[3] = 0
blue[3] = 255
red[4] = 127
green[4] = 0
blue[4] = 127
while GameRunning() do
-- later on we'll put some commands here!
coroutine.yield()
end
end
function LevelLogic()
-- initialise arrays
red = {}
green = {}
blue = {}
-- assign values for the different slots in the arrays
red[0] = 0
green[0] = 0
blue[0] = 0
red[1] = 255
green[1] = 0
blue[1] = 0
red[2] = 0
green[2] = 255
blue[2] = 0
red[3] = 0
green[3] = 0
blue[3] = 255
red[4] = 127
green[4] = 0
blue[4] = 127
while GameRunning() do
-- Check all the asteroids in turn
for i = 0,4 do
-- if an asteroid has a player mine on it...
if GetAsteroid(i):GetNumMines(1) > 0 then
-- set the backdrop colour to the values for slot i in the red, green and blue arrays
SetBackdropColour(red[i], green[i], blue[i])
end
end
coroutine.yield()
end
end
for i = 0,500 do
red[i] = ?
end
for i = 0,500 do
red[i] = i
end
for i = 0,500 do
red[i] = 1 / i
end
for i = 0,500 do
red[i] = 1 / (i + 1)
end
for i = 0,500 do
red[i] = 1 / (i + 1)
red[i] = red[i] * 255
end
MyRandomNumber = math.random(1,6)
a = AddAsteroidWithAttribs(1500,1200, 0.5,0.5,0.5)
a.owner = 1
a.TreeCap = 3
a.radius = 200
a.SendDistance = 2000
a.Moveable = false
a:AddSeedlings(20)
a = AddAsteroidWithAttribs(1500,1200, 0.5,0.5,0.5)
a.owner = 1
a.TreeCap = math.random(2,5)
a.radius = math.random(100,450)
a.SendDistance = 2000
a.Moveable = false
a:AddSeedlings(math.random(10,50))
a.SendDistance = math.random(1500,2500)
a.radius = math.random(100,450)
a.SendDistance = a.radius * 10
a = AddAsteroidWithAttribs(math.random(-1500,1500),math.random(-1200,1200), 0.5,0.5,0.5)
a.Moveable = true
a = AddAsteroidWithAttribs(math.random(-1500,1500),math.random(-1200,1200), 0.5,0.5,0.5)
a.owner = 1
a.TreeCap = math.random(2,5)
a.radius = math.random(100,450)
a.SendDistance = a.radius * 10
a.Moveable = true
a:AddSeedlings(math.random(10,50))
a = AddAsteroidWithAttribs(math.random(-1500,1500),math.random(-1200,1200), math.random(0,1),math.random(0,1),math.random(0,1))
-- generate X and Y
x = math.random(-1500,1500)
y = math.random(-1200,1200)
-- generate stats
energy = math.random(0,1)
strength = math.random(0,1)
speed = math.random(0,1)
-- add the asteroid
a = AddAsteroidWithAttribs(x,y, energy,strength,speed)
-- generate stats
energy = math.random(0,10) / 10
strength = math.random(0,10) / 10
speed = math.random(0,10) / 10
x = math.sin(GetGameTime())
y = math.cos(GetGameTime())
time = GetGameTime()
x = math.sin(time)
y = math.cos(time)
function LevelLogic()
while GameRunning() do
-- some code goes here later!
coroutine.yield()
end
end
function LevelLogic()
while GameRunning() do
-- record the time
time = GetGameTime()
coroutine.yield()
end
end
function LevelLogic()
while GameRunning() do
-- record the time
time = GetGameTime()
-- calculate a value for "input" by taking the math.sin of time
input = math.sin(time)
coroutine.yield()
end
end
-- input is a value between -1 and 1
input = input + 1
-- now input is a value between 0 and 2
input = input / 2
-- now input is a value between 0 and 1
input = input * 450
-- now input is a value between 0 and 450
input = input + 50
-- now input is a value between 50 and 500!
input = (((input + 1) / 2) * 450) + 50
function LevelLogic()
while GameRunning() do
-- record the time
time = GetGameTime()
-- calculate a value for "input" by taking the math.sin of time
input = math.sin(time)
-- now input is between -1 and 1
input = (((input + 1) / 2) * 450) + 50
-- now input is between 50 and 500
coroutine.yield()
end
end
function LevelLogic()
while GameRunning() do
-- record the time
time = GetGameTime()
-- calculate a value for "input" by taking the math.sin of time
input = math.sin(time)
-- now input is between -1 and 1
input = (((input + 1) / 2) * 450) + 50
-- now input is between 50 and 500
GetAsteroid(0).radius = input
coroutine.yield()
end
end
function LevelLogic()
Pause()
MessageBox("Welcome to happyfuntimeland. Is nice here.")
WaitDialog()
Unpause()
end
function GreetPlayer()
Pause()
MessageBox("Welcome to happyfuntimeland. Is nice here.")
WaitDialog()
Unpause()
end
function LevelLogic()
GreetPlayer()
end
function GreetPlayer()
Pause()
MessageBox("Welcome to happyfuntimeland. Is nice here.")
WaitDialog()
Unpause()
end
function LevelLogic()
DisplayMessage("Welcome to happyfuntimeland. Is nice here.")
end
function DisplayMessage(message)
Pause()
MessageBox(message)
WaitDialog()
Unpause()
end
function LevelLogic()
DisplayMessage("Welcome to happyfuntimeland. Is nice here.")
DisplayMessage("Chase rabbits down holes!!")
DisplayMessage("It's fun and the rabbits enjoy it.")
end
function DisplayMessage(message)
Pause()
MessageBox(message)
WaitDialog()
Unpause()
end
function LevelSetup()
energy = {}
strength = {}
speed = {}
radius = {}
senddist = {}
x = {}
y = {}
for i = 0,math.random(5,15) do
energy[i] = math.random(1,10) / 10
strength[i] = math.random(1,10) / 10
speed[i] = math.random(1,10) / 10
radius[i] = math.random (100,500)
senddist[i] = radius[i] * 10
x[i] = math.random(-5000,5000)
y[i] = math.radom(-5000,5000)
a = AddAsteroidWithAttribs(x[i],y[i],energy[i],strength[i],speed[i])
a.radius = radius[i]
a.SendDistance = senddist[i]
a.Moveable = true
end
end
function LevelSetup()
InitArrays()
for i = 0,math.random(5,15) do
RandomiseAttributes(i)
PlaceTheRoids(i)
end
end
function InitArrays()
energy = {}
strength = {}
speed = {}
radius = {}
senddist = {}
x = {}
y = {}
end
function RandomiseAttributes(RoidID)
energy[RoidID] = math.random(1,10) / 10
strength[RoidID] = math.random(1,10) / 10
speed[RoidID] = math.random(1,10) / 10
radius[RoidID] = math.random (100,500)
senddist[RoidID] = radius[i] * 10
x[RoidID] = math.random(-5000,5000)
y[RoidID] = math.radom(-5000,5000)
end
function PlaceTheRoids(RoidID)
a = AddAsteroidWithAttribs(x[RoidID],y[RoidID],energy[RoidID],strength[RoidID],speed[RoidID])
a.radius = radius[RoidID]
a.SendDistance = senddist[RoidID]
a.Moveable = true
end
function LevelSetup()
GenerateLevel()
end
function GenerateLevel()
InitArrays()
for i = 0,math.random(5,15) do
RandomiseAttributes(i)
PlaceTheRoids(i)
end
end
function InitArrays()
energy = {}
strength = {}
speed = {}
radius = {}
senddist = {}
x = {}
y = {}
end
function RandomiseAttributes(RoidID)
energy[RoidID] = math.random(1,10) / 10
strength[RoidID] = math.random(1,10) / 10
speed[RoidID] = math.random(1,10) / 10
radius[RoidID] = math.random (100,500)
senddist[RoidID] = radius[i] * 10
x[RoidID] = math.random(-5000,5000)
y[RoidID] = math.radom(-5000,5000)
end
function PlaceTheRoids(RoidID)
a = AddAsteroidWithAttribs(x[RoidID],y[RoidID],energy[RoidID],strength[RoidID],speed[RoidID])
a.radius = radius[RoidID]
a.SendDistance = senddist[RoidID]
a.Moveable = true
end
function LevelSetup()
-- roids and stuff created here
for i = 0, math.huge do
if GetAsteroid(i) == nil then
highroidID = i - 1
break
end
end
for i = 0, highroidID do
if GetAsteroid(i).radius > 10 then
playableroidnum = playableroidnum + 1
end
end
function LevelLogic()
--loremipsumdolorsitametfgjdflhldfgnkljndfgdg
end
… do you think a dedicated board, e.g., “Turorials—Learning And Teaching Level Coding” could be appropriate and doable for this kind of threads, so that they won’t be overlooked among all those custom levels submission threads etc.? Or perhaps make ALL such (tutorial) threads sticky? But then this board might soon have too many sticky threads, I think.
math.cos , math.sin , math.tan
Return the cosine, sine and tangent value for a given value in radians.
> = math.cos(math.pi / 4)
0.70710678118655
> = math.sin(0.123)
0.12269009002432
> = math.tan(5/4)
3.0095696738628
> = math.tan(.77)
0.96966832796149
math.deg , math.rad
Convert from radians to degrees and vice versa.
> = math.deg(math.pi)
180
> = math.deg(math.pi / 2)
90
> = math.rad(180)
3.1415926535898
> = math.rad(1)
0.017453292519943
...I would be worried that it might stifle discussion really. Maybe it would be better to have a single thread entitled something like "Eufloria Level Creation Guide". I could reserve the first 20 or 30 posts, then I would be able to make hyperlinks to each individual section in the first post in the thread. That would allow a "contents" section to be created.
...
function OnAsteroidSelected(id)
if id > 7 and id < 15 then
SetBackdropColour(r,g,b)
elseif if > 15 and id < 33 then
SetBackdropColour(r,g,b)
end
end
function OnAsteroidSelected(id)
if GetAsteroid(id).owner == 1 then
if id > 7 and id < 15 then
SetBackdropColour(r,g,b)
elseif if > 15 and id < 33 then
SetBackdropColour(r,g,b)
end
end
end