Author Topic: Not working, why?  (Read 18350 times)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Not working, why?
« on: February 14, 2011, 09:55:43 PM »
I have my project, CC, which will not work what so ever, what mey be the problem?
Code: [Select]
for i = 0,numberofroids do
for j = neighbourstart[i],neighbourend[i] do
if CCpriorities[i] > CCpriorities[j] then
*codes*
end
end
end

And the setup is like this:
Code: [Select]
function CCInit()

numberofroids=-1
for i = 0,200 do
if GetAsteroid(i) ~= nil then
if GetAsteroid(i).radius > 10 then
numberofroids = numberofroids + 1
end
end
end

neighbourstart = {}
neighbourend = {}
neighbournumber = -1
neighbour = {}

for i = 0,numberofroids do
if neighbournumber == -1 then
neighbourstart[i] = 0
else
neighbourstart[i] = neighbournumber
end

for j = 0,numberofroids do
if j ~= i then
if GetAsteroid(j) ~= nil and GetAsteroid(i) ~= nil then
length = GetAsteroid(i).position.x - GetAsteroid(j).position.x
height = GetAsteroid(i).position.y - GetAsteroid(j).position.y

distancetoroid = math.sqrt((length * length) + (height * height))
distancetoroid = distancetoroid - GetAsteroid(j).Radius

if distancetoroid < GetAsteroid(i).SendDistance then

neighbournumber = neighbournumber + 1
neighbour[j] = j

end
end
end
end
neighbourend[i]  = neighbournumber
end

CCpriorities = {}
for i = 0,numberofroids do

CCpriorities[i] = numberofroids

end
end

One of you know why... and the error is nil, but for me it seems I have set everything to what it is supposed to be :(

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #1 on: February 14, 2011, 11:11:56 PM »
Kind of hard to decypher when I don't have a conceptual map of what the code is supposed to do...  but I did notice this bit:



Code: [Select]
neighbournumber = -1
neighbour = {}

for i = 0,numberofroids do
if neighbournumber == -1 then
neighbourstart[i] = 0
else
neighbourstart[i] = neighbournumber
end

In the first line, the variable neighbournumber is set to -1.

Then, you have a conditional to check whether it's equal to -1.  It will ALWAYS be equal to -1, because that's what you've just set it to.

That means that this code will never be run:

Code: [Select]
else
neighbourstart[i] = neighbournumber

Is that ok?  If so, why bother having an "else" there at all?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #2 on: February 14, 2011, 11:14:59 PM »
No, it's not in a while loop, so it just run the For loop and add more and more neighbournumbers. It won't reset, because I have seen it in effect and working :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #3 on: February 14, 2011, 11:16:43 PM »
Code: [Select]
if GetAsteroid(j) ~= nil and GetAsteroid(i) ~= nil then
I know I told you to do this before, but those will ever be nil.  As long as you've made sure any "spacer" asteroids (with radius of 0) have the very highest ID number of any asteroid in the level.
So you could safely remove this line, I think.  It would make the code a little clearer and gets rid of a deeply nested conditional which would improve performance.  :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #4 on: February 14, 2011, 11:19:33 PM »
No, it's not in a while loop, so it just run the For loop and add more and more neighbournumbers. It won't reset, because I have seen it in effect and working :)

Are you sure?  If that's really the case, you could replace these lines:


Code: [Select]
if neighbournumber == -1 then
neighbourstart[i] = 0
else
neighbourstart[i] = neighbournumber
end

..with just this line:

Code: [Select]
neighbourstart[i] = 0
...and it would do the exact same thing as it is doing now.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #5 on: February 14, 2011, 11:30:57 PM »
Figured out one thing:
Code: [Select]
for i = 0,numberofroids do
for j = neighbourstart[i],neighbourend[i] do
if CCpriorities[i] > CCpriorities[j] then
*codes*
end
end
end
is wrong in one way... It got to be like this:
Code: [Select]
for i = 0,numberofroids do
for j = neighbourstart[i],neighbourend[i] do
if CCpriorities[i] > CCpriorities[neighbour[j]] then
*codes*
end
end
end

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #6 on: February 14, 2011, 11:33:49 PM »
But what if I do this?
Code: [Select]
for i = 0,numberofroids do

