Jump to content

Recommended Posts

Posted

Hello every one !

So today i am making my third person code.

In my code i need to compare the name of child i want and the name of each children(GetChildren())

but i have got this error. when i try to compare their name.

 

CODE:


function Script:GetChildByName(nameRequest)
    
    for i = 0 , self.entity:CountChildren() -1 do
        local ent = self.entity:GetChild(i)
        local entName = ent:GetKeyValue("name")

        if entName == nameRequest then
            System:Print(nameRequest  + " has been found !")
            return ent
        end
    end
    return nil

end

luaStrCMP.PNG.f43ad8995cca5f9aed480af152d9dd54.PNG

ART

CODE

SOUND

Posted
4 minutes ago, macklebee said:

The error tells you exactly the problem. You are trying to mathematically add something to a string in lua. In lua, concatenation is two periods not a plus sign. So your code should look like this:


System:Print(nameRequest.." has been found !")

https://www.lua.org/pil/3.4.html

I was looking for the condition not for the print ?‍♂️

 

Thanks

macklebee

ART

CODE

SOUND

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...