Skip to content

Commit b2908ae

Browse files
authored
let's promote using $on_mod(Loaded) instead of $execute by default
1 parent 597e3fd commit b2908ae

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

handbook/vol1/chap1_3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void MenuLayer_onNewgrounds(MenuLayer* self, CCObject* sender) {
3333
log::info("After original!");
3434
}
3535

36-
$execute {
36+
$on_mod(Loaded) {
3737
Mod::get()->addHook(
3838
reinterpret_cast<void*>(geode::base::get() + 0x27b480),
3939
&MenuLayer_onNewgrounds,

mods/settings.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ auto myBool = Mod::get()->getSettingValue<bool>("my-bool-setting");
6363
auto myInt = Mod::get()->getSettingValue<int64_t>("my-int-setting");
6464
```
6565

66-
You can detect whenever the value of a setting is changed by using the [listenForSettingChanges] function. In most situations, you should call this function in an `$execute` block, so it gets enabled immediately when your mod is loaded. **The function will not be called on startup**, only when the value is changed afterwards. Note that the type you get the value as must match the value type of the setting type - if you are using a custom setting, make sure to specialize `geode::SettingTypeForValueType<T>`.
66+
You can detect whenever the value of a setting is changed by using the [listenForSettingChanges] function. In most situations, you should call this function in an `$on_mod(Loaded)` block, so it gets enabled immediately when your mod is loaded. **The function will not be called on startup**, only when the value is changed afterwards. Note that the type you get the value as must match the value type of the setting type - if you are using a custom setting, make sure to specialize `geode::SettingTypeForValueType<T>`.
6767

6868
```cpp
6969
#include <Geode/loader/SettingV3.hpp>
7070

7171
using namespace geode::prelude;
7272

73-
$execute {
73+
$on_mod(Loaded) {
7474
listenForSettingChanges("my-float-setting", [](double value) {
7575
// do something with the value
7676
});
@@ -687,7 +687,7 @@ SettingNodeV3* MyCustomSettingV3::createNode(float width) {
687687
}
688688

689689
// When the mod is loaded, you need to register your setting type
690-
$execute {
690+
$on_mod(Loaded) {
691691
// You can also handle the errors, but if this fails, the game is probably about to crash anyway
692692
(void)Mod::get()->registerCustomSettingType("my-awesome-type", &MyCustomSettingV3::parse);
693693
}
@@ -890,7 +890,7 @@ SettingNodeV3* MyButtonSettingV3::createNode(float width) {
890890
}
891891

892892
// Register as before
893-
$execute {
893+
$on_mod(Loaded) {
894894
(void)Mod::get()->registerCustomSettingType("my-button-type", &MyButtonSettingV3::parse);
895895
}
896896
```

tutorials/events.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ Listening to events is done using an `EventListener`. An event listener needs an
6060
```cpp
6161
// main.cpp
6262

63-
#include <Geode/DefaultInclude.hpp> // $execute
63+
#include <Geode/DefaultInclude.hpp> // $on_mod(Loaded)
6464
#include <Geode/loader/Event.hpp> // EventListener, EventFilter
6565

6666
#include "DragDropEvent.hpp" // Our created event
6767

6868
using namespace geode::prelude;
6969

70-
// Execute runs the code inside **when your mod is loaded**
71-
$execute {
70+
// on_mod(Loaded) runs the code inside **when your mod is loaded**
71+
$on_mod(Loaded) {
7272
// This technically doesn't leak memory, since the listener should live for the entirety of the program
7373
new EventListener<EventFilter<DragDropEvent>>(+[](DragDropEvent* ev) {
7474
for (std::filesystem::path& file : ev->getFiles()) {
@@ -89,14 +89,14 @@ Notice that our callback returns a `ListenerResult`, more specifically `Listener
8989
```cpp
9090
// main.cpp
9191

92-
#include <Geode/DefaultInclude.hpp> // $execute
92+
#include <Geode/DefaultInclude.hpp> // $on_mod(Loaded)
9393
#include <Geode/loader/Event.hpp> // EventListener, EventFilter
9494

9595
#include "DragDropEvent.hpp" // Our created event
9696

9797
using namespace geode::prelude;
9898

99-
$execute {
99+
$on_mod(Loaded) {
100100
new EventListener<EventFilter<DragDropEvent>>(+[](DragDropEvent* ev) {
101101
for (std::filesystem::path& file : ev->getFiles()) {
102102
log::debug("File dropped: {}", file);

tutorials/manualhooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void MenuLayer_onNewgrounds(MenuLayer* self, CCObject* sender) {
1919
log::info("After original!");
2020
}
2121

22-
$execute {
22+
$on_mod(Loaded) {
2323
Mod::get()->hook(
2424
reinterpret_cast<void*>(geode::base::get() + 0x191E90), // address
2525
&MenuLayer_onNewgrounds, // detour
@@ -40,7 +40,7 @@ void myDrawCircle(const cocos2d::CCPoint& center, float radius, float angle, uns
4040
log::info("alright {}", radius);
4141
}
4242
43-
$execute {
43+
$on_mod(Loaded) {
4444
Mod::get()->hook(
4545
reinterpret_cast<void*>(
4646
// All of this is to get the address of ccDrawCircle

tutorials/modify-geode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ These rules are in place because the Geode UI is a highly volatile place that **
3131

3232
using namespace geode::prelude;
3333

34-
$execute {
34+
$on_mod(Loaded) {
3535
new EventListener<EventFilter<ModLogoUIEvent>>(+[](ModLogoUIEvent* event) {
3636
if (event->getModID() == "geode.loader") {
3737
// Remember: no assumptions, even trivial ones!

0 commit comments

Comments
 (0)