### Author Topic: Um....help?  (Read 1302 times)

0 Members and 1 Guest are viewing this topic.

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Um....help?
« on: June 12, 2010, 05:04:35 PM »
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)endfunction LevelLogic()gamewon = 0roidnumber = 2while GameRunning() doif GetEmpire(1):GetNumOwnedAsteroids() == 0 thengamewon = 1elseif GetEmpire(1):GetNumOwnedAsteroids() == roidnumber thengamewon = 2endcoroutine.yield()endwhile gamewon == 0 docoroutine.yield()endif gamewon == 1 thenPause()WaitDialog()MessageBox('You have won.')Unpause()Quit(true)endif gamewon == 2 thenPause()MessageBox('You have lost.')Unpause()Quit(false)endend`

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #1 on: June 12, 2010, 11:51:07 PM »

On the first asteroid, you have this line:

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

Code: [Select]
`s:LevelUp()`

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #2 on: June 12, 2010, 11:57:41 PM »
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`
« Last Edit: June 13, 2010, 12:20:13 AM by annikk.exe »

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #3 on: June 13, 2010, 12: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)`

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #4 on: June 13, 2010, 12:03:33 AM »
Also this:

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

Code: [Select]
`s = a:AddDysonTree()`

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #5 on: June 13, 2010, 12: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.  :>
« Last Edit: June 13, 2010, 12:16:40 AM by annikk.exe »

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #6 on: June 13, 2010, 12: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.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #7 on: June 13, 2010, 12: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.
« Last Edit: June 13, 2010, 12:57:09 PM by annikk.exe »

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Re: Um....help?
« Reply #8 on: June 13, 2010, 05:31:38 PM »
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.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Um....help?
« Reply #9 on: June 14, 2010, 12: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...

#### Alex

• Ent
• Thank You
• -Given: 3
• Posts: 1,035
##### Re: Um....help?
« Reply #10 on: June 14, 2010, 10:13:26 AM »
I love you guys!

• Achiever
• Ent
• Thank You
• -Given: 0