Coding Tip #10
Wow, talk about a large hiatus, huh? Let’s say you want to make a character (girl1) follow a hero (hero_1) every 10 seconds? How, exactly, would you set that up? Well, here’s a sample code that’ll do just that. Follow along:
1. Set up the timer.
In this example, I’m going to put the timer under OnPostInit.
def OnPostInit():
print 'Timer is set'
regTimer('followme', 10)
2. Define the event regTimer calls.
I made an event named “followme.”
def followme(event):
print 'testing'
follower = 'girl1'
position = Get_ObjectPos('hero_1')
addMoveGoal(follower, position, priority = ai.goal.PRI_HI, fn = 'stay')
The term “follower” in the preceding code is a “variable,” as is “position.” [A]ddMoveGoal is the piece of code to pay attention to here. This code will initiate a move command for the character labeled “follower” and have him/her move to hero_1′s old position. It will then call a function named “stay” once the movement is complete.
3. Make the character stay in place
def stay(event):
print 'stay'
follower = 'girl1'
addStayGoal(follower, priority = ai.goal.PRI_MED)
OnPostInit()
More of the same. The code will find the character labeled as “follower” and then make him stay in his current location. OnPostInit() will then be called and a loop is effectively formed.
Here’s the above code in action with obvious modifications:




