Current time: 10.04.2025, 07:15 Hello There, Guest! (LoginRegister)
Language: english | russian  

Post Reply 
Threaded Mode | Linear Mode
Школа ERM 2
» ERM 2.0 для ERA III
Author Message
Archer30 Offline
Moderators

Posts: 1190
Post: #151

Hi! I have a question about arrays in ERM 2.
Is it possible to make a variable in a variable with array?
  1. !?FU(OnEveryDay);
  2. !#VA(firstLevelMon[9]:y);
  3. !!VR(value:y):S1;
  4. !!VR(firstLevelMon):C(MON_PIKEMAN)/(MON_DWARF)/(MON_GREMLIN)/(MON_IMP)/(MON_SKELETON)/(MON_TROGLODYTE)/(MON_GOBLIN)/(MON_GNOLL)/(MON_PIXIE);
  5. !!IF:M^%(firstLevelMon[%(value)])^;

Looks like %(firstLevelMon[%(value)]) is wrong 102


Latest ERA mods and scripts in development - My GitHub
(This post was last modified: 10.03.2021 10:51 by Archer30.)
10.03.2021 10:26
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16733
Post: #152

Archer30, nope, ERM is too low level. We have to define pointer to array item and access it indirectly.

In Lua it would be firstLevelMons[value], but in ERM 2:
  1. !?FU(OnEveryDay);
  2. !#VA(firstLevelMons[9]:y);
  3. !!VR(firstLevelMonPtr:y):S(@firstLevelMons) +1; Ptr = pointer = y-index of array first item (like 50 for y50) + logical offset/index
  4. !!VR(firstLevelMons):C(MON_PIKEMAN)/(MON_DWARF)/(MON_GREMLIN)/(MON_IMP)/(MON_SKELETON)/(MON_TROGLODYTE)/(MON_GOBLIN)/(MON_GNOLL)/(MON_PIXIE);
  5. !!VR(mon:y):Sy(firstLevelMonPtr); get the value using yy3-like syntax if y3 holds 51, it's the same as y51
  6. !!IF:M^%(mon)^;


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
10.03.2021 14:00
Find all posts by this user Quote this message in a reply
Archer30 Offline
Moderators

Posts: 1190
Post: #153

Hmmm, in this particular case, the name variable is worse than v-variable. I can simplify the code by:

  1. !?FU(OnEveryDay);
  2. !#VA(firstLevelMon[9]:y);
  3. !!VR(value:y):S3;
  4. !!VRv2:C(MON_PIKEMAN)/(MON_DWARF)/(MON_GREMLIN)/(MON_IMP)/(MON_SKELETON)/(MON_TROGLODYTE)/(MON_GOBLIN)/(MON_GNOLL)/(MON_PIXIE);
  5. !!IF:M^%v(value)^;


Latest ERA mods and scripts in development - My GitHub
10.03.2021 14:40
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16733
Post: #154

It's awful code. Do not use global variables for almost the same purpose but with invalid logics. You th code I gave above, press F11 and see, what it's compiled too.
Even better try this code for testing:
  1. !?FU(OnEveryDay);
  2. !#VA(dummy[66]:y);
  3. !#VA(firstLevelMons[9]:y);
  4. !!VR(firstLevelMonPtr:y):S(@firstLevelMons) +1; Ptr = pointer = y-index of array first item (like 50 for y50) + logical offset/index
  5. !!VR(firstLevelMons):C(MON_PIKEMAN)/(MON_DWARF)/(MON_GREMLIN)/(MON_IMP)/(MON_SKELETON)/(MON_TROGLODYTE)/(MON_GOBLIN)/(MON_GNOLL)/(MON_PIXIE);
  6. !!VR(mon:y):Sy(firstLevelMonPtr); get the value using yy3-like syntax if y3 holds 51, it's the same as y51
  7. !!IF:M^%(mon)^;

You'll see something like
  1. !!VRy80:S66 +1; y80 points to y67 - second array item
  2. !!VRy81:Syy80; y80 now holds value from y67
  3. !!IF:M^%y81^;


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
10.03.2021 17:06
Find all posts by this user Quote this message in a reply
Archer30 Offline
Moderators

Posts: 1190
Post: #155

Berserker, I understand you are not a fan of mixing variable type. I myself never want to mess up with that, but it's sometimes necessary to use v. Check this:

  1. !?FU(WOG_EndOfTurn); [requires WoG Scripts to work, check every hero on turn end]
  2. !!OW:H-1/2/0;
  3. !!re i/1/v2;
  4. !!VR(heroIndex:y):Si +2;
  5. !!OW:H-1/(heroIndex)/i;
  6. !!FU(HeroMustHaveArmy):Pv(heroIndex);
  7. !!en;

