[LUA] ForForce() and GetEnumPlayer()

Status
Not open for further replies.

Bauf

B

Bauf

The Map I uploaded has this LUA code.
Lua:
function TestForce()
    print("Player Name: " .. GetPlayerName(GetEnumPlayer()))
end

function TestFunc()
    ForForce(GetPlayersAllies(Player(0)), TestForce())
end
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: TestFunc()
Player 1 has one ally, Player 2.
I expected to see:


"Player Name: Player 2"​


But when I run the map it only prints:


"Player Name:"​


GetEnumPlayer() isn't returning the players. Am I using ForForce() incorrectly? This seems to be the way it is supposed to work.
 

Attachments

Last edited by a moderator:
Thank you that worked. But what if the function I pass to ForForce() has parameters. For example:

Lua:
function TestForce(string)
    print(string .. GetPlayerName(GetEnumPlayer()))
end

function TestFunc()
    local text = "Hello: "
    ForForce(GetPlayersAllies(Player(0)), TestForce(text))
end

In my real code, the function i use in ForForce() needs to be passed local variables from the calling function.
 
Last edited by a moderator:
Yes that's what I'm looking for. Thanks again.

Lua:
function TestForce(player, string)
    print(string .. GetPlayerName(player))
end

function TestFunc()
    local text = "Hello: "
    ForForce(GetPlayersAllies(Player(0)), function() TestForce(GetEnumPlayer(), text) end)
end
 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top