My code's not working! any help?

Maps and the art of mapmaking.
JagoBC
Leprechaun
Leprechaun
Posts: 29
Joined: 29 May 2006

My code's not working! any help?

Unread postby JagoBC » 07 Feb 2008, 02:28

I put the following code in the script section to change a necromancer town to haven upon capture:

function TransN2H()
TransformTown("NH", 0);
SetObjectFlashlight("NH", "NewHavenLight");
SetAIPlayerAttractor("NH", 6, 2);
Trigger(OBJECT_CAPTURE_TRIGGER, "NH", nil);
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "NH", "TransN2H");

Now, obviously my town's internal name is NH. And in fact the script works fine turning the town to Haven. However, it turns the town to haven EVERYTIME it is captured. Clearly the line changing the Capture function call to nil is not working. I tried substituting an empty function for nil, but the game simply will not change the Capture Function to a new function inside the current function.

I changed the code to the following as a work around
function TransN2H()
if xNH == 0 then
TransformTown("NH", 0);
SetObjectFlashlight("NH", "NewHavenLight");
SetAIPlayerAttractor("NH", 6, 2);
xNH = 1;
end;
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "NH", "TransN2H");

but it seems messy (it requires an otherwise useless variable), and it just plain bugs me the original code does not work. Any suggestions?

User avatar
rdeford
Assassin
Assassin
Posts: 299
Joined: 17 Apr 2007
Location: Sequim, USA
Contact:

Unread postby rdeford » 09 Feb 2008, 15:50

@ JagoBC

I really ought to actually try your code in a test map before replying, but I just don't have the time. Here is what I suggest you try based on my own past experience with this type of error.

My theory is that the function is generating an error prior to the

Code: Select all

Trigger(OBJECT_CAPTURE_TRIGGER, "NH", nil);
call and not actually making the call.

So, turn on the console screen and watch what happens when you capture the town. If you see any errors, you must eliminate them.

BTW, based on just looking at this post, your script code looks fine to me and your workaround shows an excellent grasp of scripting principles. I am looking forward to playing your map when it is finished. What is its name so I may look for it?
rdeford, Mage Of Soquim

“Forgiving and being forgiven, loving and being loved,
living and letting live, is the simple basis for it all."

Ernest Holmes 1984

JagoBC
Leprechaun
Leprechaun
Posts: 29
Joined: 29 May 2006

Unread postby JagoBC » 16 Feb 2008, 19:11

yes, I thought of that and disabled all the other code except the two lines that transform the town and redirect the trigger; the same thing happened. I really believe that it simply won't allow redirecting a trigger function call from inside the function currently called by that same trigger. Supporting this supposition is the fact that I have a few other places in the code where I have a function triggered by an event which then calls upon a secondary function and I AM able to redirect the trigger from the secondary function. Danged annoying if you ask me but not impossible.

Now, however, I am having trouble deploying reserved heroes. Oy!

Disappointingly, this map was nearly finished in HOF, and all the code seemed to be working. Then TOE came out and not only did they renumber the town types (forcing me to rework all my transform town code) but apparently they tweaked lots of little scripting commands. And has anyone noticed that the two editor manuals that are titled NEW are not even updated with the TOE changes?

I really need to get the console up and running. Can anyone remind where the directions are for this?

Thanks

P.S. -- My map's name is Death Valley. I hope to have it ready soon...

User avatar
rdeford
Assassin
Assassin
Posts: 299
Joined: 17 Apr 2007
Location: Sequim, USA
Contact:

Unread postby rdeford » 16 Feb 2008, 20:21

JagoBC wrote:yes, I thought of that and disabled all the other code except the two lines that transform the town and redirect the trigger; the same thing happened. I really believe that it simply won't allow redirecting a trigger function call from inside the function currently called by that same trigger.
Yes you can. I do it all the time. Here are two pieces of working code from two different map scripts to show you how I did it:

Code: Select all

function feederRgnGreeting()
	if GetCurrentPlayer() == PLAYER_1 then 
		MessageBox(path.."feederGreeting.txt");
		Trigger(REGION_ENTER_AND_STOP_TRIGGER, "feederEntranceRgn", nil);
	end;
end;
  Trigger(REGION_ENTER_AND_STOP_TRIGGER, "feederEntranceRgn", "feederRgnGreeting");

