Hello.
I have a bug in my code where after a short automatic sequence, the game is restored back to the player and the gEgo is once again controllable. However, the issue is that when I give control back to the player, the first movement of the gEgo moonwalks if certain conditions are met (by "conditions" I mean the gEgo is facing east and the player clicks west or vice versa).
The sequence is a series of change states to pick up a hen.
Here is what I'm trying to achieve with my code in English (there are two actors: 1) gEgo and 2) hen):
- Remove control from player
- Halt the hen's movement
- Swap out the view of gEgo with a different view where the gEgo bends down and then stands up (ie. pick something up)
- Set the cel of gEgo to 0 so the "pick up" loop will animate from the beginning
- Set the speed of the gEgo to slow down the "pick up" animation
- Based on if gEgo is to the right or left of the hen, set the "pick up" loop of the gEgo correctly (ie. facing west or east, respectively)
- Set the cycle of the gEgo to "bend down"
- Animate the "bend down" cycle
- Dispose the hen
- Put the hen in the gEgo's inventory
- Set the cel of gEgo to 0 so the "stand up" loop with animation from the beginning
- Set the loop of the gEgo to be the "stand up" loop of the "pick up" view
- Set the cycle of the gEgo to "stand up"
- Animate the "stand up" cycle
- Give control back to the player
- Set the view of gEgo to be the normal movement view (ie. up, down, right, left, diagonals, idle)
- Set the speed of the gEgo to what is was before the "pick up" sequence
- Set the cycle of the gEgo to be StopWalk so the gEgo will cycle correctly after the "pick up" sequence
- Give control back to the player
- Set the script back to the general RoomScript
I think my bug is how I'm setting the cycle of the gEgo once the "pick up" animation is complete. Since I set it to StopWalk -1, I it will also set the direction. But since the gEgo is not moving it picks the wrong idle cel. Then when I move the gEgo, the direction is wrong because I did not change the gEgo's cycle and direction correctly.
I would also take other suggestions to make the code cleaner. I'm learning the syntax and the many methods and procedures available. Callout if you see a better way to write what I've described.
(instance getHen of Script
(properties)
(method (changeState newState &tmp newSpeed)
(= state newState)
(switchto state
(
(gGame handsOff:)
(hen setMotion: NULL)
(self cue:)
)
(
(= newSpeed gGEgoMoveSpeed)
(gEgo view: ROSELLA_PEASANT_PICKUP_VIEW setCel: 0 setSpeed: (+ newSpeed 2))
(if (<= (gEgo x?) (hen x?))
(gEgo setLoop: 0)
else
(gEgo setLoop: 2)
)
(self cue:)
)
(
(gEgo setCycle: EndLoop self)
)
(
(hen dispose:)
(gEgo get: INV_HEN setCel: 0 setLoop: (+ (gEgo loop?) 1))
(self cue:)
)
(
(gEgo setCycle: EndLoop self)
)
(
(DebugPrint {gGEgoMoveSpeed: %d} gGEgoMoveSpeed)
(gEgo view: ROSELLA_PEASANT_VIEW setSpeed: gGEgoMoveSpeed)
(self cue:)
)
(
(gEgo setCycle: StopWalk -1)
(self cue:)
)
(
(gGame handsOn:)
(rm1701 setScript: RoomScript)
)
)
)
)
Thanks
(I just thought of something.... Perhaps I can have another Actor in the script called "gEgoPickup". This Actor would have the "pick up" view. When the "pick up" sequence begins, I would hide the gEgo, show the gEgoPickup using the x,y of gEgo, animate the "pick up" cycle, hide the gEgoPickup, and then show the gEgo. I'll test this out to see if it works, but I'd think this less ideal than simply acting on the gEgo)