fatsawhorse, ERM 1 — это ассемблер. Мне лично тяжело читать и пытаться понять логику, за минуту тут не ответишь. Как не понять и что должны делать команды:
!!FU&y2<>0:E; выход если не щелчок на фоне???
!!VRy9|y4=149/y5=149/y6=149/y7=149/y8=149:S9;
Здесь используется переменная y9, которой ранее не задали значения по умолчанию, например 0.
!!CM&y9=9/y3=12:R0;
!!CM&y9=9/y3=13:R1;
Условия нужно проверять в начале триггера, а не размазывать по коду.
Если щелчок не там-то и там или не левой кнопкой мыши или с доп. кнопками клавиатуры, то выход.
Archer30,
Quick Vars (f..t): f g h i j k l m n o p q r s t
F^FindNextObject^ is not necessary anymore, I already fixed UN:U
Code:
[+] Improved UN:U command. It does not raise error if no more objects are found, but sets x-coordinate to -1 instead. Thus no premature
objects counting is required. A new syntax with 6 parameters was added to allow using arbitrary integer variables instead of v-variables.
!!UN:U(objectType)/(objectSubtype)/(direction like -1/-2 or object index)/(x)/(y)/(z).
Example:
; Let's traverse through all map monsters, doubling their quantity
!#VA(x:y) (y:y) (z:y); define variables to store object coordinates
!!VR(x):S-1; setting x-coordinate to -1 will force to start search from scratch
!!re i; endless loop
!!UN:U(OBJ_MONSTER)/(ANY_OBJ)/-1/(x)/(y)/(z); find next monster, (x) = -1 on failure
!!br&(x)<0:; exit loop if nothing found
!!MO(x)/(y)/(z):Gd*2; double monsters quantity
!!en:;
Suggestions:
-) Name functions using verbs/actions:
"EnsureTownsHaveArmy"
"EnsureNonEmptyTownGarrisons"
"EnsureTownsHaveGuards"
"AddTroopsToEmptyTowns"
-) Prefix your new functions with unique mod/script prefix to protect from same function name usage in different scripts/mods.
!?FU(arch_EnsureTownsHaveGuards)
-) Separate function arguments and any block-controls (if/el/en/re) with empty lines from the rest fo the code to improve readability.
-) Prefer to use local named variables to quick vars, unless it's single level loop with "i"-var. "g" does not tell anything.
(slotInd:y) is better then "g".
-) Try to use br/co as rare as possible and not to jump to outer level. The logics becomes less clear.
-) Use quick vars as rare as possible. Prefer local named variables. (townType:y) is better than "t".
-) Don't comment obvious things like "[define variables to store object coordinates]".
Better leave comment before complex loops or serious of actions, describing what is intended to be done.
-) Declare local arrays before usage on a separate line. Initialize static arrays outside of loops to not repeat the same heavy task in each iteration.
-) Give plural name to arrays. "firstLevelMons" instead of "firstLevelMon".
Educational version:
Final version: