alice-teacher Passing an object to a method doesn't appear to work completely in Alice 2.3.2
Marty Schultz
schultz_marty at hotmail.com
Sun Apr 14 21:48:31 EDT 2013
Does anyone have a solution for this (I've included pseudo line numbers to
make it clear):
Function world.whoGotHit (returns type OBJECT) ends with:
10 print "world.whoGotHit"
11 print tiger.name
12 return tiger
Method world.keepScore looks similar to:
20 Local variable animalThatWasHit (type=OBJECT, initial
value set to paintball)
22 animalThatWasHit set value to world.whoGotHit
23 print animalThatWasHit
24 world.whenHit target=animalThatWasHit
Method world.whenHit
30 parameter target (type=OBJECT)
32 print "world.whenHit"
33 print target
When I PLAY this program, the PRINT statements show:
world.whoGotHit (from line number 10)
tiger (from line number 11)
the value of world.keepScore.animalThatWasHit is tiger (from
line 23 - this is expected)
world.whenHit (from line 32)
the value of world.whenHit.target is paintball (from line
33- this seems WRONG - it should be "tiger")
What appears to be happening is that even though the value of
animalThatWasHit is "tiger" in the world.keepScore method, when the
world.whenHit method is called, the value reverts back to the initial value,
not the value shown in the parent (world.keepScore) method.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20130414/692c0ede/attachment.html
More information about the alice-teachers
mailing list