for j = neighbourstart[i],neighbourend[i] do
if neighbour[j] ~= i then
checkedneighbour = neighbour[j]

if CCpriorities[checkedneighbour] ~= nil then

CCpriorities[checkedneighbour] = numberofroids

elseif CCpriorities[i] > CCpriorities[checkedneighbour] then

CCpriorities[i] = CCpriorities[checkedneighbour] + 1
if GetAsteroid(i):GetNumSeedlings() > CCdefensive then

GetAsteroid(i):SendSeedlingToTarget(1, GetAsteroid(i):GetNumSeedlings() - CCdefensive, GetAsteroid(checkedneighbour))

end
end
end
end
end

EDIT:
SRY!!

This I meant:
Code: [Select]
for i = 0,numberofroids do
for j = neighbourstart[i],neighbourend[i] do
if neighbour[j] ~= i then
checkedneighbour = neighbour[j]

if CCpriorities[checkedneighbour] == nil then

CCpriorities[checkedneighbour] = numberofroids

elseif CCpriorities[i] > CCpriorities[checkedneighbour] and CCpriorities[checkedneighbour] ~= nil then

CCpriorities[i] = CCpriorities[checkedneighbour] + 1
if GetAsteroid(i):GetNumSeedlings() > CCdefensive then

GetAsteroid(i):SendSeedlingToTarget(1, GetAsteroid(i):GetNumSeedlings() - CCdefensive, GetAsteroid(checkedneighbour))

end
end
end
end
or something around that...
« Last Edit: February 14, 2011, 11:38:02 PM by Aino »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #7 on: February 14, 2011, 11:36:40 PM »
Also, neighbourstart[n] will always be equal to 0 for all values of n.

So that means you could change this code:

Code: [Select]
for i = 0,numberofroids do
for j = neighbourstart[i],neighbourend[i] do
if CCpriorities[i] > CCpriorities[j] then
*codes*
end
end
end

To this:

Code: [Select]
for i = 0,numberofroids do
for j = 0,neighbourend[i] do
if CCpriorities[i] > CCpriorities[j] then
*codes*
end
end
end




That would mean you could change this code:

Code: [Select]
function CCInit()

numberofroids=-1
for i = 0,200 do
if GetAsteroid(i) ~= nil then
if GetAsteroid(i).radius > 10 then
numberofroids = numberofroids + 1
end
end
end

neighbourstart = {}
neighbourend = {}
neighbournumber = -1
neighbour = {}

for i = 0,numberofroids do
if neighbournumber == -1 then
neighbourstart[i] = 0
else
neighbourstart[i] = neighbournumber
end

for j = 0,numberofroids do
if j ~= i then
if GetAsteroid(j) ~= nil and GetAsteroid(i) ~= nil then
length = GetAsteroid(i).position.x - GetAsteroid(j).position.x
height = GetAsteroid(i).position.y - GetAsteroid(j).position.y

distancetoroid = math.sqrt((length * length) + (height * height))
distancetoroid = distancetoroid - GetAsteroid(j).Radius

if distancetoroid < GetAsteroid(i).SendDistance then

neighbournumber = neighbournumber + 1
neighbour[j] = j

end
end
end
end
neighbourend[i]  = neighbournumber
end

CCpriorities = {}
for i = 0,numberofroids do

CCpriorities[i] = numberofroids

end
end


To this:


Code: [Select]
function CCInit()

numberofroids=-1
for i = 0,200 do
if GetAsteroid(i) ~= nil then
if GetAsteroid(i).radius > 10 then
numberofroids = numberofroids + 1
end
end
end

neighbourend = {}
neighbournumber = -1
neighbour = {}

for i = 0,numberofroids do

for j = 0,numberofroids do
if j ~= i then
if GetAsteroid(j) ~= nil and GetAsteroid(i) ~= nil then
length = GetAsteroid(i).position.x - GetAsteroid(j).position.x
height = GetAsteroid(i).position.y - GetAsteroid(j).position.y

distancetoroid = math.sqrt((length * length) + (height * height))
distancetoroid = distancetoroid - GetAsteroid(j).Radius

if distancetoroid < GetAsteroid(i).SendDistance then

neighbournumber = neighbournumber + 1
neighbour[j] = j

