For example, I have this dialogue box in my game where you can see the symbol “@”.
I’d love to somehow find its world location so I can spawn an icon over the symbol.
def letterloc(cont):
own = cont.owner
letter_loc = own.scene.objects['letter_name_here'].worldPosition
if letter_loc:
return str(letter_loc)
else:
print('something is wrong with letter_loc!!!')
Thank you for your answer.
As I understand from your reply, this would find the location of the text object.
But do I have to know when the @ symbol appears?
Is there something that would automatically find the @ symbol or its number in the text?
text objects have limited functionality, and one way to get around it is to split op you text and have “option 1” as one text object and “@ - 10” as a second text object, this way the @ is the first letter and the position would be the same as the text object.
True, that would work.
The thing is that I have it coded that Option 1 and the second line of Option 2 are the same text object.
I didn’t want to add too many of those if I didn’t have to.
I guess I’ll have to find another way.
No no in this case it’s just a placeholder text for something different.
All I wanted to say is that these two options which can be anything are a part of one text object.
Also, the text_obj what exactly is this definition for? The only thing that worked was with the Text object’s string property.
And what does it do? I’ve tried it and it wouldn’t do anything.
I’m sure I’ve messed up somewhere.
“letter_name_here” - put in the name of the object you want the position from
text_obj.replace('@', location)
text_obj = the text that need to replace the @ with the letter_loc
so it would be something like this:
def letterloc(cont):
own = cont.owner
letter_loc = own.scene.objects['letter_name_here'].worldPosition
if letter_loc:
return str(letter_loc)
else:
print('something is wrong with letter_loc!!!')
def change_text(cont):
own = cont.owner
location = letter_loc(cont)
text_obj = own.scene.objects['text_object_name']['Text'] OR own['Text'] #delete one and the OR, Text is for the text property if script is on an other object use the first part
text_obj.replace('@', location)
run the script on the object with python brick set to module mode and enter the “scriptname.change_text” (without quotes).
I see, there might have been a misunderstanding.
The ‘@’ symbol is part of the text string of ‘OPTION 1 @ - 10’.
It’s not alone as one symbol in the string. So this doesn’t work.
Maybe what I’ve wanted cannot be done.
I wanted to know if you can locate the ‘@’ symbol in a string of text and find out its world location.
The world location of the letter in a text and not the text object.
It might be impossible.
It’s alright, thanks anyway.
I’ve made a different method. I have used the len() to calculate how many symbols are there and moved the icon based on that.