[H5 EDITOR] Troubleshooting topic

Maps and the art of mapmaking.
myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 10 Oct 2006, 04:57

Grumpy Old Wizard wrote: It is fortunate that we have an active and helpful mapmaking guild here. :) We are learning much more from each other than from the tutorials.
GOW
i definetly agree, if it wasnt for the help ive recieved here, i would have quit long ago, and the left scripting behind shaking my head in confusion.

thxs Othmaar. that script helps, i think the key is that i didnt know about global variables. i had a feeling the varibles were resetting themselves. now that i know about global variables, that will help making scripts. i didnt know that you could set them to be true or false either.

is setting global variables the same as using this command?
SetGameVar(Name, Value); - sets the name of the games general variable

but im not sure im just ready for arrays, and "for I" statements :)

Othmaar
Leprechaun
Leprechaun
Posts: 22
Joined: 27 Sep 2006
Location: Oslo, Norway

Unread postby Othmaar » 10 Oct 2006, 06:38

MY wrote:is setting global variables the same as using this command?
SetGameVar(Name, Value); - sets the name of the games general variable
The SetGameVar() function is not built into LUA. It is defined by the developers themselves. I havent found it in the .pak files, but I will take a look because I am curious myself.
GOW wrote:It is fortunate that we have an active and helpful mapmaking guild here. smile We are learning much more from each other than from the tutorials.
Yes, not trying to scare anyone away. I was thinking maybe code related questions belonged in another topic thats all. Codeblocks take a lot of space and the topic is about mapmaking after all.

Take a look at this link all. Not a tutorial, but one should be able to clear up some misunderstandings by browsing a bit in the LUA documentation ;)
http://www.lua.org/manual/5.1/
O.

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 10 Oct 2006, 07:21

MY wrote:is setting global variables the same as using this command?
SetGameVar(Name, Value); - sets the name of the games general variable
I use SetGameVar/GetGameVar only when a variable is needed for different script files. For example you have combat scripts, which are not in the same file as the general map script. As long as you work within one file, IMO it is not necessary to define them at all before giving them a value. They are automatically defined when first time mentioned in script.
(Well, I have not really studied any LUA manual, but base my logic on what i have seen working and what i know from some other languages.)

Othmaar
Leprechaun
Leprechaun
Posts: 22
Joined: 27 Sep 2006
Location: Oslo, Norway

Unread postby Othmaar » 10 Oct 2006, 08:05

Warning: Long and patronizing post :D
Please do not take this personal. The following should prevent a lot of bugs that can be very hard to spot.
Pitsu wrote:As long as you work within one file, IMO it is not necessary to define them at all before giving them a value. They are automatically defined when first time mentioned in script.
This is a clear example of misleading (diplomatic form of downright wrong) information. Programming syntax is not a matter of opinion.

1. Declaration is considered good form, and ensures both backward and forward compatibility. Meaning, if a future or past version of LUA requires declaration a script fails if variables are not declared. Using local declarations also ensures that the local value for the variable is used. This is important because you may not know if the variable name is used another place in the script.

2. Variables are accessible only within the block (or chunk) where it was declared (defined is a misleading word to use here). A file is usually one chunk. The game loads several script files before it runs the MapScript. There may be variables there that are global. If you use these without declaring them you invite bugs to your script.

I dont mean to be patronizing or rude, but erroneous information like that can cause a lot of headaches among readers of the topic. Hell, while I am at it I might as well correct another recent "misleading" information:
GOW wrote:Pitsu wrote:
.
And not talking about any personal experience, but is this line "Trigger( PLAYER_REMOVE_HERO_TRIGGER, PLAYER_7); " correct? No "nil" or function name after PLAYER_7 ?


"nil" would make the script function only once. All that is necessary is the player ID.

Quoting the manual, and I have use a trigger like this in my map to determine when the main human heroe dies using nothing but the player ID as the parameter. The last script I posted *should* work, as it follows the same pattern I used to implement mine.
The quote is taken entirely out of context. The fact that your script works is a coincidence. Look at this:
The Manual wrote: From the HOMM5_practical_guide.pdf, page 54:

Code: Select all