end
end
end
end
neighbourend[i]  = neighbournumber
end

CCpriorities = {}
for i = 0,numberofroids do

CCpriorities[i] = numberofroids

end
end


Furthermore, if you take my suggestion about removing the nil checks, the code would simply be this:


Code: [Select]
function CCInit()

numberofroids=-1
for i = 0,200 do
if GetAsteroid(i) ~= nil then
if GetAsteroid(i).radius > 10 then
numberofroids = numberofroids + 1
end
end
end

neighbourend = {}
neighbournumber = -1
neighbour = {}

for i = 0,numberofroids do

for j = 0,numberofroids do
if j ~= i then

length = GetAsteroid(i).position.x - GetAsteroid(j).position.x
height = GetAsteroid(i).position.y - GetAsteroid(j).position.y

distancetoroid = math.sqrt((length * length) + (height * height))
distancetoroid = distancetoroid - GetAsteroid(j).Radius

if distancetoroid < GetAsteroid(i).SendDistance then

neighbournumber = neighbournumber + 1
neighbour[j] = j

end

end
end
neighbourend[i]  = neighbournumber
end

CCpriorities = {}
for i = 0,numberofroids do

CCpriorities[i] = numberofroids

end
end


That simplifies the code a lot, but it doesn't explain why it crashes.
So I don't think the true cause the error is here.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #8 on: February 14, 2011, 11:41:01 PM »
Can you just post the whole code so I can see what order everything happens in?


I had a brief look at the new code you posted up anyway.
What's the meaning of this line?


Code: [Select]
if neighbour[j] ~= i then
Shouldn't it be "if j ~= i then" ?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #9 on: February 14, 2011, 11:45:53 PM »
Assuming your latest codes are run _after_ everything else, look at this problem:


Code: [Select]
if CCpriorities[checkedneighbour] ~= nil then

CCpriorities[checkedneighbour] = numberofroids

elseif CCpriorities[i] > CCpriorities[checkedneighbour] then

CCpriorities[i] = CCpriorities[checkedneighbour] + 1
if GetAsteroid(i):GetNumSeedlings() > CCdefensive then

GetAsteroid(i):SendSeedlingToTarget(1, GetAsteroid(i):GetNumSeedlings() - CCdefensive, GetAsteroid(checkedneighbour))

end
end

You already assigned the value for all slots of CCpriorities to be however many asteroids are in the level.  In the first line of this code, you check if it's not equal to nil.  Well, it's never going to be equal to nil, is it?  Because you set it to a number.

So that means that only this line will run:

Code: [Select]
CCpriorities[checkedneighbour] = numberofroids

The rest of that code will never run.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #10 on: February 15, 2011, 12:29:30 AM »
Ok, three posts and three answers:

1st: I can't remove it. Because if you look at scenario like this:

0         5    6
     2      4
 3      1

and all of the numbers are roids...

Let's say 0 reaches 5, 2 and 3 and 2 reaches 0,1,3,4 and 5...

Then: For the neighbours for roid 0 it will start with 0,1 and 2 then for roid 2 it will follow the same and results 3,4,5,6 and 7.

Now all this numbers need to do something, the number is calling a variable (neighbours) which contains the ID for the neighbour it is set to :)


Now cleaning that up, the second question makes sense since neighbour[j] is the ID for the roid...


3rd: Well, look at the updated one, I know I was wrong and it didn't work :P

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #11 on: February 15, 2011, 12:41:31 AM »
it's like it don't want to work at all! God damnit -.-

Only if I add this:
Code: [Select]
and neighbour[j] ~= nil thenbehind:
Code: [Select]
if neighbour[j] ~= i it will begin crashing instead of not doing what is behind, why the hell?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #12 on: February 15, 2011, 01:11:44 AM »
Look, I'm sorry, but I can't help you unless you post the whole code.  Otherwise it's like trying to do a 1000 piece jigsaw with 400 pieces missing.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #13 on: February 15, 2011, 01:13:32 AM »
Ok, reply when u have DL'ed it cause I don't want tho release this just yet :P

