Be sure to check at least how events work in the manual.
I strongly advise to take the time to read the manual in order too (at least the "Overview", "Interface" and "Project primitive" and "system references" categories in the first place).
It takes a bit of time (honestly not that long) and it really helps.