Replace string letter by letter

Hi yall

Anyone who played or watched Transformer surely knows how text is presented right? Its kinda a bunch of “alien” letters, and each of them turns letter by letter to real english phrases ( Translator). I am planning to build this effect into my game… Still experimenting with this blend, but i am still lost.

texti_text.blend (452 KB)

thanks!


from bge import logic as log


def main(c):
    o = c.owner
    sp = c.sensors["space"]
    
    if "init" not in o:
        o["alien"] = "XXXXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXXX"  
        o["Text"] = o["alien"]
        o["init"] = True
    else:
        if sp.positive:     
            msg = "This is an alien language" 
            mlen = len(msg)  
             
            if o['counter'] < mlen :
                o['counter'] += 1
                o["Text"] = msg[0 : o['counter']]   
                #i.replace(o["Text"], '')

You guys should know at last how to fizzbuzz. Here is probably what you’re looking for: texti_text.blend (445 KB)

That said BGE is one of the worst engines out there when it comes to presenting text, consider yourself warned.


from bge import logic as log

def replaceTextWithTransformersEffect(obj):
    text = obj["Text"]
    mask = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    freq = 3
    
    def effect():
        effect.c += 1
        if effect.c%freq == 0:
            c = int(effect.c/freq)
            obj["Text"] = text[:c] + mask[c:len(text)]
        if effect.c > len(text)*freq: obj.scene.post_draw.remove(effect)
            
    effect.c = 0    
    obj["Text"] = mask[:len(text)]
    obj.scene.post_draw.append(effect)    

def main(cont):
    own = cont.owner
    own["Text"] = "This is an alien message."
    replaceTextWithTransformersEffect(own)

wow it looks cute! thank you @elmeunick9

I made this because it sounded fun :smiley:

Attachments

NotLostInTranslation.blend (479 KB)

O.O weeeeee, cool!

@@elmeunick9
Why did you feel the need to throw it in a post-render callback? His original code looks to be driven by an always pulse sensor.

On a side note: It seems to me that you’re trying to use another game engines programming paradims when using the BGE.
I’ve done this in the past, but have since discovered it is often easier to find out how an engine is intended to be programmed and run with that.

@Rockymadio
I believe the simplest change to your code to make it work is all of one line different:


from bge import logic as log


def main(c):
    o = c.owner
    sp = c.sensors["space"]
    
    if "init" not in o:
        o["alien"] = "XXXXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXXX"  
        o["Text"] = o["alien"]
        o["init"] = True
    else:
        if sp.positive:     
            msg = "This is an alien language" 
            mlen = len(msg)  
             
            if o['counter'] < mlen :
                o['counter'] += 1
                o["Text"] = msg[:o['counter']] +  o["alien"][o['counter']:]

Just in case, here’s the logic bricks to support it:

Attachments


thanks sdfgeoff ^.^ it works too

here is a cool texture of a font i made years back. though u might like it.

http://www.mediafire.com/download/ulag6nnrpmm25e7/text2.blend

Attachments