Euflorium: The Eufloria Community

Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: Pilchard123 on June 13, 2010, 01:04:35 AM

Title: Um....help?
Post by: Pilchard123 on June 13, 2010, 01:04:35 AM
I've just made a very simple map (only two asteroids) as a practice for making better stuff, and the attached message comes up. Any help?

If it's of any use, here's the code.
Code: [Select]
function LevelSetup()




-- Asteroid 0
a = AddAsteroidWithAttribs(0,0,1,1,1)
a.Owner = 1
a.TreeCap = 2
a:SetRadius(50)

a.AddSeedlings(50)
s = AddDysonTree()
s:LevelUp


-- Asteroid 1
a = AddAsteroidWithAttribs(400,0,1,1,1)
a.Owner = 0
a.TreeCap = 5
a:SetRadius(50)


end

function LevelLogic()
gamewon = 0
roidnumber = 2
while GameRunning() do
if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
gamewon = 1
elseif GetEmpire(1):GetNumOwnedAsteroids() == roidnumber then
gamewon = 2
end
coroutine.yield()
end


while gamewon == 0 do

coroutine.yield()
end

if gamewon == 1 then
Pause()
WaitDialog()
MessageBox('You have won.')
Unpause()
Quit(true)
end

if gamewon == 2 then

Pause()
MessageBox('You have lost.')
Unpause()
Quit(false)
end

end
Title: Re: Um....help?
Post by: annikk.exe on June 13, 2010, 07:51:07 AM
I'm proof-reading your code now.


On the first asteroid, you have this line:


Code: [Select]
s:LevelUp
which should really be this:

Code: [Select]
s:LevelUp()
Title: Re: Um....help?
Post by: annikk.exe on June 13, 2010, 07:57:41 AM
Ok there's a problem in your function level logic too.

Code: [Select]
while GameRunning() do
This is the first While loop.
It will never end.  The game is always running.  :>

Therefore your second While loop will never be triggered.  The game will go on spinning around the first While loop forever, and never get to the parts below it.
To fix, I'd suggest ditching the second While loop altogether, and instead replace the above-quoted line with the following:

Code: [Select]
while gamewon == 0 do
Title: Re: Um....help?
Post by: annikk.exe on June 13, 2010, 08:02:21 AM
Also I found this:


Code: [Select]
a.AddSeedlings(50)
Adding seedlings is a function, not a property of the asteroid :>
Dots imply a property.  Colons imply a function.


Should be this:

Code: [Select]
a:AddSeedlings(50)
Title: Re: Um....help?
Post by: annikk.exe on June 13, 2010, 08:03:33 AM
Also this:

Code: [Select]
s = AddDysonTree()
should be this:

Code: [Select]
s = a:AddDysonTree()
Title: Re: Um....help?
Post by: annikk.exe on June 13, 2010, 08:07:19 AM
I would recommend adding this line at the very beginning of your LevelSetup()


Code: [Select]
Globals.G.Asteroids=0
If you don't add this line, the game will assume there ought to be lots of asteroids, and will procedurally generate a few dozen in a ring.  Since you only want the asteroids you specify to exist, you set the global default number to 0.  That way only the asteroids you subsequently declare will be added to the game.

Can try removing it later, if you want to see what happens in its absence.  :>
Title: Re: Um....help?
Post by: annikk.exe on June 13, 2010, 08:15:22 AM
Few more bits and pieces.


   Globals.G.EnemyFactionsMin=(0)
   Globals.G.EnemyFactionsMax=(0)


These lines in your LevelSetup() will prevent the game from auto-adding enemy empires that you don't want.


If the win condition is met, this is what happens:


Code: [Select]
Pause()
MessageBox('You have lost.')
Unpause()
Quit(false)



It says lost instead of won.
Also, you need a WaitDialog() after the MessageBox.




If the lose condition is met, this is what happens:


Code: [Select]
Pause()
WaitDialog()
MessageBox('You have won.')
Unpause()
Quit(true)


It says won instead of lost.
Also, the WaitDialog() should be after the MessageBox, not before.
Title: Re: Um....help?
Post by: annikk.exe on June 13, 2010, 08:19:24 AM
Working version, with the changes listed above.
(click to show/hide)

Don't click the button though.  :>  You'll wind up a better coder if you take 10 minutes to apply the changes listed above on your own.  Plus, it's way more satisfying.  :>
But yea, it's there if you really get stuck.
Title: Re: Um....help?
Post by: Pilchard123 on June 14, 2010, 01:31:38 AM
Thanks annikk. I've just worked out what the error message means - I was using UTF-8 encoding, not ANSI. Why I didn't check that, I don't know.
Title: Re: Um....help?
Post by: annikk.exe on June 14, 2010, 08:38:50 AM
Ah right - heh.  :>  Didn't think of that.  I was kind of bemused when I didn't find any reference to a variable called "i" on line 1...
Title: Re: Um....help?
Post by: Alex on June 14, 2010, 06:13:26 PM
I love you guys!  :-*
Title: Re: Um....help?
Post by: annikk.exe on June 14, 2010, 08:48:33 PM
We love you too!!! <3