Zoo Keeper Help(Soldiers not moving)


#1

In my code for Zoo Keeper I have this:
It doesn’t return any errors, but for some reason my soldiers do not go to the points. Any advice? Thanks!
Edit:Posted edits to code, still not working. The soldiers run off to the right, instead of going to the points.
2nd edit: Posted code edits, still not working. The soldiers stand together, not doing anything, until enemies appear, even out of their range.
Any ideas?
Edit 3 Posted code edits; now it doesn’t even run, saying infinite loop. What am I doing wrong?
Edit 4: Posted code edits: now they just move to the positions, and then stay there, facing upward and walking.
Edit 5: It works! Thanks to everyone that helped me. I will post my code, but please, learn from it and write your own, instead of copying it.
Edit 6: Last one. I promise. I found out that I’m not allowed to post correct code. So, bye-bye it goes. If you want, though, you can PM me for help.


#2

Your problem is here:

var enemy=soldier.this.findNearest(enemies);

this should not be there. Remove it and your program should work.


#3

I edited it, implementing the change you suggested, among others. Any more advice?
Thanks! :grinning:


#4

this.command(this.findFriends()[i], "move", point.pos); will basically command all soldiers to go to point.pos if there are no enemies. Command soldier to defend their specific point.


#5

I have edited, but to no avail.
I have no idea why it isn’t working


#6

Try removing the defend command. it is pointless. Your soldiers are already looking for enemies to attack. Just move them back into position after they attack the enemy. If that doesn’t work, I’m not sure what’s wrong. Your code is almost identical to mine.


#7
var points = [{x: 33, y: 42},{x: 47, y: 42},{x: 33, y: 26},{x: 47, y: 26}];

^ these are positions.

var point = points[i];
this.command(friend, "move", point.pos);

where

point.pos

is the same as:

points[i]["pos"];

which means…

you’re asking for an array looking like this:

var points = [ {pos: {x: 33, y: 42} } , {pos: {x: 47, y: 42} } , {pos: {x: 33, y: 26} } , {pos: {x: 47, y: 26} } ];

hope that explains your problem.

Edit: just saw your edit, and oh god, that’s a close to infinite while loop you made.


#8

Ha, yeah. I’ll post my new code, still doesn’t work though. Thanks for the help!


#9

still has your pos error.


#10

I changed it to the array you suggested, is that not right?


#11

Would this help?

else if(point.pos!==soldier.pos){
          
        this.command(friend, "move", point.pos);
      
      }

#12

Well, you fixed it in reverse, but I guess it’d work to XD

I’m also preeeeetty sure “enemies” doesn’t need to check for being an ‘enemy team member’ as it’s an ‘enemy’. :stuck_out_tongue:


#13

Fixed it!
Should I post my full code?


#14

sure, I’ll rearange it to show you appearent errors. also, try giving it the appropriate spaced and ‘Tab’ usage.


#15

Yeah, I’ll put it through JSBeautifier