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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top