

ÆTERNITY ACADEMY
LEVEL 3
Congratulations Fury! You have created a record for the state variables! Let's move on to our SuperHero structure creation. We will also learn to initialise the state variables now.
​
​
Step 1
Similar to the state variables, we will create structures that record the details of the avenger.
Example syntax(to create a cryptohamster):
record hamster = {
name: string,
hamster_id: int }
​
Now, you would need to create a record named "Avenger" and create two variables called "name" and "power" of type String and Integer.
​
Step 2
​
Wohoo! We have now moved to the next important step in creating a contract - initialising the state variables.
Why initialise?
The state variables are mutable and initialising them would set the initial state of the contract.At contract creation time, the init function is executed and its result is stored as the contract state.
​
To define a function in Sophia, we can use the keyword either "function" or "entrypoint". The keyword entrypoint exposes the function to the outside world whereas the other keyword is used to define functions that can be called only internally.
There is an entrypoint called - inti(), that we need to define to initialise the starting values of our state variables. Remember the state variables you created in the previous tutorial? Yes, we will be initialising their values.
Here is an example of the init function:
stateful entrypoint init() =
{ index = 1,
map_hamsters = {},
testvalue = 42}
​
Now, you need to write both the record and the init function on the editor.
Referece: https://github.com/aeternity/aesophia/blob/lima/docs/sophia.md
