Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the Game arrays #11

Closed
Strategic-Link-Consulting opened this issue Mar 23, 2016 · 5 comments
Closed

Problem with the Game arrays #11

Strategic-Link-Consulting opened this issue Mar 23, 2016 · 5 comments

Comments

@Strategic-Link-Consulting

Thanks for creating and keeping this updated.

I noticed issues compiling and I think I see the problem but I'm pretty new at this.
It's the declarations for Game.rooms/flags/creeps etc. Instead of just an array, shouldn't they be like this?

  creeps: {[creepName: string]: Creep};
  rooms: {[roomName: string]: Room};
  spawns: {[spawnName: string]: Spawn};
  structures: {[structureId: string]: Structure};
@MarkoSulamagi
Copy link
Collaborator

What kind of compile time error you're getting and what line calls it out?
The array solution works fine for me. Both for IDE checking and while compiling.

@Strategic-Link-Consulting
Copy link
Author

error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'

applyBehavior(name: string, role: CreepRole) {
  var p0 = performance.now();
  var creep = Game.creeps[name];
  var roleCreeps = Memory.minions[creep.memory.role];
  this.minions[role].applyBehavior(name);
  if (roleCreeps != null) roleCreeps.creeps.splice(roleCreeps.creeps.indexOf(name));
  Memory.minions[role].creeps.push(name);
}

@MarkoSulamagi
Copy link
Collaborator

I was testing around a bit and I think you're right. If we only have array, then it should work in most cases, but your solution is better. I'll change the API.

Thanks for your help.

Although, I think you have a bug in your code. With using creeps.indexOf(). If I understand correctly then creeps is an object and not an array. So you can't use splice or indexOf() with it.

@MarkoSulamagi
Copy link
Collaborator

Updated the API. Run npm install to get the updates.

@Strategic-Link-Consulting
Copy link
Author

Thanks, I'm just learning Typescript. Chose to learn it by applying it to Screeps.
RR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants