How do you debug scripts?


(nUllSkillZ) #1

Hi,

I know that scripts can be debugged with:


+set g_scriptdebug 1 +set logfile 1

But at the moment I’m thinking of a graphical approach to debug scripts.
It shouldn’t be time consumpting, should be easy to use and the used tools should be freeware.

I think UML (Unified Modeling Language) / flow charts could be an approach.


(]UBC[ McNite) #2

Well I don’t know about that, but here s what helped me making my script for The River II without problems and I was a complete script noob when I started. It consists of 2 simple things:

a) usage of messages (wm_announce) in the script: text messages in the game appear while I test the map, telling me exactly which parts of the script get executed (see example of script). Knowing what gets executed and what doesn’t I knew exactly where to search for the bugs, which were almost always mistypings in the entities. This part of the script is from the final though, so all the messages are disabled.

spawnstation // second allied spawn - after repairing the tram engine - descr. "station"
{
}

spawnstation_wobj
{
	spawn
	{
		wait 150
		setstate spawnstation_wobj invisible
		setstate spawnstation invisible
		//wm_announce "^2spawnstation_wobj invisible"
	}

	trigger stationtakenover
	{
		wm_objective_status 1 0 2
		wm_objective_status 1 1 1
		wm_announce "Allies have taken over the Tram Station!"

		wait 50
		//wm_announce "^2trigger spawnstation_wobj stationtakenover executed"

		wait 50
		//wm_announce "^2trigger spawnstation_wobj on"
		trigger spawnstation_wobj on

		//wait 50
		//trigger spawntunnel_wobj off // don't think we need to turn it off
		//wm_announce "^2trigger spawntunnel_wobj off executed"

		//wait 50
		//trigger spawncastle_wobj on // put that into spawnroad_wobj off
		//wm_announce "^2trigger spawncastle_wobj on"

		wait 50
		trigger spawnroad_wobj off
		//wm_announce "^2trigger spawnroad_wobj off executed"

	}

	trigger on // forces forward allied spawn
	{
		setstate spawnstation_wobj default
		setstate spawnstation default
		//wm_announce "^2setstate spawnstation + wobj default"

		setautospawn "station" 1
		//wm_announce "^2setautospawn station 1"
	}
}

b) In case I got messages like “mistake in line 47” I copied and pasted the whole script from the texteditor to a MS Excel sheet. Each line of the script gets into 1 line of excel, and its pretty easy to find out about the misbehaving line then.

All other errors I got from the console of the game were either self-explaining or could be found easily within the forum.

Reading your approach with a flowchart I get the impression you don’t search for a debug-tool but for something that helps to visualize complex scripts. I think for that its most important to use the "// - info-to-be-remembered- " tool within the script :smiley:

So far about my simple but competely effective approach to scripting.


(Ifurita) #3

b) In case I got messages like “mistake in line 47” I copied and pasted the whole script from the texteditor

If you open up a .script file in notepad, CTRL+G will allow you to go to a specific line


(Mean Mr. Mustard) #4

Just in case you did know this (big time saver…), if you make a change to a script, you can just do a /map_restart. This will set the map to the beginning again without reloading it- but reload the new script. Also, if you have something time consuming like escorting a vehicle, you can use a /timescale x to speed up the tiime by a factor of x


(thegnat) #5

I prefer using a decent editor like UltraEdit. There is a similar free tool (dont know the name anymore - silly brain :weird:), someone in this forum posted an ET syntax highlighting addon for it some time ago.
In such an editor, you can enable line numbering. Much easier to handle…


(leifhv) #6

I use a the preprocessor in my C++ compiler…have a look at this post:

http://www.splashdamage.com/index.php?name=pnPHPbb2&file=viewtopic&p=51593&highlight=#51593

Using this I can have a lot of debug messages in the debug/test versions of my map but for release builds no debug messages appear.

Offcourse you’ll need a C++ compiler for this but there are several free ones out there. Even Microsofts compiler is a free download now if I remember correctly…not the IDE offcourse but you don’t need that.

Life