Author Topic: Updating the ego instance  (Read 7028 times)

0 Members and 1 Guest are viewing this topic.

Offline Adam

Updating the ego instance
« on: November 20, 2013, 06:47:06 PM »
I am trying to rearrange and decentralize my code, and was about to update the ego instance with automatic view setting based on outfit and animation.

Here is what I added to the ego code:

Code: [Select]
(method (outfit newOutfit)
(var oldOutfit)
= oldOutfit gEgoOutfit
= gEgoOutfit newOutfit
Print("change")  //Debug
(self:setView())
return(oldOutfit)
)

(method (animation newAnimation)
(var oldAnimation )
= oldAnimation gEgoAnimation
= gEgoAnimation newAnimation
Print("change!!") //Debug
(self:setView())
return(oldAnimation)
)

(method (setView)
(switch (gEgoOutfit)
(case (OUTFIT_CLOTHES)
= view 100
)
(default
(switch (gEgoAnimation)
(case (ANIMATION_EAT) = view 8)
(default = view 0)
)
)
)
)

I try to call it like this from the room:

Code: [Select]
(if (== (send gEgo:outfit) OUTFIT_CLOTHES) Print("You are already clothed."))
(else
(if(theChest:inControlArea)
(if (== gRoom1ChestStatus DOOR_OPEN) (send gEgo:outfit(OUTFIT_CLOTHES)))
(else Print("Your adventuring outfit must be in the closed chest before you."))
)
(else Print("Your adventuring outfit should be in your chest."))
)

But sadly it does not even go into the outfit method. Any ideas why?



Offline gumby

Re: Updating the ego instance
« Reply #1 on: November 21, 2013, 06:09:41 PM »
I tested this out, it seems like it works fine.  Here's the code I used, a very simplified version using the template game:

In the User.sc script:
Code: [Select]
    (method (outfit newOutfit)
(var oldOutfit)
Print("change")  //Debug
return(oldOutfit)
    )

And in the room:
Code: [Select]
(instance RoomScript of Script
(properties)
(method (handleEvent pEvent)
           (super:handleEvent(pEvent))

           /*****************************************
            * Handle the possible said phrases here *
            *****************************************/
           (if(Said('look'))
               Print("You are in an empty room")
               (send gEgo:outfit(800))
           )
  )
)

It does go through the outfit method & I get the 'change' debug message to pop up.  Maybe there is something wrong with the preceding conditions in the 'if' statement?
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Adam

Re: Updating the ego instance
« Reply #2 on: November 21, 2013, 06:53:51 PM »
Thanks for the reply. It turned out I messed up a level under the ego instance. I forgot that I made an outfit property for the Ego class, and it catched the gEgo:outfit, not calling the outfit method of the instance.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.021 seconds with 16 queries.