0 votes

I need to look through the groups on an object (target) for if there's one that ends with Floor, and then if there is, take its name and remove that Floor part. As seen in the code bellow, i have every part of that done except the part that finds that group in the array. Ive looked anywhere i could think of for a way to do so, but no result. Anyone know a solution? Also there wont be any objects with multiple groups ending in Floor so that doesnt need acounting for.

var ItemGroups = target.get_groups()
var ItemFloor = ItemGroups.find(~ending with "Floor"~)
var ItemHeld = ItemFloor.trim_suffix("Floor")
Godot version 3.5stable.official
in Engine by (14 points)

Could you iterate through the elements in the group, checking each element for the ending string?

for item in ItemGroups:
    if item is String and item.ends_with("Floor"):
        var ItemHeld = ItemFloor.trim_suffix("Floor")

This worked, Thanks!

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.