[Question] Game Development 2 (JavaScript)

I am a few levels into Game Development 2 and I’m not sure I understand what `var unit = event.target; really does.

So can someone go into more depth and explain it to me? From my understand you are making the variable unit which could mean any unit? Then you add an event to it that can mean any type of event? Like attack? shield? cleave? then you give it a target? so enemy, “munchkin”, “thrower”, etc? And where does event and target come from? Are they predefined by the creators of CodeCombat? or are they just I can’t think of the name for it, but they are already used in the JavaScript language and do something by default so you can’t define them yourself. Sorry if the explanation is bad, I’m confused xD

My understanding that it is an event that happens with the map because the units pretty much are part of the map in the way you look at it. So an event could either be the unit or the map itself. I think the event is something like you thought it was. The event target could be the creators but I doubt it they usually have a randomizing thing so it could be the position or just what you have the unit do I’m not at the level yet but I have done some codes like that.

var unit = event.target

I think just means the selected unit (var unit) targets the closest enemy and attackes it or does whatever the creator code says it does.

You’ll probably understand it more as you go along I’ll try to get to the level ASAP to go check it out and learn what it means.