I've been playing around with the editor, and I can't seem to figure out how to do these two things:
1. The New Day trigger seems to only work during the player's turn. Anyway to do something during an AI turn?
2. Is it possible to detect and run a function when the player Ends the turn?
Thanks for any help!
Day Triggers: During AI turn, and detecting End Turn
-
- Leprechaun
- Posts: 21
- Joined: 21 Aug 2008
- darknessfood
- Round Table Hero
- Posts: 4009
- Joined: 02 Jul 2007
- Location: Netherlands
- Contact:
1. Correction: new day trigger triggers not on human player's turn, but on the turn of a player who moves first. In singleplayer it's always human, in multiplayer - differs .
What do you need to do on AI turn? You can try using GetCurrentPlayer function, it might help.
2. Not possible directly. Can be arranged with GetCurrentPlayer, endless thread and a cycle Only works if there are more then 1 player.
What do you need to do on AI turn? You can try using GetCurrentPlayer function, it might help.
2. Not possible directly. Can be arranged with GetCurrentPlayer, endless thread and a cycle Only works if there are more then 1 player.
-
- Leprechaun
- Posts: 21
- Joined: 21 Aug 2008
Sorry, I keep forgetting that this is a forum for all HOMM versions, so I forget to write which game I'm talking about.
Thanks Franzy for the help. That helps clarify it. I believe I should be able to make it work, either with the endless loop or with a workaround just using the Day Trigger.
Thanks for the great help!
Thanks Franzy for the help. That helps clarify it. I believe I should be able to make it work, either with the endless loop or with a workaround just using the Day Trigger.
Thanks for the great help!
-
- Leprechaun
- Posts: 21
- Joined: 21 Aug 2008
-
- Leprechaun
- Posts: 21
- Joined: 21 Aug 2008
pairs() just produces index, value pairs for a table, to use in a 'for' loop.
as in:
a = {10, 20}
for i,v in pairs(a) do
--some code, i are indices (1,2), v are values (10,20)
end
Is there another way to iterate through a table?
I see this example in the Editor documentation under the function GetObjectCreaturesTypes:
types = GetObjectCreaturesTypes( "my_garrison" );
for index; type in types do
if type == CREATURE_PEASANT then
...
end;
end;
But the odd thing is, this "index; type" syntax isn't in Lua, (I don't think it is at least) and gives an error if I try to use it in game.
I think I'll just try to use a workaround with explicitly defined 'for' loops, like:
for i = 1, length(array) do
...
end
as in:
a = {10, 20}
for i,v in pairs(a) do
--some code, i are indices (1,2), v are values (10,20)
end
Is there another way to iterate through a table?
I see this example in the Editor documentation under the function GetObjectCreaturesTypes:
types = GetObjectCreaturesTypes( "my_garrison" );
for index; type in types do
if type == CREATURE_PEASANT then
...
end;
end;
But the odd thing is, this "index; type" syntax isn't in Lua, (I don't think it is at least) and gives an error if I try to use it in game.
I think I'll just try to use a workaround with explicitly defined 'for' loops, like:
for i = 1, length(array) do
...
end
-
- Leprechaun
- Posts: 21
- Joined: 21 Aug 2008
By the way, is there a way to directly edit the Map Script without opening the editor? It gets time-consuming to have to always close the game, then open the editor, then vice versa just to make every change.
EDIT: I just found out that Heroes used 0 as the first index of arrays. Very annoying, seeing as how all of Lua uses 1-based arrays.
EDIT: One more question: When the game console displays an error, it gives a line for the error like:
"last token read: xxxx at line N in string "DoString script"
Of course, the line N given doesn't correspond to the line in the script when viewed through the map editor, but it always seems to a certain number off. Is there an offset to subtract from N to give you the real line number?
EDIT: I just found out that Heroes used 0 as the first index of arrays. Very annoying, seeing as how all of Lua uses 1-based arrays.
EDIT: One more question: When the game console displays an error, it gives a line for the error like:
"last token read: xxxx at line N in string "DoString script"
Of course, the line N given doesn't correspond to the line in the script when viewed through the map editor, but it always seems to a certain number off. Is there an offset to subtract from N to give you the real line number?
No, index referring works fine in HoMM5, there is just an error in docs. GetObjectCreaturesTypes returns 7 values instead of an array. It should be used like this:I see this example in the Editor documentation under the function GetObjectCreaturesTypes:
types = GetObjectCreaturesTypes( "my_garrison" );
for index; type in types do
if type == CREATURE_PEASANT then
...
end;
end;
c1,c2,c3,c4,c5,c6,c7 = GetObjectCreaturesTypes...
Well of course! Map script is stored in the MapScript.lua file in the map file (it's zip-archive actually). You can extract it, open it in any external program (I personally use SciTE), edit and then pack back. But there is even better way!By the way, is there a way to directly edit the Map Script without opening the editor? It gets time-consuming to have to always close the game, then open the editor, then vice versa just to make every change.
Just place lua file in the data folder, run the game, stat your map, open console and enter command @doFile('myscript.lua') and your script will be executed! This is very useful for debugging, as you can run the game and edit the script simultaneously. Forementioned method with extracting/packing only works if both game and editor are closed.
It's even worse, my friend. Functions return 0-based arrays while manually created are 1-based. That's stupid, but we have to live with thatI just found out that Heroes used 0 as the first index of arrays. Very annoying, seeing as how all of Lua uses 1-based arrays.
Don't know about lines in editor but line number in SciTE always fit.EDIT: One more question: When the game console displays an error, it gives a line for the error like:
"last token read: xxxx at line N in string "DoString script"
Of course, the line N given doesn't correspond to the line in the script when viewed through the map editor, but it always seems to a certain number off. Is there an offset to subtract from N to give you the real line number?
-
- Leprechaun
- Posts: 21
- Joined: 21 Aug 2008
Who is online
Users browsing this forum: No registered users and 2 guests