Table of Contents

Lua language reference

The H5 scripting language uses and reads lua syntax and basic functions, therefore you may want to try the lua reference manual in search of more sophisticated or more capable functions, arrays and conditional statements.

if - then - else statements

if condition checks whether the following formula is true or false. For example

if ObjectExists (Aberrar)

returns “true” if the hero is on the map and false if he is not present.

then determines what happens if the condition is true. For example:

if ObjectExists (“Aberrar”) then
ChangeHeroStat (“Aberrar”, STAT_DEFENCE,1);
end;

If Zoltan (codename Aberrar) is present on the map, he will be given +2 defense.

Each of the statement blocks must be finished with end; so the compiler know where it should stop the execution of conditional statement.

else determines what happens if condition returns false. Now our function looks like this:

if ObjectExists (Aberrar) then
ChangeHeroStat (“Aberrar”, STAT_DEFENCE,1);
else
DeployReserveHero (“Aberrar”, 20,30,0);
end;

If Zoltan is not present, he will spawn in the certain point of the map.

elseif means exactly what single if, but does not need to be followed by end; which clarifies the code. For example:

function storyline ()
if storyprogress == 1 then
[commands]
elseif storyprogress == 2 then
[commands]
elseif storyprogress == 3 then
[commands]
else
print (“storyline script failure”);
end;

edn;

It allows us to create an entire linear scenario with a single function.

Manual

The Basics of Heroes V Scripting 2.01 by Robert De Ford