I'm making a bot using coco

For AI and campaign script related discussions and questions
Post Reply
camellia0x++
Rookie
Rookie
Posts: 28
Joined: 22 Jan 2012, 18:28

I'm making a bot using coco

Post by camellia0x++ »

I've decided to make a bot using the coco language.

http://pastebin.com/difZ6mJz

The bot doesn't work yet (and very little code). But I thought it would be good to show what code in coco looks like as compared to javascript.

This is what it looks like in javascript:

http://pastebin.com/qb3MSvNg
User avatar
Andrie
Regular
Regular
Posts: 533
Joined: 20 Jun 2012, 14:11
Location: Suid Afrika

Re: I'm making a bot using coco

Post by Andrie »

when will it be done :?:
"My IRC en multiplay naam is Andrie"

Groete Andrie
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: I'm making a bot using coco

Post by Duha »

camellia0x++ wrote:I've decided to make a bot using the coco language.

http://pastebin.com/difZ6mJz

The bot doesn't work yet (and very little code). But I thought it would be good to show what code in coco looks like as compared to javascript.

This is what it looks like in javascript:

http://pastebin.com/qb3MSvNg
I have no expirience in bot writing, but I know somthing about js and programming and have some note about you code:


you can use version control system for you code. Store it on github.com or bitbucket.com and you can easy share you code.

You should use code named convention recommended for javascript total_cost_enemy totalCostEnemy

Code: Select all

  for (_i = 0, _len = (_ref = enumDroid(me, DROID_CONSTRUCT)).length; _i < _len; ++_i) {
It is too complicated. Something like that should work:

Code: Select all

var ref = enum(....);
for index in ref:
   var obj = ref[index]

Code: Select all

if (v_group) {
    for (_i = 0, _len = v_group.length; _i < _len; ++_i) 
You don`t need if. Iteratation over empty array will cose 0 loops.

Code: Select all

function __of(x, arr){
  var i = 0, l = arr.length >>> 0;
  while (i < l) if (x === arr[i++]) return true;
  return false;
}
http://www.w3schools.com/jsref/jsref_indexof_array.asp ???

Code: Select all

  return _ref = visibleObjects[_key = object.id], delete visibleObjects[_key], _ref;
It is strange.

PS. Spend some time for javascript. It will help a lot. http://www.codecademy.com/en/tracks/javascript
http://addons.wz2100.net/ developer
Post Reply