Gateway level, project-scoped (gateway timer, tag change etc) scripts, for complicated legacy reasons, follow legacy scoping rules.
Generally speaking, the easiest, most maintainable thing to do is immediately bail out of your gateway timer script to a function defined in a real project script, and have all of your logic there. Besides modern scoping, you also get the benefit of true diffing of project changes if it’s in a project script.