• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[LUA] ForForce() and GetEnumPlayer()

Status
Not open for further replies.
Level 2
Joined
Oct 1, 2009
Messages
4
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

  • TestMap.w3m
    6.4 KB · Views: 33
Last edited:
Level 2
Joined
Oct 1, 2009
Messages
4
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:
Level 2
Joined
Oct 1, 2009
Messages
4
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:
Status
Not open for further replies.
Top