Jump to content

String compare problem


ScarPunk
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

  • Thanks 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...