Computer Science Canada calling classes from other classes |
| Author: | rollerdude [ Tue Feb 20, 2007 9:40 am ] |
| Post subject: | calling classes from other classes |
well, we are trying to make a b-western script generator and i have set up actor classes and i need to call one class from the other... the badguy needs to threaten the goodguy/another actor but don't know what to write when calling the "beThreatenedBy" procedure... you'll see setscreen ("nocursor,noecho,nobuttonbar,Graphics:500;500") class actor export beShotBy, beThreatenedBy, initialize, myName, emotion, talk, status var emotion, myName, status : string proc beShotBy (anActor : ^actor) put "BANG!" put myName, ":", "OW! That hurts!!!" emotion := "pain" status := "dead" end beShotBy proc beThreatenedBy (anActor : ^actor) emotion := "frightened" put myName, ":Uh-oh...please don't be hurting me ", anActor -> myName, "." end beThreatenedBy proc initialize (aString : string) myName := aString emotion := "calm" status := "alive" end initialize proc talk (whatToSay : string) put myName, ":", whatToSay end talk end actor class goodguy inherit actor export sixShooter var sixShooter : int := 6 body proc beShotBy (anActor : ^actor) put "BANG!" put myName, ":", "Ha! You just skinned me, ", anActor -> myName, "!" emotion := "mild pain" status := "alive" if sixShooter >= 0 then put myName, ":", "Now my turn to shoot at you, ", anActor -> myName, "!" sixShooter -= 1 anActor -> beShotBy(goodguy) else put myName, ":", "Damn... Outta bullets." end if end beShotBy body proc beThreatenedBy (anActor : ^actor) emotion := "utter disregard" put myName, ": Ha! You don't scare me, ", anActor -> myName, "!" end beThreatenedBy end goodguy class badguy inherit actor export sixShooter, threaten var sixShooter : int := 6 body proc beShotBy (anActor : ^actor) put "BANG!" put myName, ":", "Ha! You just skinned me, ", anActor -> myName, "!" emotion := "mild pain" status := "alive" if sixShooter >= 0 then put myName, ":", "Now my turn to shoot at you, ", anActor -> myName, "!" sixShooter -= 1 anActor -> beShotBy(badguy) else put myName, ":", "Damn... Outta bullets." end if end beShotBy body proc beThreatenedBy (anActor : ^actor) emotion := "utter disregard" put myName, ": Ha! You don't scare me, ", anActor -> myName, "!" end beThreatenedBy proc threaten (anActor : ^actor) anActor -> beThreatenedBy (badguy) end threaten end badguy var genericActor1 : ^actor new genericActor1 genericActor1 -> initialize ("Bob") genericActor1 -> talk ("I am " + genericActor1 -> myName) |
|
| Author: | rollerdude [ Tue Feb 20, 2007 9:43 am ] |
| Post subject: | Re: calling classes from other classes |
oops... never mind... teacher helped.... although any other input would be nice |
|
| Author: | Clayton [ Tue Feb 20, 2007 3:50 pm ] |
| Post subject: | Re: calling classes from other classes |
Probably shouldn't have copied Mr. Sales' code directly then eh? looks like what you did was right, so I don't know what was causing the error, unless you updated it since you got help. |
|