Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
12 years ago
Auto-translated
I discovered a rather minor, but strange quirk regarding loops iterating over array elements. I usually try to use the standard Lua tool for this, like this: for i, element in table do. So, as an example, I sketched out a code that prints all elements of a table in order: test_table = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
for i, el in test_table do
print('i = ', i, ', el = ', el)
end
. The console outputs the following: i = 13, el = 13
i = 1, el = 1
i = 2, el = 2
i = 3, el = 3
i = 4, el = 4
i = 5, el = 5
i = 6, el = 6
i = 7, el = 7
i = 8, el = 8
i = 9, el = 9
i = 10, el = 10
i = 11, el = 11
i = 12, el = 12
. That is, the 13th element comes first, and then all the others in order. And the most interesting thing is that this manifests ONLY when the array size is 13 elements; everything else I tested with a larger or smaller size iterated normally, starting from the 1st element. This is a Lua feature. I encountered this in code where the order of iteration was important.
In reply to Jack_of_shadows
User Avatar
12 years ago
Auto-translated
This is normal behavior. You cannot rely on the order of iteration in such loops.
Translation of the Lua 4.0 manual
The order in which the elements of a table are traversed is undefined, even for numerical indices. If you want to traverse indices in numerical order, use the numerical for.
It may seem strange at first glance, but if you think about it, you can understand that the order is not always unambiguous, because the index can be of any type.
User Avatar
12 years ago
Auto-translated
i is not initialized, so everything seems logical...
User Avatar
12 years ago
Auto-translated
It's understandable that you can't rely on the "order" approach, but as they say, "I've done it this way a thousand times, and it always worked." Now, I've already reworked the critical parts using a different `for` loop.
User Avatar
12 years ago
Auto-translated
Gentlemen, how can I use scripts to construct a building in a town? I couldn't find such a function, but I need it...
User Avatar
12 years ago
Auto-translated
UpgradeTownBuilding(town_name, building_id)
Constructs or upgrades a building in a town, increasing its level by one.
User Avatar
12 years ago
Auto-translated
So, if a building hasn't been constructed, it's considered level zero, right? Does the function account for this?
In reply to Ment
User Avatar
12 years ago
Auto-translated
Ment
So, if a building hasn't been constructed, it's at level zero, right? Does the function account for this?
Yes, it does.
User Avatar
12 years ago
Auto-translated
BlockTownGarrisonForAI - does this prevent an AI hero from recruiting creatures from a town, or does it prevent a hero from hiding in a town? Is there a way to set an upper limit on development, not for all heroes on the map, but only for some?
User Avatar
12 years ago
Auto-translated
Prevents AI heroes from taking a garrison from a town and, as a side effect, from entering the town completely.
User Avatar
12 years ago
Auto-translated
People, I need help with the scripts for my mission. I've created a scenario with a huge army. I need it so that when the player approaches the main enemy, a dialogue box pops up saying that they cannot be defeated, and a portal appears in a specific location, with enemies guarding the path to it! Is it possible to do this? Also, I want Biara and Alaric to appear on either side of the final battlefield and start attacking me. Then, I would capture the battlefield and win!
User Avatar
12 years ago
Auto-translated
:D I don't know if this is a script or not, but how do I specify the number of creatures? :D
:smile50:

Added after 4 minutes
How do I create a quest where the hero must survive, and how do I make it so that no player needs to capture a Castle within one week?
In reply to Dark messain
User Avatar
12 years ago
Auto-translated
Dark messain
People, I'm creating a mission, help me with the scripts. I made a location with a huge army in the mission. I need a dialog box to appear when you approach it, saying that they cannot be defeated.

This is not difficult to do. Just create a region and attach a trigger to it. I can send you a manual that describes this in detail.

Added 5 minutes ago
Dark messain
and a portal appears in a certain place.
But this is unlikely. Objects of this type cannot be created or moved.

Added 9 minutes ago
Dark messain
And also, I want Biara and Alaric to appear on both sides of the last location and start attacking me. And then I take the location and win!!!

This can be done using standard functions. Read the file with them; everything is very clear there.

Added 5 minutes ago
Dark messain
:D I don't know if this is a script or not, but how do I specify the number of creatures? :D :smile50:

Added 4 minutes ago
How do I make a quest where the hero has to survive, and how do I make it so that none of the players have to capture a Castle within a week?

No, it's not a script. Just select the object with the mouse and press the spacebar.

Everything about quests is also described in detail in the topic "Questions about the editor." If I find the right post, I'll post it here
In reply to MasteR
User Avatar
12 years ago
Auto-translated
Friends! To avoid bothering you with my silly questions, could you please share a link to the Nival's Map Editor Manual? Just a recent link, please, as I checked the previous posts, and the links there are no longer available:( Thanks in advance!

Statistics

Welcome our newest member: recijeb