function Meeting( heroname )
if heroname == "Christian" then
SetPlayerResource( PLAYER_1, GOLD, 10000 );
AddHeroCreatures( heroname, CREATURE_ARCHANGEL, 1 );
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "meeting", nil );
end;
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "meeting", "Meeting" );
This example can be conventionally divided into two blocks: The description of the function (1) and the use of this function (2) in the trigger (3).
In the function, we describe what the player is given when the trigger works, and tell the trigger to work only once.
The Trigger will work only once because it is removed (look at my previous post) inside the function using nil as a parameter.
The Manual wrote: From the HOMM5_script_functions.pdf, page 55:
If the functionName parameter is not equal to nil, the function sets the handler function with that name for the specified in-game event. Otherwise the function removes the handler from this event. For each event, there can be only one handler function set. Setting another function onto the event which is already handled will remove the first handler.
So there! :D
O.

User avatar
Grumpy Old Wizard
Round Table Knight
Round Table Knight
Posts: 2205
Joined: 06 Jan 2006
Location: Tower Grump

Unread postby Grumpy Old Wizard » 10 Oct 2006, 14:07

Othmaar wrote: In addition I believe I read in the documentation that the Human player is always PLAYER_1.
I think that is stated in the editor theory part of the manual, but the documentation is wrong. :)

My map is a single player map with all 6 positions playable by the human player. Scripting will not work without using PLAYER_2 for blue, PLAYER_2 for green, ect.

GOW
Frodo: "I wish the ring had never come to me. I wish none of this had happened."
Gandalf: "So do all who live to see such times but that is not for them to decide. All we have to decide is what to do with the time that is given to us."

Othmaar
Leprechaun
Leprechaun
Posts: 22
Joined: 27 Sep 2006
Location: Oslo, Norway

Unread postby Othmaar » 10 Oct 2006, 14:12

My map is a single player map with all 6 positions playable by the human player. Scripting will not work without using PLAYER_2 for blue, PLAYER_2 for green, ect.
Cool, nice to know. Guess I will get to use player = GetCurrentPlayer() :)
O.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 10 Oct 2006, 15:21

Grumpy Old Wizard wrote:
Othmaar wrote: In addition I believe I read in the documentation that the Human player is always PLAYER_1.
I think that is stated in the editor theory part of the manual, but the documentation is wrong. :)

My map is a single player map with all 6 positions playable by the human player. Scripting will not work without using PLAYER_2 for blue, PLAYER_2 for green, ect.

GOW
yes, i can confirm that, in the sylvan single map im making i have the human player as green, player 3. so all my references in the script are to player 3. even when i use the @OpenCircleFog command in game, i have to clear fog for player 3.

but when i load my map in the game, i select player 1, which is green not red. and you have to be careful, in my map i have human player3, and computer player 7. i tried to add a new computer player.
i thought dark blue would be a nice color, so i added computer player2.
when i loaded the map, player2 became player1, and human player 3 became player2 and the game instantly crashed upon starting to load.
so the game slides all the players down. if you make a human player anything other than player1, you cant have any computer players below that.

overall in future i think im going to always just pick player 1 red for player 1. it saves alot of confusion, and i suppose you wont have to use the GetPlayer function either. I didnt do that for this map im making since i didnt want red sylvans.
and if you go back to page 8 or 9 of this post, by picking player3 you can see the problems it caused me. i cannot use the GetObjectiveState command. the game cannot find any objectives i have for player3.
it always returns the error, objective not found, i guess since its a singleplayer map, the game looks for objectives in the player1 spot.
which limited the map i made. so another thing to remember is that if you choose anything other than player1 for your map, you wont be able to use the GetObjectiveState function. which is annoying that you always have to have red as the humanplayer.

**edit*** and another problem with selecting a human player other than number 1 is that if you put common objectives, the map will not load. it says player not found.
i just found this out because im trying to figure out how to use the GetObjectiveState function to work with player3 and added a common objective.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 10 Oct 2006, 18:08

i have another question :)

is the only way to affect player resources is with the SetPlayerResource command?

i was hoping to have an event where the player looses 10 of one resource, 10 of another, that kind of thing, and a message saying "you loose resources".

but it only seems you can set resources, not subtract from existing ones right?

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 10 Oct 2006, 18:14

myythryyn wrote: but it only seems you can set resources, not subtract from existing ones right?
perhaps:

current = GetPlayerResource(PLAYER_1, 5);
if current >= 10 then
SetPlayerResource(PLAYER_1, current - 10, 5);
end;

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 10 Oct 2006, 18:50