I'll just PM you it, how stupid am I? (Very stupid :))

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #14 on: February 15, 2011, 01:15:42 AM »
Ok done.  When you release the map, I will re-attach this file though, so that other people can benefit from our discussions.  Hope that's ok.  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #15 on: February 15, 2011, 01:18:07 AM »
Ye, or maybe I shall :P But not now ... And it's not a map, it's a function and I want it to run smooth because it's not supposed to cause much problems, but that itself causes all these problems -.-

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #16 on: February 15, 2011, 01:18:18 AM »
Maybe it's not working because you forgot the coroutine.yield()


Code: [Select]
function LevelLogic()

while GameRunning() do

CCEngine()
end
end

It's missing.  :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #17 on: February 15, 2011, 01:18:51 AM »
Ye, or maybe I shall :P But not now ... And it's not a map, it's a function

It's still code.  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #18 on: February 15, 2011, 01:20:14 AM »
Holy crap, how can I skip that? D:

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #19 on: February 15, 2011, 01:21:43 AM »
But not a map, but it will be included in a map i guess, else it is useless, hope I will get to use all these functions I make :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #20 on: February 15, 2011, 01:23:11 AM »
Maybe the lack of coroutine.yield() caused the game to crash when I had errors? I don't wanna check though xD

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #21 on: February 15, 2011, 01:24:53 AM »
Sometimes it's the things you least expect.. :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #22 on: February 15, 2011, 01:28:22 AM »
If you have tested the map, you will se a nice little box in the corner, to make people understand it I need to make letters inside there to x.x

... or just make THEM having different colors untill I find the eager to make letters drawable ...

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #23 on: February 15, 2011, 01:30:57 AM »
Strtange.. it haven't reacted on:
Code: [Select]
if CCRallyAllowed == false thenas a nil, because it is nil currently xD

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #24 on: February 15, 2011, 01:52:11 AM »
One last problem, it won't do anything when pressing the box... annikk, you have the code and plaease look at it? I bet I have done the coords wrond though :P

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #25 on: February 15, 2011, 02:03:29 AM »
nah, fix'd it... Gonna release this with a map, but first I wanna test it with EverSwarm :D:D

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #26 on: February 15, 2011, 02:07:31 AM »
HOLY CRAP, It runs smooth as seeding hell... I will use this neighbour system on my AI too, cause I tested it with 108 roids and it runs just like a normal map without it does, or maybe my code has an error that isn't succesfully ruining my code? *Implent dramatic sound here!*

EDIT: Tested with 208 roids(and fixed the numroid thing to recognixe the 8 last too:P) and it runs at the same smoothness level :O

EDIT 2: There is one error that makes it not set priorities correct... Trying to figure out why...
« Last Edit: February 15, 2011, 02:19:28 AM by Aino »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #27 on: February 15, 2011, 02:56:32 AM »
I still have no idea what on earth you are working on... but it sounds cool, and it sounds like you're making progress!  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #28 on: February 15, 2011, 03:03:02 AM »
Lol, ye... I'll PM you the code if you want.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #29 on: February 15, 2011, 10:46:04 PM »
Code: [Select]
function LevelSetup()

Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
Globals.G.GreysProbability=(0)
Globals.AI.GraceTimer=(99999)
SetBackdropColour(0,0,0)

a = AddAsteroidWithAttribs(2000,0, 0.3,0.3,0.3)
a.Owner = 0
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 3500
a:Reveal(1)
a.Moveable = false

a = AddAsteroidWithAttribs(0,0, 0.7,0.6,0.5)

a.Owner = 1
a.TreeCap = 20
a:SetRadius(500)
a.SendDistance = 7000
a.Moveable = false

a:AddSeedlings(20)

a = AddAsteroidWithAttribs(4000,0, 0.3,0.3,0.3)
a.Owner = 0
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 2500
a:Reveal(1)
a.Moveable = false

a = AddAsteroidWithAttribs(6000,0, 0.3,0.3,0.3)
a.Owner = 0
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 2500
a:Reveal(1)
a.Moveable = false

a = AddAsteroidWithAttribs(8000,0, 0.3,0.3,0.3)
a.Owner = 3
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 2500
a:Reveal(1)
a.Moveable = false

a:AddSeedlings(68)

a = AddAsteroidWithAttribs(0,-2000, 0.3,0.3,0.3)
a.Owner = 0
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 3500
a:Reveal(1)
a.Moveable = false

