---
# System prepended metadata

title: Tipps & Tricks
tags: [TimoliaCreative, Doucmentation, TranClate]

---

# Tipps & Tricks 

###### tags: `TimoliaCreative` `TranClate` `Doucmentation`

## Kotlin features

### with-operator

The with operator can set a certain context.

Sample:
```kotlin
fun mainFunction() {
    addon {
        entity {
            name("mouse")
            behaviour {
                getMyMouseBeh(beh = this)
            }        
        }
    }
}

fun getMyMouseBeh(beh: AddonEntityBeh) {
    with(beh) {
        components {
            physics { }
        }
        componentGroups {
            componentGroup("sample") {
                
            }
        }
    }
}
```

In this case we can just call `components { }` as if we are still in the main body and don't have to call `beh.components{ }`.

### Context Receivers

A context receivers is still a pre-experimantal feature, see the jetbrains introduction video for mor information: [https://www.youtube.com/watch?v=GISPalIVdQY](https://www.youtube.com/watch?v=GISPalIVdQY).

### Iterating/Using Data

It might be useful to use maps, lists or other froms of storing data like coordinates. Here are some methods to iterate more elegant through these data structures.

```kotlin
val test = mapOf(
    1 to "1",
    2 to "2"
)
for ((key, value) in test) {    //this needs a iterator fun like maps or lists
    //do stuff
    if(key.toString() == value) {
        println("yay")
    }
}
```

this method is called destructering and can also be used outside of loobs:

```kotlin
val test = 1 to "1"    //this is a fancy way to declare a Pair

val (first, second) = test
//do stuff
if(first.toString() == second) {
    println("yay")
}
```

Note: It's generally considered bad practice to use destructering in lists but you may have a case for using it:

```kotlin
val test = listOf(1,2,3)

val(x,y,z) = test
//do stuff
val sum = x + y + z
```