Pitsu wrote:
myythryyn wrote: but it only seems you can set resources, not subtract from existing ones right?
perhaps:

current = GetPlayerResource(PLAYER_1, 5);
if current >= 10 then
SetPlayerResource(PLAYER_1, current - 10, 5);
end;
that should work...since you cant have a negative number for quantity of resource, the above script will only happen if the player has more than 10, and they will loose 10 of whatever that amount is.

but i have a problem where i have too many events all triggered by new day.
i have these events triggered by the new day trigger -

current = GetPlayerResource(PLAYER_1, 5);
randomnumber = random(101);

if (randomnumber <= 50 and current >=10 ) then
SetPlayerResource(PLAYER_1, current - 10, 5);
MessageBox("Maps/SingleMissions/test/test.txt");
elseif GetDate(day) == 15 then
do this event

im worried that if the first random event happens on the same day as the event that is supposed to happen on day 15, then the event for day 15 wont happen.
is that what will happen? maybe i shouldnt use "elseif".....is there such a thing as "elseor"?

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 10 Oct 2006, 19:09

I am not sure I understand when exactly the scripts have to trigger. You mean that one triggers at random time and other on day 15. And on day 15 both may happen?
in that case cant it be

Code: Select all

if (randomnumber <= 50 and current >=10 ) then
SetPlayerResource(PLAYER_1, current - 10, 5);
MessageBox("Maps/SingleMissions/test/test.txt");
end;

if GetDate(day) == 15 then
do this event 
Both "if"s are triggered no matter whether the other is true or false. Right?

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 10 Oct 2006, 19:34

Pitsu wrote: Both "if"s are triggered no matter whether the other is true or false. Right?
ok yes, you can have two "if" events happen on the same day, i just checked, wasnt sure it was possible, thought maybe after one "if" happened, the function ended.

thxs :) its hard sometimes workign with only a small set of triggers that can be limiting, and having to have multiple events happen for multiple players on one trigger like the new day trigger.

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 10 Oct 2006, 19:49

With the new day trigger i made all days separate functions and then triggered them in a daily event. Like:

Code: Select all

Trigger (NEW_DAY_TRIGGER, "dailyevents");

function dailyevents()
        day1();
        day12();
       day23();
end;

function day1()
if GetDate() == 1 then
script
end;

function day12()
if GetDate() == 12 then
script
end;

function day23()
if GetDate() == 23 then
script
end;
BTW, Ruins in the desert in the testing section is mine. I know Othmaar will start to :wall: when he reads the scripts :) , and I admit some of them are most likely working only due to a coincidence. Many of the scripts were in fact done even before the manuals came (by copying commands from game data files) and i had even less idea about what is going on than i have now. But one can have a look at them anyway if interested.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 10 Oct 2006, 20:13

ok i will try that map out.

i also just found out that while you cannot enter a negative value into the script for the command setplayerresource, you can subract from the players total, until they reach a negative, in which case the game gives and error message, and does not subtract from the resource.
but the rest of the script seems to continue working after the error.
and im assuming that as soon as the player has enough resources to subtract again, the function will work again.

i suppose it would be an intersting way to keep the player very resource limited until they do something to stop the event subtractions happening :)

User avatar
Grumpy Old Wizard
Round Table Knight
Round Table Knight
Posts: 2205
Joined: 06 Jan 2006
Location: Tower Grump

Unread postby Grumpy Old Wizard » 11 Oct 2006, 09:24

myythryyn wrote:ok i will try that map out.

i also just found out that while you cannot enter a negative value into the script for the command setplayerresource, you can subract from the players total, until they reach a negative, in which case the game gives and error message, and does not subtract from the resource.
but the rest of the script seems to continue working after the error.
and im assuming that as soon as the player has enough resources to subtract again, the function will work again.

i suppose it would be an intersting way to keep the player very resource limited until they do something to stop the event subtractions happening :)
I would be very careful in putiing in events that take away player resources too much. He battles for the resources, sometimes taking large losses to get something he needs for the next building and will likely become very frustrated with too many negative events. Additionally if the events are random he has trouble with plaanning what buildings to build when since he dosn't know when he will be with a negative event.

Just a thought.

GOW
Frodo: "I wish the ring had never come to me. I wish none of this had happened."
Gandalf: "So do all who live to see such times but that is not for them to decide. All we have to decide is what to do with the time that is given to us."

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 11 Oct 2006, 14:28

