tags:

views:

72

answers:

1

wanted to know how to write a forward and back command in a superclass not sure but i gave it a try dont know if its right or wrong some help plz

def forward(self):
  return (self.100)

def back(self):
  return (self.50)
+1  A: 
def forward(self):
  self.position += self.distance
  return (self.position)

def back(self):
  self.position -= self.distance
  return (self.position)

EDIT: I assumed you are doing something like progress bar of install app, where some operation advances progress (copying files), and if user cancels install others operation make rollback (deleting files). Try ask a proper question as other users comment.

Michał Niklas
Also note this may not work correctly with floating point calculations. Your better of pushing and poping the float values onto a command pattern to keep the same floating point calculation accuracy.
Chad
what does the second line of code do "self.position += self.distance"
hugh
+= increases value on the left side by value on the right
Michał Niklas