function heaven1Captured()
	heaven1Quest = 0;
	print("heaven1Quest = ", heaven1Quest);
	Trigger(OBJECT_CAPTURE_TRIGGER, "heaven1", nil);
end;
  Trigger(OBJECT_CAPTURE_TRIGGER, "heaven1", "heaven1Captured");

I have done more that just use nil disable the trigger. I've used the names of other functions to change the target for the trigger as well. It works just fine.
Now, however, I am having trouble deploying reserved heroes. Oy!
I did it once on a map and it worked. But, I deleted it when I revised the map so I cannot give you an actual example. But, as I recall, you have to go into the Player Properties tab on the Map Properties and reserve the hero on the Reserve Heroes List for a particular player, then you can deploy that hero later on with the script. Do not forget that you have to use the hero's ID when you deploy it, not the hero's game name or the hero's scripting name. To find a particular hero's ID, place the hero on the map temporarily. Select the hero and display the Objects List Panel over on the left hand side of the editor screen. The name that appears in the Name column for the hero will be the ID. For example, the Barbarian hero commonly known as Kilgham has Hero9 as its ID. Delete the hero from the map once you know the ID. Then, use that ID when you deploy the hero.
Disappointingly, this map was nearly finished in HOF, and all the code seemed to be working. Then TOE came out and not only did they renumber the town types (forcing me to rework all my transform town code) but apparently they tweaked lots of little scripting commands. And has anyone noticed that the two editor manuals that are titled NEW are not even updated with the TOE changes?
Yes, I noticed. I had to go onto the Internet and do a little digging to find all the new IDs. Go here to get the new IDs for example:
http://www.heroesofmightandmagic.com/he ... :creatures

BTW, I don't think they tweaked any existing IDs or scripting commands except the town IDs. They simply added more functions, and more IDs, but did not tell us about all the additions. (The new functions are in the new manual, but not the new IDs.) All my HOF maps, which have LOTS of scripting run just fine with ToTE, but I did not use the transform towns function.
I really need to get the console up and running. Can anyone remind where the directions are for this?
You CANNOT succeed in writing a working script without the console. Period. The code check done by the editor is worthless. No, more than that, it is inaccurate and misleading. Do not use it. The only way to check your code is to let the game compile it, which it does every time you open a map, and watch what happens on the console screen. Your script will not run properly (if at all) as long as any error appears. The instructions for enabling the console can be found in Basics Of Heroes V Scripting Guide written by Pitsu, which is available on this web site. But, to save you a little time, here is an excerpt from that guide:

Code: Select all

Adding string 
setvar dev_console_password = schwinge-des-todes 
as the last line of autoexec.cfg file
Under My Documents/My Games/Heroes of Might and Magic V/Profiles find  input.cfg file and add
		bind show_console '`' 
right after the line saying bind enter_pressed 'NUM_ENTER' 
In case of having Hammers of Fate expansion you need to edit input_a1.cfg.

In game you should now be able to enter the console by pressing ` (the key above TAB).
Keep in mind that this guide has not been updated for ToTE, so adapt the instructions as required.
rdeford, Mage Of Soquim

“Forgiving and being forgiven, loving and being loved,
living and letting live, is the simple basis for it all."

Ernest Holmes 1984

JagoBC
Leprechaun
Leprechaun
Posts: 29
Joined: 29 May 2006

Unread postby JagoBC » 18 Feb 2008, 22:46

I have searched the website using the search function and also googled the name of the guide, but I can not find instructions on activating the console. Where on this site is it located? Does anyone have a link?

User avatar
rdeford
Assassin
Assassin
Posts: 299
Joined: 17 Apr 2007
Location: Sequim, USA
Contact:

Unread postby rdeford » 19 Feb 2008, 00:16

JagoBC wrote:I have searched the website using the search function and also googled the name of the guide, but I can not find instructions on activating the console. Where on this site is it located? Does anyone have a link?
JagoBC,

First, those are the instructions for activating the console up there in my last post. I guess some of the formating got lost in the copy/paste so they are a little hard to follow. Sorry.

Second, here is the link to the CH page where you can download the Guide.
https://www.celestialheavens.com/567
rdeford, Mage Of Soquim

“Forgiving and being forgiven, loving and being loved,
living and letting live, is the simple basis for it all."

Ernest Holmes 1984

JagoBC
Leprechaun
Leprechaun
Posts: 29
Joined: 29 May 2006

Unread postby JagoBC » 20 Feb 2008, 01:16

Thanks!


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 8 guests