Skip to content

Posts from Scripts are not working.

No ratings yet — be the first to rate!
User Avatar
#1
Auto-translated
I don't know if you've encountered this problem, but in general: I copied some scripts from other forums and single-player missions and pasted them into the editor, but nothing happened when testing (For example: creature animations, disabling AI (so that the enemy hero doesn't move)

Here are the scripts from the map:
---THE LORD OF THE RINGS: THE FELLOWSHIP OF THE RING (1 - The Way to Bree)---
EnableHeroAI("Necros", nil)

function new_day()
local day = GetDate(DAY)
if day == 1 then
DeployReserveHero("Necros", x, y, 0)
end
end

Trigger(NEW_DAY_TRIGGER, 'new_day')



Trigger(REGION_ENTER_AND_STOP_TRIGGER, "Idle", "hire1")
----------------------HOBBITS--------------------------
PlayObjectAnimation("Hobbit1_work","attack00",IDLE)
PlayObjectAnimation("Hobbit2_work","attack00",IDLE)
----------------------RESOURCES--------------------------
SetPlayerStartResources(1,0,0,0,0,0,0,0) ;
User Avatar
#2
Auto-translated
The `new_day` function clearly contains errors:
1. It will not be called for the first day of the game.
2. The parameters of the `DeployReserveHero` function are incorrectly specified, meaning that empty, meaningless variables x and y are passed to it, which is an error. Either replace them with numbers or assign them some values.

Also, the internal name of the hero "Necros" needs to be checked, as it is not a standard one.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
#3
Auto-translated
No, you misunderstood. My scripts don't work at all, no matter what I fix.
User Avatar
#4
Auto-translated
Aleha, the script code is executed sequentially; any error will cause the interpreter to terminate, and all subsequent code will not be executed, even if it is correct. For example, if there is no hero named "Necros" on the map, the script will fail on the first line, EnableHeroAI("Necros", nil), and will not proceed further. Common errors include using a period instead of a comma, or vice versa, and missing closing "end" statements, and so on. Enable the console; it will show you which command caused the error.
In reply to Jack_of_shadows
User Avatar
#5
Auto-translated
How should I fix these issues then? (Sorry if that sounds silly).
Делаю кампанию "Последний Феникс"
User Avatar
#6
Auto-translated
Alex, there are several approaches you can take:
Write scripts in editors with syntax checking, such as the HoMM5 MapScriptsEditor. At the very least, it will immediately issue warnings for minor typos, plus it offers autocompletion of function names and parameter hints (although this feature works somewhat glitchily).
Comment out the entire script code, then uncomment it in small chunks, a few lines at a time, and check if it works, or fix it until it does, and only then move on to the next chunk. You can mark the parts that are already working in some way so that you don't have to check them again next time.
Place test debug messages in the code, such as print('this function has been executed'). This makes it easy to see which section of code has been executed and which has not.
A particularly useful trick is to debug the code without leaving the game. Create a .lua file in Unicode encoding in the "path_to_heroes/data" folder, write the code you are unsure about in it, and you can add something like print('script OK') at the end of the file. Load the map, open the console, and type doFile('filename.lua'). If you see the green message 'script OK' in the console, the code is working; if not, close the game, work on the file, don't forget to save, go back to the game, and enter the same command in the console (you can just press the up arrow button). Repeat until the code works.
User Avatar
#7
Auto-translated
HoMM5 MapScriptsEditor? Where is it located?
Делаю кампанию "Последний Феникс"
User Avatar
#8
Auto-translated
This is a third-party program; enter the name in the search bar and download it from the first or second link.
User Avatar
#9
Auto-translated
doFile('Proverka.lua') reports that it does not recognize the command.
Делаю кампанию "Последний Феникс"
User Avatar
#10
Auto-translated
Jack_of_shadows
in Unicode encoding
ANSI, I think.

Added 5 minutes later
Aleha
doFile('Proverka.lua') wrote, says he doesn't know that command
Script commands need to be preceded by @ if you're writing them in the console.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
#11
Auto-translated
RedHeavenHero
ANSI, right?

Added 5 minutes later

You need to put an @ before script commands if you're typing them in the console.

1) No, it's Unicode.
2) Got it.

Added 17 minutes later
The script (animation) worked! It worked!!! And EnableAiHero works too! But resources don't.
Делаю кампанию "Последний Феникс"
User Avatar
#12
Auto-translated
I'm sure this function worked for me:
SetPlayerStartResource(PLAYER_1, GOLD, 1000);
In reply to Jack_of_shadows
User Avatar
#13
Auto-translated
I already understand what the mistake is; the script specifies player 1, but I'm using player 3. Hey, I have a question: how can I make the "Nazgûl" patrol an area and, as soon as they detect "Frodo," immediately attack him?
Делаю кампанию "Последний Феникс"
User Avatar
#14
Auto-translated
Unfortunately, Unicode doesn't work.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#15
Auto-translated
Unicode still doesn't work.
The easiest way is to take any Lua file from any map and modify it to suit your needs. I always do it this way.

Statistics

Welcome our newest member: dodoD0D0