[H5 EDITOR] Troubleshooting topic

Maps and the art of mapmaking.
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 » 05 Oct 2006, 04:53

myythryyn wrote:hello, im hoping someone can help me make this script and would appreciate help with the proper syntax. this is the first script ive tried to make, so its very rough...
im having lvl 7 units disabled in this town, called testtown. if the player enters a certain region, then lvl 7 units for that town will be enabled, so the player can build then
so, i set up the region, and called it testregion.

function Enabledwelling (playerID)
GetCurrentPlayer == playerID
if playerID == "PLAYER_3" then
SetTownBuildingLimitLevel( testtown, 13, 1) ***see below**
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "testregion", nil);
end;
end;
(do i need another end?)

Trigger (REGION_ENTER_AND_STOP_TRIGGER, "testregion", "Enabledwelling" );
You were close. I just tried this and it works. Don't put quotes around Player_3 and be careful with your semicolens.
function Enabledwelling (heroname)


if GetCurrentPlayer () == PLAYER_3 then
SetTownBuildingLimitLevel( "testtown", TOWN_BUILDING_DWELLING_7, 1);
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "testregion", nil);
end;
end;


Trigger (REGION_ENTER_AND_STOP_TRIGGER, "testregion", "Enabledwelling" );
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 » 05 Oct 2006, 14:56

thank you GOW, that worked perfect, i was going to use the Building ID, but the longer script name works.
and with your help, and the magic of cut and paste, i tried to make another script, this one is to display a messagebox after a player completes a player specific objecitve....
the objective is named testobjective, i used the "name" parameter.


function objectivecomplete (heroname)