The command uses v index. What should I do to get rid of v-variable in this case? 102


Latest ERA mods and scripts in development - My GitHub
(This post was last modified: 10.03.2021 20:58 by Archer30.)
10.03.2021 17:50
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16733
Post: #156

Array access code via pointers does not need v-vars at all. The code above can be converted to safe:
  1. !!OW:C?(player:y);
  2. !!re i/(HERO_FIRST)/(HERO_LAST_WOG);
  3. !!HEi:O?(heroOwner:y);
  4. !!FU(HeroMustHaveArmy)&(heroOwner)=(player):Pi;
  5. !!en;


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
10.03.2021 19:15
Find all posts by this user Quote this message in a reply
Archer30 Offline
Moderators

Posts: 1190
Post: #157

Hmmm, maybe I was wrong about coding. I thought your code would require much more calculation (as you loop through all heroes) and may extend the time of passing the day a little bit.


Latest ERA mods and scripts in development - My GitHub
10.03.2021 20:06
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16733
Post: #158

Try it, it won't. 255 iterations, 2 commands and one condition evaluation. ERM speed is about 400 000 lightweight receivers/sec.


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
10.03.2021 21:12
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16733
Post: #159

In response to igrik and Archer30 array indexing request, ERA Team presents v3.3.7:
  1. !#VA(firstLevelMons[9]:y);
  2. !!VR(firstLevelMons):C(MON_PIKEMAN)/(MON_DWARF)/(MON_GREMLIN)/(MON_IMP)/(MON_SKELETON)/(MON_TROGLODYTE)/(MON_GOBLIN)/(MON_GNOLL)/(MON_PIXIE);
  3. !!re i/0/(firstLevelMons[SIZE])/1/-1;
  4. !!IF:M^%(firstLevelMons[i])^;
  5. !!en;


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
11.03.2021 18:03
Find all posts by this user Quote this message in a reply
daemon_n Offline
Administrators

Posts: 4356
Post: #160

Berserker, что за -1? прочитал в теме обновления.
Божечки, скоро ERM превратится в c++96-copy

P.S: вместо гномов кентаврыYes


Image: widget.png?style=banner2

Новейший Heroes Launcher
11.03.2021 20:39
Visit this user's website Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16733
Post: #161

daemon_n, 5-й параметр был введён сто лет назад. Конечное значение счётчика всегда ограниченно суммой пятого и третьего параметра.
Большинство цикло идут от 0 до КОЛВО_ЧЕГО-ТО - 1. Иногда нужно пропустить последний элемент вообще. Тогда будет -2.


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
11.03.2021 21:47
Find all posts by this user Quote this message in a reply
igrik Offline

Posts: 2819
Post: #162

(11.03.2021 18:03)Berserker Wrote:  
  1. !!re i/0/(firstLevelMons[SIZE])/1/-1;
  2. !!IF:M^%(firstLevelMons[i])^;
  3. !!en;
119 Аллилуйя!


game bug fixes extended.dll || My Plugins || My GitHub
11.03.2021 21:52
Visit this user's website Find all posts by this user Quote this message in a reply
Bes Offline

Posts: 5459
Post: #163

igrik, ты теперь часть ERA Team, как я понимаю, а потому все твои взывания к неким нужностям будут так или иначе воплощаться в ERA3 Spiteful Пора засчехлять мешок с отложенными хотелками Spiteful
11.03.2021 22:33
Visit this user's website Find all posts by this user Quote this message in a reply
igrik Offline

Posts: 2819
Post: #164

Bes, не поверишь, но хотелок у меня больше нет.
Раньше были 3: расширенное UN:C, получение структуры героя и стека. Теперь они есть.

В ERM2 сложно работать с массивами в циклах. Решение тут крайне необходимо. Надеюсь оно в скором времени появится в реальности.
Итого - мой мешок с хотелками пуст ))

Вот WoG Scripts 2 допилю (через год, два) и вообще на пенсию уйду.
11.03.2021 23:31
Visit this user's website Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16733
Post: #165

igrik Wrote:Надеюсь оно в скором времени появится в реальности.
Так уже же: https://mods.hmm35.ru/Era%20Update.exe


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
12.03.2021 01:14
Find all posts by this user Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Forum Jump:

Powered by MyBB Copyright © 2002-2025 MyBB Group