In the previous chapter, we defined the logic of a pokemon battle and returned the wild pokemon details if the trainer pokemon wins.
But what if the trainer pokemon loses? In such a case we need to return some empty values.
empty is a built-in Vyper function which returns a default value of the type(typename) passed as a parameter.
It is useful for initializing new memory variables.
@external
def someFunction():
name: String[32] = empty(String[32])Here you can find a list of all types and default values:
| Type | Default Value |
|---|---|
| address | 0x0000000000000000000000000000000000000000 |
| bool | False |
| bytes32 | 0x0000000000000000000000000000000000000000000000000000000000000000 |
| decimal | 0.0 |
| int128 | 1 |
| uint256 | 1 |
We will use the empty function to return default values in case the trainer pokemon loses.
- Create an
elsestatement which returns the following values:- Battle result:
False - Wild pokemon name:
empty(String[32]) - Wild pokemon DNA:
empty(uint256) - Wild pokemon HP:
empty(uint256)
- Battle result: