Common mistakes and bugs

From WiCWiki

Revision as of 12:00, 12 December 2007 by kowalski (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Misspelling and character related bugs

Case 1 Debug Message:

[Mon Oct 22 15:15:36.906] ***************  ERROR START *************

[Mon Oct 22 15:15:36.906] wico_pythonc.cpp(210): CheckPyError(): Error 

         Exception Type:       exceptions.NameError


         Exception message:  global name 'Ambianc' is not defined


         Traceback( last call last ):


maps/europeTest/python\server.py   44: OnGameStarted()

maps/europeTest/python\server.py   85: Intro()


Solution: The problems started going wrong on row 44. This row calls the Intro() function. So we step down to def Intro() and the next row mentioned in the debug file.

The row 85 in server.py file in this case said Ambianc( ). A search in the file showed there is no function called def Ambianc( ), but there is an def Ambiance(). So it was a misspelling error in this case.


Misspellings and wrong capitalization are among the most usual problems encountered and they are sometimes hard to find since it often “looks correct”.

Making yourself a set of rules how to use capital letters and naming functions/variables, will reduce the amount of this problem.


Case 2 Debug Message:

[Mon Oct 22 15:50:01.218] ***************  ERROR START *************

[Mon Oct 22 15:50:01.218] wico_pythonc.cpp(210): CheckPyError(): Error 

         Exception Type:       exceptions.SyntaxError


         Exception message:  ('invalid syntax', ('maps/europeTest/python\\server.py', 59, 24, "\tAddDeploymentZoneToTeam( 'DZ_Ussr', TEAM_USSR )\n"))


         Traceback( last call last ):?

Solution: This error was caused in server.py, row 59 and the 24th character. The row looks like follows.

AddDeploymentZoneToTeam( 'DZ_Ussr', TEAM_USSR )

And the character that seems to have caused the problem is the left parenthesis.

But this row is correct, so the problem must have been elsewhere. Scrolling up a couple of rows to 56, the problems source is found.

AddDeploymentZone( 'DZ_Ussr'


The right parenthesis is missing in this row, causing problems further down in the code.

I.e. adding an end parenthesis will solve the problem.


Mostly when the ‘invalid syntax’ debug message turns up it’s because of missing end/start parenthesis, end/start brackets or quotation marks. The problem is in most cases found prior to the row indicated by the Debug Message.


Indentation Errors

Case 1 Debug Message:

[Tue Oct 23 09:25:46.609] ***************  ERROR START *************

[Tue Oct 23 09:25:46.609] wico_pythonc.cpp(210): CheckPyError(): Error

         Exception Type:       exceptions.SyntaxError


         Exception message:  ('invalid syntax', ('maps/europeTest/python\\server.py', 55, 1, "\tAddDeploymentZone( 'DZ_Mansion' )\n"))


         Traceback( last call last ):?

Solution:

This error looks much like Case 2 in Misspelling and character related bugs. We start with opening server.py and go to row 55.

AddDeploymentZone( 'DZ_Mansion' )

The debug message points to character 1, which is the A in AddDeploymentZone. AddDeploymentZone is however spelled and capitalized correctly, so the problem lies elsewhere. The answer to the problem lied just above in row 54.

AddDeploymentZone( 'DZ_Village' )


In this case there is missing a tab in front of the row making the first rows looking like this:


50 def Intro( ):
51      DebugMessage( "Intro::" )
52
53      # Add deployment Zones to use later on.
54      AddDeploymentZone( 'DZ_Village' )       
55      AddDeploymentZone( 'DZ_Mansion' )
56      AddDeploymentZone( 'DZ_Ussr' )

By adding a tab in front of the row 54, the problem will be solved.


Take your time checking your functions and keep a keen eye on your tabs as this will save you a lot of headache further on.

Case 2 Debug Message: Not an actual debug message but if you notice that your if-statements are ignored or acting weird.

Solution: A common cause for this problem is tab related.

if mapvars.pltLastStandRu.Size( ) <= 2:
queLastStandComplete.Execute( ) 

The above example would ignore the if-statement and in this case start the actionqueue named queLastStandComplete.

The correct version would look like this.

if mapvars.pltLastStandRu.Size( ) <= 2:
    queLastStandComplete.Execute( ) 


Now the actionqueue will start only if the size of mapvars.pltLastStandRu is less then or equal to 2.


Keeping your tabs in check is even more important when having if-statements in if-statements.


primary

if mapvars.pltLastStandRu.Size( ) <= 5:

secondary

if GetCommandPointOwner( 'CP_Village' ) == TEAM_NATO:
    MissionCompleted()

tertiary

if GetCommandPointOwner( 'CP_Village' ) == TEAM_USSR:          
mapvars.grpMansionRuAttacker2.ActivateRefillMode( 1, 3, [ USSR_BMP_3, USSR_T62, USSR_BMP_3 ], 'areaRuSpawn1', 5, None, 20 )


In the above script the tertiary part will never happen because of a faulty tab placement, as the MissionCompleted() function ends the mission. The intention was to have two different if-statements if the size of mapvars.pltLastStandRu was less or equal to 5. In this case the correct way would be.


primary

if mapvars.pltLastStandRu.Size( ) <= 5:

secondary1

if GetCommandPointOwner( 'CP_Village' ) == TEAM_NATO:
    MissionCompleted()


scondary2

if GetCommandPointOwner( 'CP_Village' ) == TEAM_USSR:          
    mapvars.grpMansionRuAttacker2.ActivateRefillMode( 1, 3, [ USSR_BMP_3, USSR_T62, USSR_BMP_3 ], 'areaRuSpawn1', 5, None, 20 )

Both of the secondary if-statements will now be statements to the primary one.

Missing pass or return bug

Case 1 Debug Message:

[Tue Oct 23 15:45:51.015] ***************  ERROR START *************

[Tue Oct 23 15:45:51.015] wico_pythonc.cpp(210): CheckPyError(): Error 

         Exception Type:       exceptions.IndentationError


         Exception message:  ('expected an indented block', ('maps/europeTest/python\\allunits.py', 48, 3, 'def PlayerAward( ):\n'))


         Traceback( last call last ):? 


Solution: This error seems to be located in the allunits.py file, row 48 and the third character.

48      def PlayerAward( ):
49      DebugMessage( 'allunits.PlayerAward::' )
50      
51      # add one helicopter with the cost of 0 to the reinforcements meny.
52      AddToSPReinforcement( 'NATO_Mangusta', 1, 0 )

The marked error in this case is the letter f in def. Since there is nothing wrong with def, the conclusion can be made that it is only a symptom of an error made earlier in the script. Scrolling up a few rows show this.

45      def CounterAttack():
46
47
48      def PlayerAward( ):
49                DebugMessage( 'allunits.PlayerAward::' )
50      
51      # add one helicopter with the cost of 0 to the reinforcements meny.
52      AddToSPReinforcement( 'NATO_Mangusta', 1, 0 )

There is an empty function on row 45, which is a big No-no. The solution is to remove it or writning either return or pass under the function.

45      def CounterAttack():
46                pass

To avoid this error one should try to avoid adding function definitions in advance.


Action related bugs

Case 1 Debug Message:

[Wed Oct 24 09:47:12.562] ***************  ERROR START *************

[Wed Oct 24 09:47:12.562] wico_pythonc.cpp(210): CheckPyError(): Error 

         Exception Type:       reaction.action.BadActionException


         Exception message:  First argument is not callable. None


         Traceback( last call last ):



maps/europeTest/python\server.py   44: OnGameStarted()

maps/europeTest/python\server.py   76: Intro()

maps/europeTest/python\server.py   99: VillageSetup()

          action.py   15: __init__()


Solution: This error seem to originate in row 99 under the function VillageSetup() in server.py. That row looks like this.

RE_OnCustomEvent( 'IntroEnd', Action( VillageCam( ) ) )

After a quick glance you might think this looks correct and that the problem must lie elsewhere. But as mentioned in the action chapter a function in an Action should not have parentheses after it.

RE_OnCustomEvent( 'IntroEnd', Action( VillageCam( ) ) )

So by removing the yellow marked parenthesis’s the problem will be solved.


Juice related bugs

Case 1 Debug Message: Juice related bugs will not generate a correct debug message, but the symptom of these bugs is easy to recognize. Errors in a Juice file will often cause the game to jump to the gamemeny.


Solution: The usual errors in .juice files are caused mostly of misspellings, missing curly brackets and wrong tabs. Since the debug message wont give you a hint where to start, you have to check the functions one by one. Be systematic and check the functions one by one. Missing curly brackets will give you the biggest headache, as there are plenty of them.



Case 2 Debug Message: If you notice that different text wont show ingame, although you make a correct call for them in the python file, the problem is probably a missing quotation mark in singleplayerdata.juice.

Solution: You probably know which text that is missing, may it be a dialogue or objective description they all have a simple solution. Find the text in singleplayerdata.juice or step through all text if you are not sure which one is missing. Add the missing quotation mark or marks. The text should now be shown correctly ingame.




Group and Unit related bugs

Case 1 Debug Message:

[Wed Oct 24 17:49:18.484] ***************  ERROR START *************

[Wed Oct 24 17:49:18.484] wico_pythonc.cpp(210): CheckPyError(): Error 

         Exception Type:       group.group.GroupNameException


         Exception message:  Bad Group name (grpVillageRu1)! Group already added or hash collision. Try different groupname.


         Traceback( last call last ):



maps/europeTest/python\server.py   44: OnGameStarted()

maps/europeTest/python\server.py   76: Intro()

maps/europeTest/python\server.py  104: VillageSetup()

   serverimports.py 1193: PostEvent()

        reaction.py  164: PostEvent()

        reaction.py  779: Execute()

          action.py   95: Execute()

maps/europeTest/python\server.py 112: VillageCam()

maps/europeTest/python\allunits.py 67: Village()

   serverimports.py 2411: CreateGroup()

           group.py  150: AddGroup()


Solution: In this debug message the error has been described very well.

It says there is two groups created with identical names and that the problem arose in allunits.py, row 67 in the function Village().

There we will find these rows.


56      def Village( ):
57      DebugMessage( 'allunits.Village::' )
58      mapvars.grpVillageRu1 = CreateGroup( 'grpVillageRu1', [ USSR_BMP_3 ], 'areaVillageSpawn1', PLAYER_SCRIPT, TEAM_USSR  )
59      mapvars.grpVillageRu1.SetAttackBehavior( BHA_StandFast(  ) )
60      mapvars.grpVillageRu1.SetBaseBehavior( BHB_IdleUnits( 'areaVillageRuMove1' ) )
61      mapvars.grpVillageRu2 = CreateGroup( 'grpVillageRu1', [ USSR_TRUCK, USSR_TRUCK ], 'areaVillageSpawn2', PLAYER_SCRIPT, TEAM_USSR  )       


After a close inspection you will notice that the group created in row 58 and the one created in row 61 has the same name assigned to them. By changing the one on row 61 to 'grpVillageRu2’ the problem will be solved.


This kind of errors happens a lot when copy-pasting scripts. Be sure to check your scripts thoroughly and be extra vigilant when it comes to naming things.


Case 2 Debug Message:

[Thu Oct 25 11:38:15.109] ***************  ERROR START *************

[Thu Oct 25 11:38:15.109] wico_pythonc.cpp(210): CheckPyError(): Error 

         Exception Type:       exceptions.Exception


         Exception message:  No such unit type 583337175


         Traceback( last call last ):


maps/europeTest/python\server.py   44: OnGameStarted()

maps/europeTest/python\server.py   76: Intro()

maps/europeTest/python\server.py  104: VillageSetup()

   serverimports.py 1193: PostEvent()

        reaction.py  164: PostEvent()

        reaction.py  779: Execute()

          action.py   95: Execute()

maps/europeTest/python\server.py 112: VillageCam()

maps/europeTest/python\allunits.py 60: Village()

   serverimports.py 2411: CreateGroup()

           group.py  575: __init__()

           group.py 1221: CreateGroup()

           group.py 1340: CreateUnitsAtPosition()

Solution: The error in this case is unit related. The script is trying to create a unit that does not exist. Opening up allunits.py and going to row 60, under the function Village(), the following row were found.

60      mapvars.grpVillageRu1 = CreateGroup( 'grpVillageRu1', [ aHELICOPTER, USSR_BMP_3 ], 'areaVillageSpawn1', PLAYER_SCRIPT, TEAM_USSR  )

The units involved in this case are aHELICOPTER and USSR_BMP_3. To really see the problem we have to head on to unittypes.py and search for these units there. The search gave us these rows.

aHELICOPTER = base.StringToInt("USSR_AH_Apache")

USSR_BMP_3 = base.StringToInt("USSR_Bmp_3")


Now we have the strings to look for in the unittypes_wic_singleplayer.juice.

Opening the juice file and searching for USSR_Bmp_3 and USSR_AH_Apache shows that there is no USSR_AH_Apache. The solution is to either create a unittype named USSR_AH_Apache or to check the spelling of the string and correct it. Remember to change misspellings in the unittypes.py to.

Extra Chapter 3: The Objective Class
Personal tools
User Created Content