GetLocalPlayer() question

jrhetf4xb

Member
Reaction score
12
I just noticed something while browsing through some of my code, particularly these lines:

JASS:

        if IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS) then
            call DisplayTextToPlayer(GetLocalPlayer(), 0., 0., sc + MSG[GetRandomInt(1, 8)] + st + "!")
        endif


What I am concerned about is the [ljass]GetRandomInt(1, 8)[/ljass] part, which is in a GetLocalPlayer() block... Does that mean that it would return a different value for each player? This part of my code seems to malfunction from time to time (not showing texts for around a minute and then starting to show them again) and I was wondering if that was the cause.
 

meOme

New Member
Reaction score
31
Yes, I think it will return a different random value for each player.

But I don't think that's the problem that's causing your errors, it would just mean that each player sees a different message.

And your condition "IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)" is useless I think. Every player is in bj_FORCE_ALL_PLAYERS, so it will return true all the time.
 

meOme

New Member
Reaction score
31
That's got nothing to do with one another. oO

The condition is useless because as I said, every player is in "bj_FORCE_ALL_PLAYERS" anyway.

So this:
JASS:
if IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS) then
    call DisplayTextToPlayer(GetLocalPlayer(), 0., 0., sc + MSG[GetRandomInt(1, 8)] + st + "!")
endif

Would do exactly the same as this alone:
JASS:
call DisplayTextToPlayer(GetLocalPlayer(), 0., 0., sc + MSG[GetRandomInt(1, 8)] + st + "!")

because the if-condition will allways return true.


But I'm not so sure anymore if the players really will see different messages... Maybe they will see the same. Maybe it even depends on wether or not the if-condition is there... I am confused. @_@
 

meOme

New Member
Reaction score
31
Ah, so everything inside the if-actions-block is already local.

Then I'm sure that each player get's a different random value (and a different message) as long as the if-condition is there.

Without the if-condition, everyone should get the same message I think.
 

saw792

Is known to say things. That is all.
Reaction score
280
It's not local if it returns true for all players.The blizzard example only returns true for half the players, so that half of the players would (in your example) receive the same random number.

Regardless of that, since each player gets the same random seed at the beginning of the game I'm pretty sure the "random" number would be the same regardless of it being local or not. Try this:

JASS:
//
  loop
    exitwhen i == GetPlayerId(GetLocalPlayer())
    set r = GetRandomInt(1, 8)
    set i = i + 1
  endloop
  call DisplayTextToPlayer(GetLocalPlayer(),  0, 0, sc + MSG[r] + st + "!")
//Now both r and i and asynchronous, so don't use them again without reassigning them outside a local block of code
 

Bribe

vJass errors are legion
Reaction score
67
>> It's not local if it returns true for all players.

I recommend he tests it before accepting it as fact, but if this is true, then ignore the adjusted if-block I suggest:

JASS:
//Syntax
if GetLocalPlayer() != null then
    call DisplayTextToPlayer( GetLocalPlayer() , sc + MSG[ GetRandomInt( 0 , 7 ) ] + st + "!" )
endif

//Notes:
// Optimizations in the if-block with the lightest comparison possible,
// Arrays start at 0, not 1.  Ranging your selectables from 0 to 7 is preferred in a professional or mainstream environment.
 
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