i was only making a silly idea :) i did add a random event where the player looses resources, but it doesnt happen often and there is a reason for it. plus i dont think it works all the time, and i cant figure out why. i get the message saying you loose resources but it doesnt subtract all the time.

but, it looks like thats it, im done. after 600 or so lines of script, (thanks to the gods of copy and paste) and a couple weeks of frustration, i finished the map i made. i could have done more, but its time to play the maps that are being made instead of making them.
its funny after all that script, the events i made arnt very complicated, dont really do that much, and im sure anyone reading my script will get a headache, and make any programmer wince, but for my first time trying it, i think i did good. :)
just want to thank everyone that has helped me here :)
and of course, you have to test my map, its called Fury of the Elements, it should be up for testing soon, i just submitted it and has all the scripting ideas you guys helped me with in it.

zanan
Leprechaun
Leprechaun
Posts: 2
Joined: 11 Oct 2006

Unread postby zanan » 11 Oct 2006, 23:07

Hello all...

Excuse the language but english is not my native language...

I need help with a simple event I want to setup in my map.
I read all topics including the one from myythryyn, but this simple trigger wont work.

Maybe you can help.

Here is what I Want to do: On day 28 I want Deirdre to spawn in a cave, in which I put 1 one way teleport. She is supposed to rush human players through the teleport. I put Deirdre in the reserve heroes for player 3.

I am using that script, that I pasted and adapted from the post I was talking about:

function event()
if GetDate(DAY) == 28 then
OpenCircleFog(145,88,1,5,PLAYER_3);
DeployReserveHero("Deirdre",145,88,1);
Trigger (NEW_DAY_TRIGGER,"event");

I tried this playing the player_3 that should normally be played by AI. But nothing happens. The OpenCircleFog does not even work( I added it just for testing purpose). So I believe there is a problem with the trigger, or maybe an error in the date setup...

If anyone can help ,would be great, because I just finished this XL map (after hours...) and can't even play it as intented just because this sript wont work.

I'm getting mad because I need 4 spawns, and the first one is already difficult to setup.

Thank you.

Othmaar
Leprechaun
Leprechaun
Posts: 22
Joined: 27 Sep 2006
Location: Oslo, Norway

Unread postby Othmaar » 12 Oct 2006, 02:25

Try

Code: Select all

function event()
  local day;
  day = GetDate(DAY);

  -- First event
  if  day == 28 then
    OpenCircleFog(145,88,1,5,PLAYER_3);
    DeployReserveHero("Nemor",145,88,1); -- Nemor is Deirdre's scriptname
  end;

  -- Second event
  if day == xx then
    <do some cool stuff on day xx>
  end;

  -- Third event
  if day == yy then
    <do some cool stuff on day yy>
  end;

  -- Fourth event
  if day == zz then
    <do some cool stuff on day zz>
  end;

end;

Trigger (NEW_DAY_TRIGGER,"event");
O.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 12 Oct 2006, 02:41

and after that i recommend to add this command
because when i tried this the AI is a coward and sometimes would appear, then just sit there scared to move and not enter the monolith. or would takes turns to finally move. this makes the AIhero move its butt.

if day == 29 then
EnableHeroAI ("Nemor", false); -- this gives you control so the AI doesnt do stupid things
MoveHero ( "Nemor", x, y, floor); -- co ordinates of the place you want the hero to travel too.
end;

then create a region right outside of the town you want attacked, right in the middle x, y location as above, called attack now, then use this command

function attacknow ()
if GetCurrentPlayer () == PLAYER_whoever is the attacker
EnableHeroAI ("Nemor", true);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "attack");

-- this turns AI back on when it arrives at the spot you want it to. and usually attacks after that if its outside a city.
you might also want to use the blockregion command and create blocked regions so the AI cant move anywhere and is forced to attack.

and also watch out what player you have set to be the human player, there is always problems if its any other player than player1, but for script you indicate whatever player you choose.

zanan
Leprechaun
Leprechaun
Posts: 2
Joined: 11 Oct 2006

Unread postby zanan » 12 Oct 2006, 13:25

Thanks for answers.

I finally found the solution to my problem: Scripts do no work in multiplayer maps...

I tried a similar script in solo mode and everything works fine.

Thank you for your help anyway.


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 4 guests