Skip to content

Commit e611be0

Browse files
authored
Merge pull request #4 from prokube/patch-1
Clarification in Common Mistakes
2 parents d69c536 + 593a7b9 commit e611be0

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

modify.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class $modify(MyComplicatedClass, MenuLayer) {
240240
241241
## Adding new virtual functions
242242
243-
We currently don't support this yet, but here is how you would do it anyway:
243+
We currently don't support this yet, but here is how you *would* do it anyway:
244244

245245
```cpp
246246
class $modify(CopyPlayerObject, PlayerObject) {
@@ -261,14 +261,27 @@ Not yet implemented
261261

262262
# Common mistakes
263263

264-
Here are some common mistakes you (and us) may make:
264+
Here are some common mistakes you (and we) may make:
265+
266+
## Accidental recursion
267+
268+
```cpp
269+
class $modify(MenuLayer) {
270+
void onMoreGames(CCObject* target) {
271+
Log::get() << "MenuLayer::onMoreGames called woooo";
272+
this->onMoreGames(target); // !!
273+
}
274+
};
275+
```
276+
277+
This will result in an infinite loop, because `this->` calls the $modified MenuLayer's `onMoreGames` instead of the original's. Name the class you're calling the function from instead.
265278
266279
## Accidental not recursion
267280
268281
```cpp
269282
class $modify(MenuLayer) {
270283
bool init() {
271-
if (!this->init()) return false;
284+
if (!this->init()) return false; // !!
272285
273286
auto label = CCLabelBMFont::create("Hello world!", "bigFont.fnt");
274287
label->setPosition(100, 100);
@@ -279,22 +292,10 @@ class $modify(MenuLayer) {
279292
};
280293
```
281294

282-
This will not result in an infinite loop because `MenuLayer::init` is a virtual function, but please don't use it. It will confuse us all.
283-
284-
## Accidental recursion
285-
286-
```cpp
287-
class $modify(MenuLayer) {
288-
void onMoreGames(CCObject* target) {
289-
Log::get() << "MenuLayer::onMoreGames called woooo";
290-
this->onMoreGames(target);
291-
}
292-
};
293-
```
295+
This will not result in an infinite loop because `MenuLayer::init` is a virtual function, but please don't do `this->function`. It will confuse us all.
294296

295-
This will result in an infinite loop.
296297

297-
## Accidental not using the correct function
298+
## Accidentally not using the correct function
298299

299300
```cpp
300301
class $modify(MyBrokenClass, MenuLayer) {
@@ -324,11 +325,11 @@ class $modify(MyBrokenClass, MenuLayer) {
324325

325326
This will result in the modification getting called twice when you press the newly created button, then the original function will be called.
326327

327-
## Accidental not supplying the correct signature
328+
## Not supplying the correct signature
328329

329330
```cpp
330331
class $modify(MenuLayer) {
331-
bool onMoreGames(CCObject* target) {
332+
bool onMoreGames(CCObject* target) { // !!
332333
FLAlertLayer::create(
333334
"Geode",
334335
"Hello World from my Custom Mod!",´
@@ -339,4 +340,4 @@ class $modify(MenuLayer) {
339340
};
340341
```
341342
342-
This will result in not modifying the intended function at all.
343+
This will result in not modifying the intended function at all, because `onMoreGames` is `void` in MenuLayer.

0 commit comments

Comments
 (0)