Quinn
05/15/2019, 1:38 PMvar sources = spawn.room.find(FIND_SOURCES).sort { a,b ->
(a.pos.x - b.pos.x) * (a.pos.x - b.pos.x)
+ (a.pos.y - b.pos.y) * (a.pos.y - b.pos.y)}
val creepsWithSource1 = creeps.count { it.memory.assignedSource == sources[0].id }
val creepsWithSource2 = creeps.count { it.memory.assignedSource == sources[1].id }
val assignedSource = if(creepsWithSource1 < creepsWithSource2) sources[0].id else sources[1].id
This results in the following error message. I'm trying to decipher what this error means so I can understand it in the future.
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun <K, V> Record<Int, [ERROR : No type element]?>.get(key: Int): [ERROR : No type element]? defined in starter
dalexander
05/15/2019, 1:43 PMsort
doesn't return the sorted array, but rather sorts it in place. So by calling sort like that you are changing the type of sources
. (I ran into a similar problem recently myself)Quinn
05/15/2019, 1:50 PMsources
. Do you happen to know what fun <K, V>
is? Is that two types, one of which is Record<Int, [Error]>
and the other is .get(key: Int)
? I see that the error message mentions that the Record function is returning no type elements. Still very confused by this error messages.dalexander
05/15/2019, 1:52 PMsources[0]
ie. you're trying to get the first element in the sources object. And because sort doesn't return a list it's complaining.Quinn
05/15/2019, 1:53 PMdalexander
05/15/2019, 1:58 PMval sources = spawn.room.find(FIND_SOURCES)
sources.sort { a,b -> (a.pos.x - b.pos.x) * (a.pos.x - b.pos.x) + (a.pos.y - b.pos.y) * (a.pos.y - b.pos.y) }
And no problem, glad I could help 🙂Quinn
05/15/2019, 2:24 PMdalexander
05/15/2019, 2:29 PMctrl + shift + p
on OS X. I think it's similar on Windows. You can also open the "do an action" window with ctrl + shift + a
and type in expression type (or any other action, really).Quinn
05/15/2019, 2:36 PMQuinn
05/15/2019, 2:36 PMdalexander
05/15/2019, 2:37 PMdalexander
05/15/2019, 2:39 PMtypes from their API that are converted from javascript to Kotlin
I could see this being a problem based on working with loosely typed JS API's in the past.dalexander
05/15/2019, 2:40 PMQuinn
05/15/2019, 2:42 PM