a = AddAsteroidWithAttribs(0,-4000, 0.3,0.3,0.3)
a.Owner = 0
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 2500
a:Reveal(1)
a.Moveable = false

a = AddAsteroidWithAttribs(0,-6000, 0.3,0.3,0.3)
a.Owner = 0
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 2500
a:Reveal(1)
a.Moveable = false

a = AddAsteroidWithAttribs(0,-8000, 0.3,0.3,0.3)
a.Owner = 2
a.TreeCap = 2
a:SetRadius(300)
a.SendDistance = 2500
a:Reveal(1)
a.Moveable = false

a:AddSeedlings(68)

SetCameraPositionToAsteroidID(1)
SetCameraZoomNow(5)

AddAsteroidRing(200, 0, 0, 15000, 150)

CCInit()

end

function ScreenDraw()
maxx = GetScreenWidth()
maxy = GetScreenHeight()
x1 = maxx
y1 = maxy
x2 = maxx - (maxx/15)
y2 = maxy
DrawLine(x1,y1,x2,y2,255,0,0,255,255,0,0,255,5)
x1 = maxx - (maxx/15)
y1 = maxy
x2 = maxx - (maxx/15)
y2 = maxy - (maxy/15)
DrawLine(x1,y1,x2,y2,255,0,0,255,255,0,0,255,5)
x1 = maxx
y1 = maxy
x2 = maxx
y2 = maxy - (maxy/15)
DrawLine(x1,y1,x2,y2,255,0,0,255,255,0,0,255,5)
x1 = maxx
y1 = maxy - (maxy/15)
x2 = maxx - (maxx/15)
y2 = maxy - (maxy/15)
DrawLine(x1,y1,x2,y2,255,0,0,255,255,0,0,255,5)
end

function LevelLogic()

while GameRunning() do

CCEngine()

coroutine.yield()
end
end

function CCInit()

numberofroids=-1
for i = 0,300 do
if GetAsteroid(i) ~= nil then
if GetAsteroid(i).radius > 10 then
numberofroids = numberofroids + 1
end
end
end

neighbourstart = {}
neighbourend = {}
neighbournumber = -1
neighbour = {}

for i = 0,numberofroids do
if neighbournumber == -1 then
neighbourstart[i] = 0
else
neighbourstart[i] = neighbournumber + 1
end

for j = 0,numberofroids do
if j ~= i then
length = GetAsteroid(i).position.x - GetAsteroid(j).position.x
height = GetAsteroid(i).position.y - GetAsteroid(j).position.y

distancetoroid = math.sqrt((length * length) + (height * height))
distancetoroid = distancetoroid - GetAsteroid(j).Radius

if distancetoroid < GetAsteroid(i).SendDistance then

neighbournumber = neighbournumber + 1
neighbour[j] = j

end
end
end
neighbourend[i]  = neighbournumber
end

CCpriorities = {}
barrier = {}
CCdefensive = 10
checked = {}
for i = 0,numberofroids do

CCpriorities[i] = numberofroids
barrier[i] = false
checked[i] = 0

end
end

function CCEngine()
for i = 0,numberofroids do
if barrier[i] == false then
for j = neighbourstart[i],neighbourend[i] do
if neighbour[j] ~= i and neighbour[j] ~= nil then

if CCpriorities[i] > CCpriorities[neighbour[j]] then

CCpriorities[i] = CCpriorities[neighbour[j]] + 1
if GetAsteroid(i):GetNumSeedlings(1) > CCdefensive then

sendthisamount = GetAsteroid(i):GetNumSeedlings(1) - CCdefensive
GetAsteroid(i):SendSeedlingsToTarget(1, sendthisamount, GetAsteroid(neighbour[j]))

end
checked[i] = 1
end
end
end
end
end
end

function OnMouseLeftDownScreen(x,y)
if x >= maxx - maxx and x <= maxx - maxx + (maxx/15) and y >= maxy - maxy and y <= maxy - maxy + (maxy/15) then
for i = 0,numberofroids do
CCpriorities[i] = numberofroids
checked[i] = 0
end
CCpriorities[selectedid] = 0
end
end

function OnAsteroidSelected(id)
print(CCpriorities[id] .. " " .. neighbourstart[id] .. " " .. neighbourend[id] .. " " .. id .. " " .. checked[id])
selectedid = id
end

The checked shows that it ain't checking all roids, acctually just the two first (0,1) but why???

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #30 on: February 15, 2011, 11:37:57 PM »
You need to put comments on most lines of your code, otherwise it's impossible to tell what it's supposed to be doing.
A general description of what problem you are trying to solve, and how, would also help.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #31 on: February 16, 2011, 12:01:03 AM »
Ye, gonna add descriptions from now on :)

And the problem is that the for loop doesn't go trough all the roids(which explains no lag :/) but I dunno why, everything seems fine...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #32 on: February 16, 2011, 12:10:16 AM »
Sorry... when I said "what problem are you trying to solve?" what I really meant was "What is your code supposed to do - overall?"

When you want to code a big project, you should always start by working out what your overall goal is.  You need to be able to define well what ought to happen.  Write this down, and be detailed.

Next, write down (in as much detail as possible) HOW you are going to accomplish this.  Will you use a for loop?  Or several for loops?  What will be inside them, and why? Do you know what equations (such as pythagoras) are going to be needed?  Write all of this down.

If your project is large and complicated, it's also a good idea to draw diagrams of things.  This is an extremely useful exercise and coding things like the 3D engine, gravity engine, and my own AI would have been insanely difficult had I not made diagrams.



Once you've done all that, THEN it's time to start coding.  :>  Whenever you're about to type a line of code that is anything more complicated than initialising or incrementing a variable (or whatever), you should first write out a comment for the line, to say what you want it to do.  Then, on the next line, translate that comment into code.


If you don't follow a process like this, you will run into problems later - as you've perhaps already discovered when you programmed your AI.  :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #33 on: February 16, 2011, 12:14:36 AM »
As an example, look at all the planning I did before writing the new version of Infected AI:


http://www.dyson-game.com/smf/index.php?topic=1171.0


I wrote basically that whole thread before typing a single line of code.  :>  It paid off bigtime.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #34 on: February 16, 2011, 12:52:07 AM »
I wanna code, not write a tons of things D:
I usually run my coding on the idea, not typing it in and then coding it. I am allready having some pieces of paper in front of me, designing stuff(not good though xD) and writing down examples for codes :) Without the I would never figure out aboue neighbourstart and neighbourend and the numbers inbetween stores the acctual ID, that took me some thinking, but seems simple when it is thought of already :)

Main goal in these sentences:

1: I do paint and do stuff before coding, but I also code as it runs into my head, test and fixing all the problem :)
2: I'm gonna begin making comments before making the code 2 reasons:
1: You understand better then...
2: I know what to do better :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #35 on: February 16, 2011, 02:54:25 AM »
That sounds like a good idea.  :>


I know when you get an idea for a level or a function, the temptation is to start coding immediately.  But every 20 minutes you spend planning beforehand will save you an hour or two of troubleshooting later on.. :>
I speak from experience - specifically, the experience of coding Infected AI version 1.  I had the idea, started coding immediately and didn't stop until I was done - which took about 12 hours.  It took an hour of troubleshooting to even get the level to load, and when it finally did, my AI did nothing.  Absolutely squat.  :>
It took months to get IAIv1 right.  AIv2 took me only a couple weeks.  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #36 on: February 16, 2011, 03:01:06 AM »
Lol, nice :) But I have made a map already, I think I will release it now :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #37 on: February 16, 2011, 03:04:27 AM »
Ok.  :>  Are you sure you don't want to get it beta tested first though, in case there are some bugs that you didn't find yourself?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #38 on: February 16, 2011, 03:28:40 AM »
It's not supposed to be on this topic actually, cause it has nothing to do with this :) I guess there will be few bugs, since there isn't much coding, but adding a whole new concept, hows that possible?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Not working, why?
« Reply #39 on: February 16, 2011, 03:32:41 AM »
Well just ask for beta testers on the forum if you need your map tested, then PM them the code.  :>

You'll need to allow a few days for them to play the map and get back to you.

If there's not much scripting it might be ok to just release it as-is though.  Up to you.  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Not working, why?
« Reply #40 on: February 16, 2011, 03:45:57 AM »
Released :)

Maybe if I am going to release maps with big codes I will make beta testing a must for me :)