GetPlayers() not working

zon3d

New Member
Reaction score
0
Wherever I use the GetPlayers() command in my JASS script for my map, it seems to always cause an error on that line: "Expected a code statement."

Why is that coming up when I'm using GetPlayers() like this:

JASS:
local integer asdfasdfPlayers = GetPlayers()


Thanks.
 

Hatebreeder

So many apples
Reaction score
381
I have never seen someone use this native...

Whats it supposed to do?

As for the solution of your problem: You need some arguments, I suppose
 

Crusher

You can change this now in User CP.
Reaction score
121
Perhaps you should use Player Number of triggering player and convert it to JASS.

:)
 

BlackRose

Forum User
Reaction score
239
I have never seen someone use this native...

Whats it supposed to do?

As for the solution of your problem: You need some arguments, I suppose

It counts how many players there are in the map, I think o.o?
[ljass]native GetPlayers takes nothing returns integer[/ljass]

Just tried: [ljass]call BJDebugMsg( I2S( GetPlayers() ) )[/ljass] in Singleplayer and it returned one! Hooray :)

It takes no arguments.

Perhaps you should use Player Number of triggering player and convert it to JASS.

:)

Why would you? He is not checking the player ID, he is checking why won't the function work. And'

Why are you telling him to use;
JASS:
function GetConvertedPlayerId takes player whichPlayer returns integer
    return GetPlayerId(whichPlayer) + 1
endfunction


What will this solve?
 

cryowraith

New Member
Reaction score
7
I can use it fine though I'm not really sure what it returns. I think it returns the number of players that are allowed to join the map? I'm pretty sure it doesnt return the number of players currently in the game though.
 

zon3d

New Member
Reaction score
0
I can use it fine though I'm not really sure what it returns. I think it returns the number of players that are allowed to join the map? I'm pretty sure it doesnt return the number of players currently in the game though.

It's supposed to return the number of players currently in the game. Or is there another way to achieve this?

Thank you.
 

cryowraith

New Member
Reaction score
7
What I did was

JASS:
set i = 0
set j = 0
        
        loop
            exitwhen (i >= 12)
            if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
                set j = j + 1
            endif
            set i = i + 1
        endloop


GetPlayers() returns the number of players allowed in the map. I tested it. I was the only player but my map allows maximum of 12 players at a time. GetPlayers() returned 12. There you have it.

If you want human players only then you will need to check slot controller as well.
 

zon3d

New Member
Reaction score
0
But what about the amount of players currently in the game playing?

Or is there a way to find out how many players currently on opposing team?
 

cryowraith

New Member
Reaction score
7


This line checks whether Player(i) is still playing or not. If he has left the game or there were no players to begin with, it returns false.

I'm not sure whether there are any natives that would return number of players currently in the game though.

If you are want to check for players on opposing/allied team you will have to loop through players in the force/player group.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Wherever I use the GetPlayers() command in my JASS script for my map, it seems to always cause an error on that line: "Expected a code statement."
Post the code, the whole code, and nothing b... well, a problem description is nice.
I have a hunch you're trying to declare locals mid-function.
 

zon3d

New Member
Reaction score
0
Thank you very much, cryowraith. I'll give that a try.

I have a hunch you're trying to declare locals mid-function.

I am. Can't variables be set within a function?

I just tested it with "call DisplayTimedTextToForce(GetPlayersAll(),10.00,I2S(GetPlayers()))" and it worked. It seems GetPlayers() does display the total amount of players allowed in the map, not the amount currently in game. I will give cryowraith's solution a try to get amount of players currently in game and let you know how it goes.

Thanks for your help guys. :)
 

cryowraith

New Member
Reaction score
7
I am. Can't variables be set within a function?

You can and you can't. Variables can only be created at the starting of a function. So all variable declaration must be at the top of the function, before any other things you want to do.

JASS:
local unit u = GetTriggerUnit()  //This is fine

call SomeFunction()

local integer i = 0 //This gives error

...
 

Laiev

Hey Listen!!
Reaction score
188
[ljass]local[/ljass] things can just be used at top of function :p

like this:

JASS:
local unit u = GetTriggerUnit()  //This is fine
local integer i = 0 //or some value what you want...
call SomeFunction()

set i = 0
 

zon3d

New Member
Reaction score
0
Thanks guys, the loop script from cryowraith worked.

One other question though, how do I round a number to its nearest whole number?

EDIT: I think I found a solution: R2I(realnum) converts from real to integer, and thus incorporates rounding.
 

Nestharus

o-o
Reaction score
84
I know I'm a little late in pointing these things out but-

This-
http://www.blizzvault.com/forum/showthread.php?t=84

Will handle your player needs and uses better methods than what people have posted up : ).


I saw you wanted team counts as well, then you use GetPlayerTeam() for that to determine which team they are on. The id it returns is actually the team they are on in the lobby.


Now if that's not enough for you (in-game teams, changing teams, etc)-
http://www.thehelper.net/forums/showthread.php?t=142712

That's in cJASS, but it will do teams for you that can easily be managed and is faster to use than forces or GetPlayerTeam after it's done its ini.

I really suggest using GetPlayerTeam though as it sounds like that's what you really need.

Furthermore, if there is no player in the slot (computer or human), GetPlayerTeam will return -1. It also happens to be faster than GetPlayerSlotState.. ;p

But yea, I believe that PlayerTracker is essential to virtually all maps, so I really just suggest you use that instead.
 

Laiev

Hey Listen!!
Reaction score
188
R2I() truncates, it doesnt round.
JASS:
function Round takes real r returns real
  return I2R(R2I(r + 0.5))
endfunction

why you do this:

[ljass]return I2R(R2I(r + 0.5))[/ljass]

you convert integer to real then convert real to integer... so we back to the start point :nuts:
 

Nestharus

o-o
Reaction score
84
>you convert integer to real then convert real to integer... so we back to the start point

that's wrong... it actually rounds and returns the answer as a real although the answer should be as an integer since it's rounded....

[ljass]return R2I(r + 0.5)[/ljass]
 

saw792

Is known to say things. That is all.
Reaction score
280
He wanted to round a real. He didnt say he wanted an integer. It's not the same thing. If he wants an integer it's a simple change.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top