473,573 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Missing member

I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):
http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

Any comments are welcome. :)

Feb 4 '07 #1
4 2443
On Feb 5, 9:45 am, "Mizipzor" <mizip...@gmail .comwrote:
I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
Line 15 is:
self.pos += (self._directio n * self.stats.spee d)
So obviously(???) self._direction is None

What does line 8 do: self._direction = vector() ???

I'd suggest adding line 8.1:

assert self._direction is not None
Any comments are welcome. :)
I doubt that you really mean that, so I have refrained from
commenting :-)

Cheers,
John

Feb 4 '07 #2
On Feb 4, 4:45 pm, "Mizipzor" <mizip...@gmail .comwrote:
I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

Any comments are welcome. :)
Here's a suggestion: use new-style classes. Have _BaseEntity inherit
from object, allows you to use super for invoking methods on super
classes. Instead of:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
_BaseEntity.__i nit__(self, type, x, y)

You enter:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
super(Entity,se lf).__init__(ty pe, x, y)

This makes it easier to update your inheritance hierarchy later. New-
style classes have other benefits too.

As for your NoneType problem, try adding "print self._direction " to
the end of _BaseElement.__ init__.

-- Paul

Feb 5 '07 #3
"Paul McGuire" typed:
Here's a suggestion: use new-style classes. Have _BaseEntity inherit
from object, allows you to use super for invoking methods on super
classes. Instead of:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
_BaseEntity.__i nit__(self, type, x, y)

You enter:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
super(Entity,se lf).__init__(ty pe, x, y)

This makes it easier to update your inheritance hierarchy later. New-
style classes have other benefits too.
I am still a beginner to Python, but reading that made me think on
impluse, "What happens in case of one class inheriting from two or more
different classes?"

Having written a small test case and testing it, I find that
super().__init_ _() calls the __init__() of the first of the class in
the list of classes from which the calling class inherits. For example:

class C(A, B):
def __init__(self):
super(C, self).__init__( )

calls A's __init__ explicity when an instance of C is instantiated. I
might be missing something. I didn't know that.

--
Ayaz Ahmed Khan

A witty saying proves nothing, but saying something pointless gets
people's attention.

Feb 5 '07 #4
Mizipzor a écrit :
I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):
http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
Alas, there's a dependency on an unknown class or function vector (which
I presume lives in the eponym module), so we just can guess that the
call to vector() at line 8 returned None. IOW, the problem is elsewhere...
Any comments are welcome. :)
You ask for it, you get it:

import pygame, math
from pygame.locals import *
=bad style
import tilemap, dataManager
from vector import *
=idem

class _BaseEntity:

=class _BaseEntity(obj ect):

def __init__(self, type, x, y):
self._direction = vector()
self.pos = vector(x,y)
self.stats = dataManager.get EntityStats(typ e)
self.hp = self.stats.maxH p # todo: make all atttributes local

def move(self):
""" moves the entity in its direction according to its speed """
self.pos += (self._directio n * self.stats.spee d)

def setDirection(se lf, point, y = None):
""" sets the direction to point, and normalises it
if y is specifed, "point" is expected to be x,
otherwise, "point" is expected to be a vector class """
# make a vector
if not y == None:
= if y is not None:
point = vector(point, y)
self._direction = point.normalise ()
#def lookAt(self, point, y = None):
# """ changes the angle so the entity "looks" at the specified
coords
# if y is specifed, "point" is expected to be x,
# otherwise, "point" is expected to be a vector class """
# # make a vector
# if not y == None:
# point = vector(point, y)

=code duplication, should be factored out

# vec = vector(point.x - self.posx, point.y - self.posy)
# vec.normalise()
#
# angle = math.degrees(ma th.asin(vec.y))
# print angle

def draw(self, targetSurface):
""" blits the entire stats.image onto the targetSurface at the
ent's coords """
targetSurface.b lit(self.stats. image, (self.pos.x,sel f.pos.y))

class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
_BaseEntity.__i nit__(self, type, x, y)

=You don't need to override the __init__ method if it's just to call
the superclass's __init__ with the same args...

(snip)
Feb 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
21373
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've tried everything... Could anyone please paste this and tell me what I'm doing wrong ? I use SerialPort.zip, which can be downloaded at...
4
2445
by: Conrad Weyns | last post by:
vc7.1 has no problem with the following snippet: template <typename T> class TTest { std::list<T*>::iterator m_It; }; but metrowerks codewarrior 9.2 kicks my butt and online Comeau confirms: 1. MW:
2
10915
by: kalpana.sinduria | last post by:
Hi all, how to remove the following complle error. When I compiling the code I get the following errors: Compiling... CDrtEachDefFeat.cpp d:\ include\common\cdrtintegfeat.h(39) : error C2143: syntax error : missing ';' before '*'
4
1529
by: Peter Olcott | last post by:
Yesterday I found that an invocation of a member function that lacked the required "()" pararenthesis did not generate an error message. This was an invocation of a member function that is part of a library so I do not have access to the source code. The compiler was MSVC++ 6.0. I can't think of any scenario that would prevent a compiler...
2
1206
by: Caladin | last post by:
I'm sure once someone answers this I'll feel really dumb. I'm a c++ programmer playing with c# an here's my conundrum I declare a class in the for public class Form1 : System.Windows.Forms.For class Class
0
1426
by: Harald Hoyer | last post by:
My application has an exe and some DLLs. During debugging only debug information of the current binary is available. For example: ============DLL: -----------------------------------------Header: class CKnownLocal; class CKnownGlobal { CKnownLocal &Member; ...
14
1818
by: tshad | last post by:
I am trying to set up a reusable library (business component) that I can use in a bunch of my pages. I built the file and it almost compiles, but I am not sure what I am missing. The vbc command and results are: ************************************************************************ C:\Inetpub\wwwroot\Development>vbc /t:library...
1
4276
by: BobPaul | last post by:
I'm following code out of a howto book and this is really bugging me. This header file was created by VStudio 6.0 when I did a "Right Click: Add Member Function" CLine is a class I wrote (per the book's instructions) and Line.h in included in Day10Doc.cpp Here is the contents of Day10Doc.h #if...
0
4212
by: RickVidallon | last post by:
Missing or Truncated Body Text in Email Application - 2 Strange Examples... There is no earthly reason why this is happening! EXAMPLES HERE: http://65.36.227.70/actmailer/ We have a scheduled task which runs every 5mins and sends pending email campaign. The script has been written in VB.NET and following is the code which
0
7781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7699
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7788
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8066
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5292
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2216
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1304
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1041
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.