SCAR/LUA help needed

#1
1 year ago
JLXJLX Ottawa, CanadaPosts: 28

I have a game mode mod with the following in a .scar file:

local function MyFunction_OnInit()
    for i = 1, World_GetPlayerCount() do
        local player = World_GetPlayerAt(i)
        local playername = Player_GetDisplayName(player)
        UI_SystemMessageShow(playername)            -- This displays playername correctly
        if playername=="SomePlayerName" then        -- This never evaluates to true...
            DoStuff()                           -- ...so, this is never executed
            ...
        end
    end
end

Scar_AddInit(MyFunction_OnInit)

I'm new to LUA but see that Player_GetDisplayName() returns a LocString while I assume that "somePlayerName" is a regular String. Is there a type issue? I tried tostring(playername) == "SomePlayerName" but that didn't work either.

What am I missing?

Comments

  • #2
    11 months ago
    eliw00deliw00d Posts: 1,086
    edited June 2017

    Unfortunately Lua's tostring won't work for this. You just have to access the part of the LocString that has a string, like so:

    local playername = Player_GetDisplayName(player)[1]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

  • © SEGA. SEGA, the SEGA logo, Relic Entertainment, the Relic Entertainment logo, Company of Heroes and the Company of Heroes logo are either trademarks or registered trademarks of SEGA Holdings Co., Ltd. or its affiliates. All rights reserved. SEGA is registered in the US Patent and Trademark Office. All other trademarks are the property of their respective owners.