ActorCopy

I have two questions actually.

Is it possible to copy an actor just as is done with a model (loader.loadModelCopy("")?

I thought this code should work, but it isn’t.

            if self.playSeq.getT() > 0.5 and self.playSeq.getT() <  2:
                self.line["text"] = "This"
            elif self.playSeq.getT() > 2 and self.playSeq.getT() <  5:
                self.line["text"] = "is a"
            elif self.playSeq.getT() > 5 and self.playSeq.getT() <  10:
                self.line["text"] = "test"

I want to change a text gradually during an interval. The code is in a running task so that it updates. Is something wrong with the code?

  1. Yes, in fact this is the default behavior. Actor(“model.egg”) will load the model from disk the first time, and then load it from memory for subsequent times. In fact, loader.loadModel() behaves this way too. loader.loadModelCopy() is deprecated and should no longer be used, since this is now the default behavior for all loader.loadModel() calls.

  2. I don’t see anything wrong, though it’s possible you’ll skip over some of those functions if your frame rate is very low, but why not do it this way:

Sequence(Wait(0.5), Func(self.line.__setitem__, 'text', 'This'),
   Wait(1.5), Func(self.line.__setitem__, 'text', 'is a'),
   Wait(3), Func(self.line.__setitem__, 'text', 'test'))

Seems a little cleaner to keep it all within the interval system.

David

Whoaaa big fella.
This is great! I just want to be sure I understand you clearly.

Actor(“model.egg”) will load the model from disk the first time, and then load it from memory for subsequent times.

Got that covered.

loader.loadModel() behaves this way too.

I no longer need to use loader.loadModelCopy().
Am I right?

Sequence(Wait(0.5), Func(self.line.setitem, ‘text’, ‘This’),
Wait(1.5), Func(self.line.setitem, ‘text’, ‘is a’),
Wait(3), Func(self.line.setitem, ‘text’, ‘test’))

Thanks for this. I never saw that code before.
self.line.setitem, ‘text’, ‘test’
Where can I find info on this?

Thanks much.
[/quote]

Right. The only reason we still have loadModelCopy() at all is to support old code that’s calling it. Eventually, we will remove this function, since it’s not needed anymore.

This is the Function interval, with three parameters: the function to be called, and its two arguments. So when this Function interval runs, it will call the function self.line.setitem(‘text’, ‘test’), which is just another way of saying self.line[‘text’] = ‘test’. In fact, Python changes this assignment statement into the function call internally when it executes it. Thus, when this Function interval executes, it will execute the statement self.line[‘text’] = ‘test’.

If you didn’t know about the sneaky Python rewriting, or don’t like it, you could also do the same thing with a lambda:

Func(lambda: self.line.__setitem__['text'] = 'test')

Or with a plain old named function:

def setLineText(self, text):
    self.line.__setitem__['text'] = text
...
Func(self.setLineText, 'test')

David

Hey… I’m not complaining.
It works.
That’s fine with me.
Infact it’s just one line, which is quite simple.

I just wanted to know where I could find infomation on that ‘setitem’ thingy. I like to read up on things. I get a better understanding that way.

I find the manual very helpful. Which reminds me…
I was reading up on HeightfieldTesselator in the manual, but there isn’t much infomation to get me started. Has anyone been using it? How can I get started using it?