# Xs scripting: \`main\` called on saved game load and save chapter

**URL:** <https://forums.ageofempires.com/t/xs-scripting-main-called-on-saved-game-load-and-save-chapter/287609>\
**Category:** II - Report a Bug\
**Created:** [July 12, 2026, 1:36am UTC](https://forums.ageofempires.com/t/xs-scripting-main-called-on-saved-game-load-and-save-chapter/287609 "2026-07-12T01:36:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ductape1957](https://forums.ageofempires.com/user_avatar/forums.ageofempires.com/ductape1957/32/202959_2.png) [@ductape1957](https://forums.ageofempires.com/u/ductape1957)\
**Post date:** [July 12, 2026, 1:36am UTC](https://forums.ageofempires.com/t/xs-scripting-main-called-on-saved-game-load-and-save-chapter/287609/1 "2026-07-12T01:36:30Z")

</div>

### ▶ GAME INFORMATION

👇 _These details are CRITICAL; DO NOT skip them or your issue may not be reviewed._

- **GAME BUILD** #: 101.103.48987.0 (#180059) 24094652, and (1.1.2RC1) on mac
- **GAME PLATFORM:** Steam
- **OPERATING SYSTEM:** Windows 10 and Mac (same behavior)

### ▶ ISSUE EXPERIENCED

👇 _DESCRIBE THE ISSUE IN DETAIL (below). LIMIT TO ONE_ BUG PER THREAD.

The xs function `main` gets called when a saved game is loaded, or when the “save chapter” button is pressed.

There is already an old unresolved post on save chapter: [https://forums.ageofempires.com/t/save-chapter-glitch/](https://forums.ageofempires.com/t/save-chapter-glitch/). But there may be multiple separate issues. Save chapter/game load also resets xs variables, but only when the xs code is inside triggers and not as a separate xs file. But `main` gets called in both cases.

### ▶ FREQUENCY OF ISSUE

👇 _How often does the issue occur? CHOSE ONE; DELETE THE REST__!_

- **100%** of the time / matches I play (ALWAYS)

### ▶ REPRODUCTION STEPS

👇 _List CLEAR and DETAILED STEPS we can take to reproduce the issue ourselves… Be descriptiv__e!_

Here’s the steps to reproduce the issue:

1. Test the attached scenario.

2. Press “save chapter” or save and load the game.

3. Move the xs code from the trigger into a separate xs file, include it and test again.

4. Press “save chapter” or save and load the game.

### ▶ EXPECTED RESULT

👇 _What was SUPPOSED to happen if the bug you encountered were not prese__nt?_

`main`should only be called once, when the game starts.

### ▶ IMAGE

👇 _ALWAYS attach a PICTURE (.jpg, .png, .gif) or VIDEO (.mp4, YouTube link) that highlights the prob__lem._

 ![bugMain](https://forums.ageofempires.com/uploads/default/original/3X/f/2/f2a4a823317f6eb0d4bb3c91bfb956cd986dc232.png)

### ▶ GAME FILES (SAVE / RECORDING)

👇 _Attach a SAVE GAME (.aoe2spgame) or GAME RECORDING (.aoe2record) of the match where you encountered the issue. Link it below if using an external file ser__vice._

- [bugMain.aoe2scenario](https://forums.ageofempires.com/uploads/short-url/v3R4UGjGdigOHbtWsrrKFNYlm04.aoe2scenar) (1.2 KB)

---

<div class="post-metadata">

**Author:** ![Ekarlath](https://forums.ageofempires.com/user_avatar/forums.ageofempires.com/ekarlath/32/146833_2.png) [@Ekarlath](https://forums.ageofempires.com/u/Ekarlath)\
**Post date:** [October 6, 2026, 2:46pm UTC](https://forums.ageofempires.com/t/xs-scripting-main-called-on-saved-game-load-and-save-chapter/287609/2 "2026-10-06T14:46:41Z")

</div>

You can “bypass” that issue by adding an IF check in your main function, until it’s fixed, if not already.

if a dedicated variable is at 0 then execute your main and at the end of it set this variable to 1, then the next time it attempts to execute it, the variable will be at 1 and won’t be run.

---

<div class="post-metadata">

**Author:** ![ductape1957](https://forums.ageofempires.com/user_avatar/forums.ageofempires.com/ductape1957/32/202959_2.png) [@ductape1957](https://forums.ageofempires.com/u/ductape1957)\
**Post date:** [October 6, 2026, 4:21pm UTC](https://forums.ageofempires.com/t/xs-scripting-main-called-on-saved-game-load-and-save-chapter/287609/3 "2026-10-06T16:21:23Z")

</div>

Yes, this was fixed in the last update!

And yes, your approach worked, except when variables would also reset due to that other bug. But that’s fixed too.

---

<div class="post-metadata">

**Author:** ![Ekarlath](https://forums.ageofempires.com/user_avatar/forums.ageofempires.com/ekarlath/32/146833_2.png) [@Ekarlath](https://forums.ageofempires.com/u/Ekarlath)\
**Post date:** [October 6, 2026, 4:24pm UTC](https://forums.ageofempires.com/t/xs-scripting-main-called-on-saved-game-load-and-save-chapter/287609/4 "2026-10-06T16:24:52Z")

</div>

> [@ductape1957](#):
>
> except when variables would also reset due to that other bug

Then a time check could solve it too. if game current time is greater than 1sec don’t apply.

> [@ductape1957](#):
>
> Yes, this was fixed in the last update!

I was wondering if the fix they did that was not loading properly the xs files (breaking auras that are not in the main) affect it. Glad to hear it’s fixing both.
