–2 votes

This is the code I have:
$"/root/World/UI/InteractionInfoLabel".text = getcollider().getname()

It's under an interaction script and basicly sets text in the screen to the name of the thing at the end of interaction raycast. It works with single object like Shotgun it works but with things that has multiple of them like ammo boxes engine automaticly gives that node a number like Ammo Box1 or Ammo Box 2 and in label it shows that number. I wanna remove it

Godot version 3.3
in Engine by (49 points)

2 Answers

+1 vote

Unless you know in advance the length of the string you need to display (in that case you can use left() or right() method to remove the numbers), i guess you have to use something else to show it
eg use a custom "type" variable: print(raycast_collision_result.type) or using the class name of the node print(raycast_collision_result.get_class()) .

by (1,436 points)
0 votes

I believe the string rstrip function coul help here.

$"/root/World/UI/InteractionInfoLabel".text = getcollider().getname().rstrip("0123456789")

by (114 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.