Author Topic: What are you working on? :D  (Read 34478 times)

0 Members and 1 Guest are viewing this topic.

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #465 on: August 17, 2011, 05:56:43 PM »
...
...

It wouldn't make sense starting at -1, since it's a simple counter. Add 1 when you find a asteroid, that's it.

Also the 0 starting thing, does not even apply to Lua.
While it supports it 0-starting arrays, Lua's idiom is to start at index 1. Unlike the bazilion programming languages that actually start at 0(Due to C influence).
Either way, it does not change the fact that it has nothing to do with it.

If the code doesn't work(Highly likely), it's not that.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #466 on: August 17, 2011, 05:59:41 PM »
Then add an "or 0" the the end... Easy way to handle nil's :)

Edit: Uhhm, it's "or numberOfRoids" not 0, cause 0 will make the variable 0!

Edit 2: doing edits rapidly here, but: This should be added to one of the tutorials, it'll make life easy for some programmers atleast :)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #467 on: August 17, 2011, 06:02:28 PM »
W/ever, I'll do it the old-fashioned way, by hand.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #468 on: August 17, 2011, 06:04:18 PM »
W/ever, I'll do it the old-fashioned way, by hand.



Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #469 on: August 17, 2011, 06:07:05 PM »
...
...

It wouldn't make sense starting at -1, since it's a simple counter. Add 1 when you find a asteroid, that's it.

Also the 0 starting thing, does not even apply to Lua.
While it supports it 0-starting arrays, Lua's idiom is to start at index 1. Unlike the bazilion programming languages that actually start at 0(Due to C influence).
Either way, it does not change the fact that it has nothing to do with it.

If the code doesn't work(Highly likely), it's not that.

Heh, but the Asteroid ID's in the game starts at 0, and you don't wanna miss any of them? And it'll run a nil roid at the end, so it would be catastrophic!

Ask any programmer, things in the PC world starts with 0 usually, but Lua's arrays are intended to start at 1 so humans can easily pick it up I guess :)

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #470 on: August 17, 2011, 06:07:32 PM »
Code: [Select]
function GetAsteroidNumber()
numberOfRoids = 0
for empireID = 0, GetNumFactions() - 1 do

     numberOfRoids = numberOfRoids + GetEmpire(empireID):GetNumOwnedAsteroids()

    end

    return numberOfRoids

end

This work. Tested on two built in maps.
Have fun, kids ;)

Nice meme, Aino ^^

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #471 on: August 17, 2011, 06:09:04 PM »
U tried running a code on the value? I think it will cause a crash o.O

kmercy

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
Re: What are you working on? :D
« Reply #472 on: August 17, 2011, 06:09:59 PM »
Code: [Select]
function Num()
asteroidnum = 0

for d = 0, 100 do
if GetAsteroid(d) ~= nil then
if GetAsteroid(d).radius > 5 then
asteroidnum = asteroidnum + 1
end
end
end
Pause()
MessageBox(asteroidnum)
WaitDialog()
Unpause()
end

Simple

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #473 on: August 17, 2011, 06:13:11 PM »
FUN FACT: I'm an IDIOT!

All/Most of the codes posted work fine. However, if you put them in LevelSetup, they don't take into account any asteroids added randomly, since these are added AFTER LevelSetup. Can you guess where I was counting the asteroids?  :-[

Sorry for wasting everyone's time.

kmercy

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
Re: What are you working on? :D
« Reply #474 on: August 17, 2011, 06:14:38 PM »
FUN FACT: I'm an IDIOT!

All/Most of the codes posted work fine. However, if you put them in LevelSetup, they don't take into account any asteroids added randomly, since these are added AFTER LevelSetup. Can you guess where I was counting the asteroids?  :-[

Sorry for wasting everyone's time.

Another fun fact thats why its a function so use it where you want :)

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #475 on: August 17, 2011, 06:14:47 PM »
...
...
...

Heh, but the Asteroid ID's in the game starts at 0, and you don't wanna miss any of them? And it'll run a nil roid at the end, so it would be catastrophic!

Ask any programmer, things in the PC world starts with 0 usually, but Lua's arrays are intended to start at 1 so humans can easily pick it up I guess :)

Not the problem, because it's not what I am doing in the code.
In the code, I am looping through all empires(which start by zero), and using the GetNumOwnedAsteroids built-in, which returns the number of asteroids.

i.e.
Empire 0 has 2 roids / Empire 1 has 7 roids / Empire 2 has 6 roids

GetNumFactions will return 3, so I need to loop between 0 and the last empire(which is GetNumFactions() - 1, because indeed it starts at zero)

Code: [Select]
numberOfRoids = numberOfRoids + GetEmpire(empireID):GetNumOwnedAsteroids()This on the first run will return 2
On the second it will return 2 + 7 = 9
On the third run it will run 9 + 6 = 15

And in the end returns the last result, which is 15.(What I am not entirely sure, is if empty asteroids have a empire assigned to them. If not, this won't work...)

kmercy

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
Re: What are you working on? :D
« Reply #476 on: August 17, 2011, 06:16:52 PM »
Quote
Not the problem, because it's not what I am doing in the code.
In the code, I am looping through all empires(which start by zero), and using the GetNumOwnedAsteroids built-in, which returns the number of asteroids.

i.e.
Empire 0 has 2 roids / Empire 1 has 7 roids / Empire 2 has 6 roids

GetNumFactions will return 3, so I need to loop between 0 and the last empire(which is GetNumFactions() - 1, because indeed it starts at zero)

Code:
numberOfRoids = numberOfRoids + GetEmpire(empireID):GetNumOwnedAsteroids()
This on the first run will return 2
On the second it will return 2 + 7 = 9
On the third run it will run 9 + 6 = 15

And in the end returns the last result, which is 15.(What I am not entirely sure, is if empty asteroids have a empire assigned to them. If not, this won't work...)

Thats why you just use what i posted

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #477 on: August 17, 2011, 06:20:44 PM »
Quote
Not the problem, because it's not what I am doing in the code.
In the code, I am looping through all empires(which start by zero), and using the GetNumOwnedAsteroids built-in, which returns the number of asteroids.

i.e.
Empire 0 has 2 roids / Empire 1 has 7 roids / Empire 2 has 6 roids

GetNumFactions will return 3, so I need to loop between 0 and the last empire(which is GetNumFactions() - 1, because indeed it starts at zero)

Code:
numberOfRoids = numberOfRoids + GetEmpire(empireID):GetNumOwnedAsteroids()
This on the first run will return 2
On the second it will return 2 + 7 = 9
On the third run it will run 9 + 6 = 15

And in the end returns the last result, which is 15.(What I am not entirely sure, is if empty asteroids have a empire assigned to them. If not, this won't work...)

Thats why you just use what i posted

Yap, yours will run even if empty asteroids are not assigned to empires ;)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #478 on: August 17, 2011, 06:22:19 PM »
Empty asteroids belong to Empire 0, the greys.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #479 on: August 17, 2011, 06:26:49 PM »
I guess I was wrong :)