You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modify.md
+21-20Lines changed: 21 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -240,7 +240,7 @@ class $modify(MyComplicatedClass, MenuLayer) {
240
240
241
241
## Adding new virtual functions
242
242
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:
244
244
245
245
```cpp
246
246
class $modify(CopyPlayerObject, PlayerObject) {
@@ -261,14 +261,27 @@ Not yet implemented
261
261
262
262
# Common mistakes
263
263
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.
265
278
266
279
## Accidental not recursion
267
280
268
281
```cpp
269
282
class $modify(MenuLayer) {
270
283
bool init() {
271
-
if (!this->init()) return false;
284
+
if (!this->init()) return false; // !!
272
285
273
286
auto label = CCLabelBMFont::create("Hello world!", "bigFont.fnt");
274
287
label->setPosition(100, 100);
@@ -279,22 +292,10 @@ class $modify(MenuLayer) {
279
292
};
280
293
```
281
294
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.
294
296
295
-
This will result in an infinite loop.
296
297
297
-
## Accidental not using the correct function
298
+
## Accidentally not using the correct function
298
299
299
300
```cpp
300
301
class $modify(MyBrokenClass, MenuLayer) {
@@ -324,11 +325,11 @@ class $modify(MyBrokenClass, MenuLayer) {
324
325
325
326
This will result in the modification getting called twice when you press the newly created button, then the original function will be called.
326
327
327
-
## Accidental not supplying the correct signature
328
+
## Not supplying the correct signature
328
329
329
330
```cpp
330
331
class $modify(MenuLayer) {
331
-
bool onMoreGames(CCObject* target) {
332
+
bool onMoreGames(CCObject* target) { // !!
332
333
FLAlertLayer::create(
333
334
"Geode",
334
335
"Hello World from my Custom Mod!",´
@@ -339,4 +340,4 @@ class $modify(MenuLayer) {
339
340
};
340
341
```
341
342
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