Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
#1781
Auto-translated
Hmm, it's strange that I didn't notice that. Thanks, I'll try it now.

Added after 1 hour 42 minutes
if GetPlayerResource(1, k1) >= res1{k1+1} then

It seems there's an error here. "attempt to call table value," or something like that. How can I fix it? (I need an array, there are many components).

Whatever
User Avatar
#1782
Auto-translated
res1{k1+1} - the parentheses are incorrect; they should be [], if accessing by index is intended.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1783
Auto-translated
Ah, yes. I made a mistake. Thanks!

Added 59 minutes later
Then, here's another question: can I use a value from an array for text messages? For example: "your troops + < value=army[3] >"?

Whatever
User Avatar
#1784
Auto-translated
Yes, but they are defined in the script:
{"path to text"; army=army[3]}
which means that in the text, the tag will be replaced with the third element of the array.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1785
Auto-translated
Okay. Thank you very much again!

Added 1 hour 29 minutes ago
I apologize, but I have another question:
-How can I calculate the total number of objects (let's say, those poor, long-suffering peasant huts) on the map?
I can assign a common name to them. But how do I output all of this into a single numerical variable?

Whatever
User Avatar
#1786
Auto-translated
Here's how you can calculate the total number of all peasant huts on the map:
peasant_huts_n = length(GetObjectNamesByType("PEASANT_HUT"))
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1787
Auto-translated
Oh yes! I completely forgot about this function for determining the length of the array!

Added 25 minutes later
Ah, no. What if we make the task a little more complicated? Huts that belong only to player 2?

Whatever
In reply to Heroist
User Avatar
#1788
peasant_huts_n = 0
for i,hut in GetObjectNamesByType("PEASANT_HUT") do
if GetObjectOwner(hut) == 2 then
peasant_huts_n = peasant_huts_n + 1
end
end
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1789
Auto-translated
and how does this work...?
damn, I really need to figure out how this for loop works. I just can't find the time. It's a useful thing though.
Thanks for the nth time!

Whatever
In reply to Heroist
User Avatar
#1790
Auto-translated
Heroist
how does this work...?
damn, I really need to figure out how this for loop works. I just can't find the time. It's a useful thing.
Thanks again!

A loop with a counter. In the example above, it will execute the code for each element in the GetObjectNamesByType array. i, hut are indices, where hut represents the current index of the array element, and i - I don't know what it's for, but it doesn't work without it.
Мои карты:
Town
Готовится:Чума (40%), Сосиска(42%), Война Грааля
User Avatar
#1791
Auto-translated
i is a variable that, during the loop, receives a constant increment of one. After the loop is executed, i will contain the number of times the loop was performed (I don't remember if there is a "tick" function here, but it may be relevant in languages with this function).
 

К А
Стикеры GBF в Telegram
User Avatar
#1792
Auto-translated
In this case, the loop will execute the code for all elements of the array. `i` is the key (index) of the array element; it doesn't necessarily have to be a number, and it doesn't necessarily iterate in ascending order, while `hut` is the value of the array element.

Added after 58 seconds
Ment, what kind of thing is that, what does it do, or what should it do?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1795
Auto-translated
Thanks for the explanations, everyone! It just seems like "for" works a little differently here than it does with its counterparts in other programming languages.

Added 5 hours and 17 minutes ago
The error "quantity cannot be negative" - could it be caused by the variable being equal to 0? Is 0 considered a negative number in scripts?

Whatever