Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Phantom Errors
#1
Can anyone see anything wrong with the syntax in this code?

	def CheckClearInv(self, EntityName):
	   me=Bladex.GetEntity(EntityName)
	   inv = me.GetInventory()
	   for id in range(inv.nObjects):
	      for ob in Actions.GetListOfObjectsAt(inv,id):
	      try:
	         ent = Bladex.GetEntity(ob)
	            if ent.Kind in ("Pocima100", "Pocima200", "PocimaTodo"):
	               Actions.RemoveFromInventory (me, ent, "")
	               print "Stuck potion removed"
		  except:                 # this is line 1164 in the file
		     pass
There isn't. Big Grin It works perfectly well in a game level and has done for years.

I have used UltraEdit for about 20 years. Recently I got a new PC and upgraded to the latest version.

I copied that code into another game map and now it gives this error.....

  File "..\..\Maps\DwarfWarsII\NUFiles\AllyNPCTypes.py", line 1164
    except:
         ^
SyntaxError: invalid syntax
This is totally baffling me. Huh I make enough real errors with getting phantom ones.
This isn't the first time it has happened. NEVER with the old version of UltraEdit.

Not really asking for magic answers, but has anyone encountered this weird phenomenon???
Reply
#2
Lines 6-12 block must be indented one level, but this should raise IndentationError, so I guess glitch is when posting here. Then if you updated to latest python3 version (3.8?) print is a function, not statement like in python2. I guess that is what you worked with.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
So Sorry.... This is what it looks like.

	def CheckClearInv(self, EntityName):
		me=Bladex.GetEntity(EntityName)
		inv = me.GetInventory()
		for id in range(inv.nObjects):
			for ob in Actions.GetListOfObjectsAt(inv,id):
				try:
					ent = Bladex.GetEntity(ob)
					if ent.Kind in ("Pocima100", "Pocima200", "PocimaTodo"):
						Actions.RemoveFromInventory (me, ent, "")
						print "Stuck potion removed"
				except:                 
					pass						
I can't really update the Python. This game comes with it's own and dates from 1999.
It's a case of "If it ain't broke......."

I'm now getting instances of functions not being found in classes when they are clearly there. Dodgy
Reply
#4
(Oct-29-2019, 12:59 AM)prospero Wrote: Recently I got a new PC and upgraded to the latest version
(Oct-29-2019, 04:02 AM)prospero Wrote: I can't really update the Python. This game comes with it's own and dates from 1999.
I am confused - what exactly did you upgrade to latest version?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(Oct-29-2019, 04:50 AM)buran Wrote:
(Oct-29-2019, 12:59 AM)prospero Wrote: Recently I got a new PC and upgraded to the latest version
(Oct-29-2019, 04:02 AM)prospero Wrote: I can't really update the Python. This game comes with it's own and dates from 1999.
I am confused - what exactly did you upgrade to latest version?


The code editor UltraEdit. Smile
Reply
#6
Just to report that the Attribute Error that occurred when trying to call some functions within a class
was solved by my re-typing the entire function manually and deleting the old code. I was scrupulous in copying
it exactly. I am still none the wiser, but at least it wasn't my fault. Rolleyes
Reply
#7
(Oct-29-2019, 12:59 AM)prospero Wrote: I have used UltraEdit for about 20 years. Recently I got a new PC and upgraded to the latest version.
Maybe it's time to test something else,i remember i tired UltraEdit a long time ago.
Example VS Code from start it's free open source unlike UltraEdit,and they have put a lot resources to make Python work well in there editor.
There is no longer a discussion about 2 or 3,most use Python 3 now,
as Python 2 is dead(all most some will of course use for a long time still) in a couple of months.
Reply
#8
If there's still an issue, please share the entire error traceback.
Reply
#9
Caught another.....

def CheckNearerOpponent(EntityName):
	me=Bladex.GetEntity(EntityName) 
	x,y,z = me.Position	   
	for i in Bladex.GetEntitiesAt(x,y,z,2200):	
		ent=Bladex.GetEntity(i)
		if ent and ent.Person:
			if ent.Life>0:
				if CheckIfEnemy(ent.Name): 
					if ent.ActiveEnemy and ent.ActiveEnemy==EntityName:
						me.Data.SwitchOpponent(EntityName, ent.Name)
						return 1
						
	 	   			    #me.Data.SwitchOpponent(EntityName, ent.Name)
	 	   			    #return 1
	return 0
In the above function the commented lines cause an error.
The live lines(which I typed manually) are OK.

Traceback (innermost last):
  File "Cfg.py", line 98, in ?
    execfile("DefFuncs.py")
  File "DefFuncs.py", line 21, in ?
    import EnemyNPCTypes
  File "..\..\Maps\DwarfWarsII\NUFiles\EnemyNPCTypes.py", line 332
    me.Data.SwitchOpponent(EntityName, ent.Name)
     ^
SyntaxError: invalid syntax
** I'll try a different editor. Smile
Reply
#10
I get no error with a copy/paste into sublime text.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? GaryKuipers 4 3,173 Aug-28-2018, 02:32 PM
Last Post: GaryKuipers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020