text, using courser

hi,

another question again:

is it possible to use an text courser like the blinking little line “|”
and how can I develop that at an text object?
At the moment I use this extra char “_” at the end

What you could do is have a delay sensor connected to a python script. The delay could be like ~60 with Repeat enabled. The script then checks the last character of the text. This can be done with

lastChar = own.text[-1]

if the lastChar is not a ‘|’ character, add a cursor with:

own.text += '|'

otherwise, delete it with:

own.text = own.text[:-1]

that means there is no in-build function?

how to time it safely right if some input is done that not the raw input text is effected by an leaving “|” ?
without checking if there an “|” or if not?

You could have another script that deletes the | after the user is done typing

or

have another text object above the actual text object. Use a monospaced font. The text object on top will be the cursor and the one on the bottom will be the actual text entered by the user. Then on the cursor text object, the text on top, get the number of characters of the text entered by the user and make the cursor text be

own.text = ' '*numChars

what that does is set the cursor text to white space * the number of letters in the user-entered text. Then use what I said in the first post to cycle through adding and removing the pipe symbol (’|’).

Create a custom font with a cursor character in an unused spot (eg 0x07 - originally used for the bell on a teletype). Now you can easily manipulate it (ie append and remove it without fearing you will remove some text)! You can also make the character zero-width so you can place it in the middle of the text without it doing funny things.

its easy in python:

(pseudo code)  the game property ["ENTRY"] stores the typed characters

OWNER = textObject

if OWNER["EDIT"] == True:
    OWNER["BLINK"] += 1

    if OWNER["BLINK"] < 5:
        TEXT = OWNER["ENTRY"]+"_"
    else:
        TEXT = OWNER["ENTRY"]

    if OWNER["BLINK"] == 10:
        OWNER["BLINK"] = 0

else:
    OWENR["BLINK"] = 0
    TEXT = OWNER["ENTRY"]

OWNER.text = TEXT

here is a example blend
it got a blinking cursor

http://15b.dk/blendfiles/textinput.blend

sorry for long time to response,

@sdfgeoff
if I understand it right I can use that as an character and can test for if some in the “raw Input Text” or not?

@Daedalus_MDW
no that wouldn’t work, because I have some clipboard functions in like mask all, copy, past, delete all (strg+A, strg+C, strg+V, strg+X)

@edderkop
possible to move courser (arrow- left /right) in-line between and edit at specific point and if finished join text together?

possible to move courser (arrow- left /right) in-line between and edit at specific point and if finished join text together?

thats probable going to be problematic to do.

because you have to know:
-in which position the courser is
-how long the input is

and you have to avoid what sdfgeoff says that the text goes crazy by adding inline an char because of the wide of each

i got curious to see if i could make it work and here is the result
it is not perfect but it works (mostly)

http://15b.dk/blendfiles/textinput1.blend

no copy and paste

mh to change on char to toggle with the courser seams to be one way.

ps: any other free character in usually fonts? maybe I want to add the courser zero wide space char and toggle them with an empty zero wide space to detect these and replace them safely

sdfgeoff says that the text goes crazy by adding inline an char because of the wide of each

Hence the modify the font.

For example in Fontforge you can select a glyph and:


Set it to zero:

Now your cursor object won’t move the other text so you can ‘blink’ it anywhere in the text object:

Blend file (blinking only, not editing):
blink.zip (74.3 KB)
Arrow keys to move cursor

That looks very good.

@sdfgeoff

I would prefer this lines:

cursor_markers = {True:"|", False:" "} **

marker = cursor_markers.get(blink)

own.text = te[: pos] + marker + te[pos:]

** here I wanna add the second zero space char like an zero spaced “wide space” and later pop it out

so can I safely say there is no marker in

You could do:


cursor_markers = {True:"|", False:""}

Also, I’d suggest not using “|”, but as I mentioned before, picking a non-standard character.

Have you ever thought about that the visible string is not the necessarily the entered string?

I mean the user enters:

Hello world

But the game shows:

Hello world|

This way you never need to worry about removing the cursor character as you have the final text already. You format the “cursored” text out of it:

input text + cursor => cursored text

Indeed when entering characters you need to manipulate the input string at the right position.

After any change to input text or cursor (left right move, and blinking!) you recreate the cursored text.

that is an point I don’t have thinking of. But it makes sense

thats the way i did it in my example

Yes that is my fault I did not realize that sorry.