Skip to content

Commit

Permalink
Update fields.md
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 authored Apr 22, 2024
1 parent 5107963 commit cfb3e94
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tutorials/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ class $modify(PlayerObject) {

This code works even if you have multiple `PlayerObject`s, and the counter is initialized as 0 for each one, providing an elegant yet simple solution to the problem.

**Fields must be accessed through the `m_fields` member**. If you access them directly through `this`, you will get **undefined behaviour** (most likely a crash).
> :warning: If you are using old fields behavior, then **fields must be accessed through the `m_fields` member**. If you access them directly through `this`, you will get **undefined behaviour** (most likely a crash).

Fields are declared just like normal member variables, even constructors and destructors work\*.

```cpp
class $modify(PlayerObject) {
struct Fields {
int m_totalJumps = 13;
Fields() : m_totalJumps(13) {
log::debug("Constructed!");
}
int m_totalJumps;
~Fields() {
log::debug("Destructed!");
}
};

void pushButton(PlayerButton button) {
Expand Down

0 comments on commit cfb3e94

Please sign in to comment.