Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Олегарх
User Avatar
Auto-translated
Oligarch
I googled it and found this:

try
... (block) ...
end

If an error occurs in the block, the control immediately jumps to the first statement after END, and
the error will be ignored.

another form,

try
... (block) ...
catch err do
... (handler) ...
end
This is not Lua. It won't work.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
Hmm, that's strange, here's the link: http://lua-users.org/lists/lua-l/2008-01/msg00650.html
and the very first sentence:
I just wrote a TRY..CATCH extension for Lua, and adapted it into version 5.1.3

so, maybe pcall will work?
pcall (f, arg1, ···)
Calls the function f with the given arguments in protected mode. This means that if any error occurs inside the function f, it will not be passed further; instead, pcall intercepts the error and returns a status.
Мои карты:
Town
Готовится:Чума (40%), Сосиска(42%), Война Грааля
In reply to Олегарх
User Avatar
Auto-translated
Oligarch
Hmm, that's strange, here's the link: http://lua-users.org/lists/lua-l/2008-01/msg00650.html
and the very first sentence:
I just wrote a TRY..CATCH extension for Lua, and adapted it into version 5.1.3

so, maybe pcall will work?
pcall (f, arg1, ···)
Calls the function f with the given parameters in protected mode. This means that if any error occurs inside the function f, it will not be passed further; instead, pcall intercepts the error and returns a status.
Yes, he wrote it. But this is an extension for the language, not a built-in construct, and it's not for implementation in the game.
The game uses version 4.0 of Lua, not 5.1.
The developers have removed almost all built-in functions.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
startThread doesn't work?
No. It creates too many simultaneous threads. Besides, this workaround is needed for every standard function. And even in the simplest situation, you have to write a lot of conditions before the development functions so that they don't crash.

Surely there aren't even any exception handling mechanisms. Do I have to write them myself?
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
Auto-translated
Dyrman
No. It results in many simultaneous threads. Besides, this workaround is needed for every standard function. And even in the simplest situation, you have to write many conditions before the development functions so that they don't crash.

Surely there aren't even any exception handlers.
Do I have to write them myself?
Threads start and end...
Should all functions work without errors, regardless of what is passed to them as parameters?
What should these exception handlers do?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
Streams have a beginning and an end...
Is it necessary for all functions to work flawlessly, regardless of the parameters passed to them?
What should these exception handlers do?
For a test database, there should be infinite streams. Combining them into a single stream leads to script delays and the inability to perform its functions, plus a high probability of the script crashing. Splitting it into many streams leads to delays in the game itself.
For now, there is a way to use a mixed system: some parts sequentially, some in parallel, but as the system approaches infinity, the delay will increase. The most optimal solution would be to skip those functions that cause failures. Strangely enough, even a failing function can be beneficial.
In a single-player game, this is not so critical, but in a multiplayer game (not hotseat), it's a complete disaster!

There is a possibility of creating a stack-based replacement system, where one function is incompletely processed and replaced by another, in order to save resources. But such a system is poor for testing.

Added 5 minutes later
I will have to choose a simple, optimal system in which errors (stack-based) have already been eliminated, but also create a second environment for testing (parallelized).
I will test it and see.

Added 8 minutes later
The maximum number of active heroes on one map is 127. This is actually the limit of "infinity". But 127 simultaneous infinite streams is a lot!
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
Auto-translated
However, there don't seem to be any other ways to work around the error besides using startThread.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
But there don't seem to be any other ways to bypass the error besides using startThread.
That's bad. :(
By the way, I'll rework your Hafad: I'll make it so that his ability also affects heroes, even if they are in the town.
You can, of course, do it yourself. You'll just need one function without triggers and forced adjacency.
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
Auto-translated
Dyrman
Bad :(
By the way, I'll modify your Hafad: I'll make his ability work on heroes too, even if they are in the town.
You can, of course, do it yourself) You'll only need one function without triggers and forced interactions.
Maybe errorHook will work?
void errorHook( fCallback )

Allows you to set an error handler. By default, when a script error occurs, the current thread terminates. Thanks to this function, you have the opportunity to adjust this behavior – before stopping, control will be passed to the fCallback function.
Found it at Novik's. If this doesn't help, then there are no more options.
Мои карты:
Town
Готовится:Чума (40%), Сосиска(42%), Война Грааля
User Avatar
Auto-translated
RedHeavenHero
Won't it be too powerful for the heroes? After all, the plague kills a fairly large percentage of the total number.
It will kill fewer ;)

Added after 59 seconds
Oligarch
Maybe errorHook would be suitable?
void errorHook( fCallback )

Allows you to set an error interceptor. By default, when a script error occurs, the current thread terminates. Thanks to this function, you have the opportunity to adjust this behavior – before stopping, control will be passed to the fCallback function.
Found it at Novik's. If this doesn't help, then there are no more options.
This is not it.
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
User Avatar
Auto-translated
< HeroesPool >
< Count >1< /Count >
< Heroes >
< Item >
< HeroScriptName >RedHeavenHero01< /HeroScriptName >
< TargetCampaign/ >
< TargetMission >1< /TargetMission >
< /Item >
< /Heroes >
< /HeroesPool >

In the first mission and in the second, only the number near target mission changes. I think I copied it from the developers' file, with some small changes. However, recently, the hero has stopped transitioning to the next mission. I can't figure out what same is wrong...

Whatever
User Avatar
Auto-translated
Okay, so how about the function `

AllowPlayerTavernRace ?

I need it so that in cities under player control, Necromancers, Mages, Orcs, and Elves never appear. It seems like this function should work, but when I try to write a script for it, it throws an error saying "nil" in the third parameter, even though I have no idea why, because the manual says it should be true/nil....

Whatever
User Avatar
Auto-translated
aaa. (However, the manual clearly states nil). Thank you.

Whatever
In reply to Heroist
User Avatar
Auto-translated
Heroist
< HeroesPool >
< Count >1< /Count >
< Heroes >
< Item >
< HeroScriptName >RedHeavenHero01< /HeroScriptName >
< TargetCampaign/ >
< TargetMission >1< /TargetMission >
< /Item >
< /Heroes >
< /HeroesPool >

In the first and second missions, only the number near "target mission" changes. I copied it, and it seems to be from the developers' file, with minor changes. However, recently, the hero has stopped transferring to the next mission. I can't understand what's wrong...
As I understand it, this snippet saves the heroes whose names are listed in the pool, preserving their stats as they were at the end of the mission. Maybe you used @Win() and the hero remained at level one, which is why he didn't transfer to the next mission with anything.
TargetMission should be equal to the current mission.
You can try writing the campaign file name in TargetCampaign.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4

Statistics

Welcome our newest member: Emil