### Author Topic: GetNumOwnedAsteroids() + GetEmpire()  (Read 951 times)

0 Members and 1 Guest are viewing this topic.

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### GetNumOwnedAsteroids() + GetEmpire()
« on: June 11, 2010, 03:40:40 PM »
How do I check if a certain empire owns all the asteroids, or none of them? Presumably its something the do with the two functions in the title, but how do I use them?

If it helps, I want to check if the player (empire 1?) has all or none of the asteroids.

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0
• Posts: 274
##### Re: GetNumOwnedAsteroids() + GetEmpire()
« Reply #1 on: June 11, 2010, 03:51:15 PM »
annikk's your guy for this one. but id imagine you use the get empire (1) then get num owned asteroids, equal to 0, then do such and such a command ...
just my thought on it

aws

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: GetNumOwnedAsteroids() + GetEmpire()
« Reply #2 on: June 11, 2010, 04:34:44 PM »
The way I do it is, in LevelSetup(), I count (literally or procedurally, depending on how I'm doing the level) how many asteroids there are in the level, then I make a variable called roidnumber equal to that number.

So if I had 10 asteroids in the level, I would do:

Code: [Select]
`roidnumber = 10`

Then, during Levelogic(), I can query how many asteroids a particular empire owns, and check if it is the same as roidnumber, or if it is 0.

If it's equal to roidnumber, then that empire owns all of the asteroids in the level.
If it's equal to zero, well... then that empire doesn't own any asteroids.

Code: [Select]
`While GameRunning() do  if GetEmpire(1):GetNumOwnedAsteroids() == 0 then    -- ooh look, no asteroids.  player 1 suck and fail!  elseif GetEmpire(1):GetNumOwnedAsteroids() == roidnumber then    -- EPIC WIN, i has all asteroids!  end  coroutine.yield()end`

roidnumber is used for loads and loads of stuff in my scripts.  I find it a useful variable to have around.

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Re: GetNumOwnedAsteroids() + GetEmpire()
« Reply #3 on: June 12, 2010, 12:37:40 PM »
Typed on DSi

I'm using you beginner's guide to do what I'm doing, and in particular your win/lose check. Would the gamewon variable be changed in the comments you added to the code you just gave, or elsewhere, and if elsewhere, then where?

Thanks for the help so far.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: GetNumOwnedAsteroids() + GetEmpire()
« Reply #4 on: June 13, 2010, 12:27:37 AM »
Well now that I've read through your level a bit more (in the other thread), and I can see how you've structured things... basically the best way to do it is to make the While loop repeat as long as gamewon = 0.  Then, if either EPIC WIN or PLAYER 1 SUCK & FAIL (the If statements) are triggered, you can add gamewon = 1  or gamewon = 2

Then gamewon doesn't equal 0 anymore.  So the while loop will end, and then you can have some more If statements below that to evaluate whether the game was won or lost, based on whether the gamewon variable is 1 or 2.

This is the reasoning behind the changes I suggested in the other thread.

Great job on this by the way :>  It's not terribly easy to get started, I promise you though it gets easy very quickly :>  And then comes the power....muahahahaha...

#### AWS

• Achiever
• Arboreal Being
• Thank You
• -Given: 0