if GetObjectiveState (testobjective) == OBJECTIVE_COMPLETED then
MessageBox("Maps/SingleMissions/testmap/completemessage.txt");
Trigger( OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", nil);
end;
end;

Trigger (OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", "objectivecomplete" );

but its not working.....any ideas what is the correct syntax?

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 05 Oct 2006, 16:05

In this line:

Code: Select all

if GetObjectiveState (testobjective) == OBJECTIVE_COMPLETED then
remove space between GetObjectiveState and (testobjective).

Also remove space after Trigger in this line:

Code: Select all

Trigger (OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", "objectivecomplete" );
Maybe there are also other errors, but check if it works now...
.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 05 Oct 2006, 19:40

are you sure its the spaces that are the problem? (or only problem)
i removed the spaces and the script didnt show the message after testobjective completed.

the script syntax, with spaces in the places you mentioned works for other scripts i have, and is directly how i copied it from the script provided by GOW above.

im thinking there must be something else wrong, what do you think?

i just read this...maybe this is the problem...this is a quote from the documentation.

"when this trigger works the following parameters are sent to the handler function -
OBJECTIVE_STATE_CHANGE_TRIGGER - the ID of the player whose objective has changed its status(is sent to the handler)."

so maybe i need some kind of line that checks if the trigger has returned a value of PLAYER_3
like
If OBJECTIVE_STATE_CHANGE_TRIGGER == PLAYER_3 then

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

Unread postby Pitsu » 05 Oct 2006, 20:30

Aren't you missing the quotation marks there...
myythryyn wrote:
if GetObjectiveState ("testobjective") == OBJECTIVE_COMPLETED then

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 06 Oct 2006, 00:42

hmm, no the quotations didnt fix it...

here is what i have now

function objectivecomplete (heroname)

if GetObjectiveState ("testobjective") == OBJECTIVE_COMPLETED then
MessageBox("Maps/SingleMissions/testmap/completemessage.txt");
Trigger( OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", nil);
end;
end;

Trigger (OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", "objectivecomplete" );

any other ideas of how to make this script work?
i hope we can get this script to work, its would be nice to be able to give players a message after they complete an objective, since the game gives no other indication of it completing. it even erases the objective after completetion from the mission log.

i even tried the mysterious setting at the very bottom of the objectives, right after show complete, and need complete
there is this section called "state change trigger"
when you open it, you get an option to add a value to the FunctionName parameter, which i was thinking means that when the objective state changes, that function is called, but it didnt work either....
so maybe the problem is in the function itself.

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

Unread postby Othmaar » 06 Oct 2006, 01:26

Have you found any error messages in the console? Also try to insert a debug print line like this:

Code: Select all

function objectivecomplete (heroname)

print('Objectivestate function triggered');
By the way. Remove the quotes in if GetObjectiveState ("testobjective"). Using quotes here mean you send the literal testobjective string as a parameter instead of the variable. EDIT: It occurs to me that is exactly what you want, so never mind :)

If the function does not trigger, then the problem is outside the function. If it does trigger the problem may lie in the MessageBox path string.
O.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 06 Oct 2006, 02:27

im not familiar with the print command yet, when i tried to use it it disabled all my scripts ive made, so i can only assume i was using it wrong.

but i didnt realise the console gives error messages, and now i know whats the problem.
im getting this error-
(Script) ERROR objective with name "testobjective" is not exist.
i tried not using the " " but then the scripteditor changes the word testobjective from orange to black, so im assuming you have to have the ""

it must be how im naming the objective so i re read the documentation. page 24-25 of editor theory explains it. this is how ive named my objective
map properties tree - objectives - primary - player specific - 2 (for player 3)- objectives - 2 - name = testobjective
i even tried using "2" to identify the objective, since its the third objective in the list.

so im stumped on what is the proper way to name or indicate in the script which objective i want to be used for the function.

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 » 06 Oct 2006, 03:36

myythryyn wrote:im not familiar with the print command yet, when i tried to use it it disabled all my scripts ive made, so i can only assume i was using it wrong.

but i didnt realise the console gives error messages, and now i know whats the problem.
im getting this error-
(Script) ERROR objective with name "testobjective" is not exist.
i tried not using the " " but then the scripteditor changes the word testobjective from orange to black, so im assuming you have to have the ""

it must be how im naming the objective so i re read the documentation. page 24-25 of editor theory explains it. this is how ive named my objective
map properties tree - objectives - primary - player specific - 2 (for player 3)- objectives - 2 - name = testobjective
i even tried using "2" to identify the objective, since its the third objective in the list.

so im stumped on what is the proper way to name or indicate in the script which objective i want to be used for the function.
My attempts at playing around with objectives have not met with success, so I fear I will be of no help. However, have you doublechecked the name you gave the objective? Just to be sure, delete the name and retype it to make sure no unwanted space is at the end. I did have a script not involving objectives in which I did have an unintended space at the end of the name which cause me much head scratching.

If anyone does have a working objective or two perhaps you could post step by step specifics as an example for the rest of us to go by.

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."

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 » 06 Oct 2006, 03:38

Have I missed something in the editor documentation? I see no way to script a building to be built. I see ways to limit or allow buildings to be built and a way to check whether a building is built, but nothing to actually build a building.

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 » 06 Oct 2006, 06:42

no, as far as i could see from what i read, there is no way to have a building built in a player town. has anything like that ever been done in one of the nival made maps? maybe we can open it and read the scripts.

hopefully someone can figure out how to make a message appear after an objective completes, i think im totally stumped. maybe thats something we could read in nivals scripted maps too.

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

Unread postby Pitsu » 06 Oct 2006, 07:53

myythryyn wrote:no, as far as i could see from what i read, there is no way to have a building built in a player town. has anything like that ever been done in one of the nival made maps? maybe we can open it and read the scripts..
Build a structure command is not there since Nival never needed it as far as i know. IMO the scripting engine has only the commands that Nival needed at one or another point. Some simple ones like "GetPlayerFaction" or "SetTownStructureLevel" are not existant. For the latter I even do not know a fine workaround. (I did it by changing the owner to an AI player and hope that he builds some structures. Can be done with neutral towns, but will probably be problematic if the town is already under human control)

Back to the objectives. Could you try to define the objective as a common, not player specific one? Just in case there is some trick with the specific ones.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 06 Oct 2006, 13:58

Pitsu wrote: Back to the objectives. Could you try to define the objective as a common, not player specific one? Just in case there is some trick with the specific ones.
i think i understand what you are thinking, that maybe for player specific objectives i need to specify the player....but this is what the documentation says...

"GetObjectiveState(objectiveName, playerID = PLAYER_1);
for player specific objectives, the playerID parameter is ignored. For common objectives, it indicates the player for whom the objectives status is deteremined...."

so i think the only difference between player and specific is if you use the playerID parameter or not. since i am making a one human vs one computer map, and there is no way the computer can participate in the objective, ill try making it common and see what happens.

edit, ok i tried this script for a common objective, but its not in the right syntax..
function testcomplete (heroname)

if GetObjectiveState ("testobjective", PlayerID = PLAYER_3) == OBJECTIVE_COMPLETED then
MessageBox("Maps/SingleMissions/Fury of the Elements/completemessage.txt");
Trigger( OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", nil);
end;
end;

Trigger (OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", "testcomplete" );

i would think it should be more like

GetObjectiveState ("testobjective", PlayerID = PLAYER_3)
if GetObjectiveState == OBJECTIVE_COMPLETED then

but thats probably wrong too...

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

My turn to try :)

Unread postby Othmaar » 06 Oct 2006, 15:49

I also want this kind of triggering to function so I have done some research. My code is at the very end.

Setup
XL (too big for you), 1v1, human vs computer, human is always PLAYER_1. Map properties: player specific objective for [0] Name = PRIMARY_1, Kind: OBJECTIVE_KIND_MANUAL. No other parameters are set in the map properties. Everything else goes into the script (as per the editor documentation).

Synopsis
I have a region named homeborder. When a hero enters this region the function fnHomeBorder is triggered. This function checks to make sure the objective for the correct player is set to completed, but only if the objective is currently in the active state. This leads to the objective state being changed and function fnObjPrimary_1 is triggered handling the consequenses of completing the objective.

Results
Everything works as it should up to the message box. I get an error saying the message file was not found or empty. I tried different pathing alternatives and moved the file around etc. Have anyone successfully implememented a message box? I would love to know how :)

Notes
According to the documentation the human player will always be PLAYER_1 (slot [0] in map properties) inside scripts. This would explain why multuplayer scripting is not possible. I will test this later, but first I need to get my message box working. The documentation also notes that when you decide to make an objective OBJECTIVE_KIND_MANUAL, all handling and parameters is left to the script. In other words, any parameters specified in the map properties below kind is ignored.

Hope this can clarify some issues mentioned above. And please tell me how to use MessageBox :)

Code: Select all

function fnHomeBorder()
	local player;
	local oldobjstate;
	local objstate;
	local newobjstate;
	local objective;
	
	player = GetCurrentPlayer();
	oldobjstate = OBJECTIVE_ACTIVE;
	newobjstate = OBJECTIVE_COMPLETED;
	
	if player == PLAYER_1 then
		objective = "PRIMARY_1";
		objstate = GetObjectiveState(objective, player)
		if objstate == oldobjstate then
			SetObjectiveState(objective, newobjstate, player);
		end;
	end;
end;

function fnObjPrimary_1()
	local player;
	local objective;
	local objstate;
	
	player = GetCurrentPlayer();
	objective = "PRIMARY_1";
	objstate = GetObjectiveState(objective, player)
	
	if objstate == OBJECTIVE_COMPLETED then
		MessageBox("objective_primary_1_completed.txt", "fnJobWellDone")
	end;
end;

function fnJobWellDone()
	-- script engine pats itself on the shoulder :)
	print('Region enter and objective stuff completed successfully!');
end;



Trigger(REGION_ENTER_WITHOUT_STOP_TRIGGER, "homeborder", "fnHomeBorder");
Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER, "PRIMARY_1", "fnObjPrimary_1");
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 » 06 Oct 2006, 16:51

MessageBox("objective_primary_1_completed.txt", "fnJobWellDone")

You did not include the path for the text file...ie "Maps/SingleMissions/A Test Map5/objective_primary_1_completed.txt"

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."

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 » 06 Oct 2006, 17:08

myythryyn wrote: any other ideas of how to make this script work?
i hope we can get this script to work, its would be nice to be able to give players a message after they complete an objective, since the game gives no other indication of it completing. it even erases the objective after completetion from the mission log.
Is the objective type set to OBJECTIVE_KIND_MANUAL?

I tried using scripts to trigger a message after completing a grail quest and couldn't get it to work. I had set up the script under the map properties tree rather than scripting. Maybe you have to use OBJECTIVE_KIND_MANUAL if you want to use any scripting at all with the quest?

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."

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

Unread postby Pitsu » 06 Oct 2006, 17:26

I did use pretty much copy-paste of Mythryyn's script and it looks quite strange. It sometimes works, then, after minor changes it does not. Somehow felt that either the editor does not save always everything correctly or the game loads some older version of the map/scripts...

Anyway, currently what works for me
IMO function objectivecomplete () would be better than function objectivecomplete (heroname) , but it works either way

Code: Select all

function objectivecomplete (heroname) 

if GetObjectiveState ("testobjective") == OBJECTIVE_COMPLETED then
	MessageBox('Maps/SingleMissions/townchange/obj1.txt');
	Trigger( OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", nil);
end;
end;

Trigger (OBJECTIVE_STATE_CHANGE_TRIGGER, "testobjective", "objectivecomplete" ); 
And PLAYER 1 specific objective. Not tested with PLAYER_3

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

Unread postby Othmaar » 06 Oct 2006, 18:12

The heroname parameter just makes that variable available for the function and is optional. It is misleading the way it is used in the documentation because the function itself does not use the variable heroname. The parameter is probably a leftover from a copy/paste operation ;)
Pitsu wrote:It sometimes works, then, after minor changes it does not. Somehow felt that either the editor does not save always everything correctly or the game loads some older version of the map/scripts...
I also noticed this and did some experimenting. When you open a map in the editor it upacks the .h5m file to the Editor/H5MMods/ ... folders (hereafter referred to as the Editor folders). I this process it overwrites all files that have a match in the .h5m file and leaves the rest of the folderstructure intact.

Apparantly when you save a map, it only updates the Editor folders.

Only when you close the map (or close the map editor) does the .h5m file get rebuilt.

So, make sure you close the editor before you test the map and make sure you save files open in external applications (like a text editor) before you close the editor.

1. open editor
2. open map
3. work work work
4. save map
5. save and close files in external applications
6. close map
7. test map
8. tear some hair off your head
9. go to 1. :S
GOW wrote:
MessageBox("objective_primary_1_completed.txt", "fnJobWellDone")
You did not include the path for the text file...ie "Maps/SingleMissions/A Test Map5/objective_primary_1_completed.txt"
I did try earlier, and now did it again ... maybe the filname is too long or the file itself to short (only a single line)? Or maybe some silly typo ... ill try some more :)
O.

myythryyn
Assassin
Assassin
Posts: 293
Joined: 05 Sep 2006

Unread postby myythryyn » 07 Oct 2006, 01:20

Othmaar wrote: I did try earlier, and now did it again ... maybe the filname is too long or the file itself to short (only a single line)? Or maybe some silly typo ... ill try some more :)
are you still having problems with your messagebox? one thing i did notice that is like what Pitsu mentioned about the editor not having things current, or changed, is that when you just enter a new message reference in the map properties tree, it shows the path to the new txt file with "" while any older txt messages have a path with a "/".
the paths do not change from \ to / that till after you save and close the editor and re open it, then all your slashes are in the right direction and paths can be copy and pasted.

so if you are directly copying and pasting the path from a newly made txt file, then you will be copying the wrong path.


so after more tests, i have figured some more interesting things out.
first off, the scripts provided by Othmaaar and Pitsu still did not work for me, i still had that "object" is not exist error message.

so i opened a whole new map, placed player1 and player2, and each gave them an obtain artifact objetive.
then i started as player1. the above scripts worked, a message appeared after objective complete.
i then reloaded the map as player2, and the script did not work.
even though i used Othmaar's script that gets current player and sets it as a variable. it still did not work with player 2.

so then just to make sure, i opened the map im making, and changed player3 to player1 and the script now works.

but this to me is not a solution. the script works, but its limited. it only shows messages if player1 completes an objective.
im making a sylvan single mission, and didnt want it to be a red player, but a green player.

which could have been part of my problem, i set player3 to be the human, but when i load the map in the game, the human player is player1 green. but oddly all my other objectives that i set for player3 in the map property tree work, show up in the objective log and can be compelted, even though im technically player1.
hope that all makes sense :)

but, what would be interesting to figure out, is why the script only works for player1 and no other player....i really didnt want my sylvaans to be a red player.

MER
Peasant
Peasant
Posts: 63
Joined: 23 Jul 2006

Unread postby MER » 07 Oct 2006, 08:34

Othmaar wrote: I did try earlier, and now did it again ... maybe the filname is too long or the file itself to short (only a single line)? Or maybe some silly typo ... ill try some more :)
Did you add your file manually or through the editor? If you added it manually to the .h5m file it could be with a wrong compression (for instance rar-archived files can't be decompressed by the game).


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 0 guests