Using Player(Integer A) in JASS

LearningCode

New Member
Reaction score
24
I'm trying to convert this TD map I have from GUI to JASS because I think it may make it faster =P
Even if it does not make it faster, I would have learned heaps from it.

And here is my first block:

JASS:

function creation takes nothing returns nothing
   local integer a
   local force b
   local location c
      loop
         exitwhen (a>8)
         set force b=a
         if (GetPlayerSlotState( b == PLAYER_SLOT_STATE_PLAYING ) then
            set location c=GetPlayerStartLocationLoc(b)
            call CreateNUnitsAtLoc(1, 'e008', b, c, bj_UNIT_FACING)
            call SelectUnitForPlayerSingle(GetLastCreatedUnit(), b)
            set location c= null
         endif
         set force b= null
         set integer a=a+1
      endloop
   
endfunction

function CreateBuilder takes nothing returns nothing
   local trigger t
   set t= CreateTrigger()
   call TriggerAddAction(t, (function creation))
endfunction


The trigger is supposed to:

1) Create a 'Worker' for each Player in the map that has its slot filled with a Controller (Not bothering about CPU or Human for now)
2) Select the Created 'Worker' for the Player

But the JASS compiler (Is it called that? I'm using NewGen 1.5d, I think) says that there is a syntax error here:

JASS:

set force b=a


And I understand why, I can't set an integer value to a force, right?
So.. how do I go about this?
 

Nestharus

o-o
Reaction score
84
[ljass]ForceAddPlayer(force, Player(id))[/ljass]

There's a bj var that contains all playing players already ><.


Also, there are a couple of player tracking utilities that do this but put them into an indexed array (better/faster than a force)

; )
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
   local force b

-->
JASS:
   local player b


JASS:
set force b=a

-->
JASS:
set b=Player(a)

^don't include the type when using set, for example, don't have the word [LJASS]force[/LJASS].
[ljass]ForceAddPlayer(force, Player(id))[/ljass]

There's a bj var that contains all playing players already ><.


Also, there are a couple of player tracking utilities that do this but put them into an indexed array (better/faster than a force)

; )
Really? ForceAddPlayer(Player(id)) is incorrect syntax, and player tracking isn't relevant - who even says he has vJass?
 

LearningCode

New Member
Reaction score
24
I don't even know what vJASS is, xD
I'm on new territory here, I started some hours ago (this morning at 3am, I think, it's 11.40am now.)

types?
sets?

o.0

I thought force was player =x

*Checking if Jesus4Lyf's fix works*

Erm..
JASS:
function creation takes nothing returns nothing
   local integer a
   local player b
   local location c
      loop
         exitwhen (a&gt;8)
         set player b=Player(a)  //---- Complaining that it&#039;s the wrong syntax again
         if (GetPlayerSlotState( b == PLAYER_SLOT_STATE_PLAYING ) then
            set location c=GetPlayerStartLocationLoc(b)
            call CreateNUnitsAtLoc(1, &#039;e008&#039;, b, c, bj_UNIT_FACING)
            call SelectUnitForPlayerSingle(GetLastCreatedUnit(), b)
            set location c= null
         endif
         set force b= null
         set integer a=a+1
      endloop
   call DestroyTrigger(t) 
   set trigger t= null
endfunction

function CreateBuilder takes nothing returns nothing
   local trigger t
   set t= CreateTrigger()
   call TriggerAddAction(t, (function creation))
endfunction


=x
 

Jesus4Lyf

Good Idea™
Reaction score
397

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
It is not force. It is player. :)
How to convert the integer into player?
JASS:
Player(someInteger) -&gt; player

Remember : Player(0) -> player 1/Player(1) -> player 2, and vice versa.

Since you are learning Jass, then go forward to learn vJass at same time. :p
JASS:
scope CreateWorker initializer Init
    
    private function Init takes nothing returns nothing
        local integer i = 0
        local player p = null
        local real x = 0.
        local real y = 0.
        local unit u = null
        loop
        exitwhen i &gt; 7
            set p = Player(i)
            if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then
                set x = GetStartLocationX(i)
                set y = GetStartLocationY(i)
                set u = CreateUnit(p,&#039;hpea&#039;,x,y,270.)
                if GetLocalPlayer() == p then
                    call ClearSelection()
                    call SelectUnit(u,true)
                endif
            endif
            set i = i + 1
        endloop
        set u = null
    endfunction

endscope
 

LearningCode

New Member
Reaction score
24
Code:
set x=GetPlayerStartLocationX(p)
set y=GetPlayerStartLocationX(p)

Does WE automatically recognize Real x as the x co-ordinates and Real y as the y co-ordinates and give it that value?

If I set:
local real x
local real y

to:
local real a
local real b

and use:
set a=GetPlayerStartLocationX(p)
set b=GetPlayerStartLocationX(p)
call SelectUnitForPlayerSingle(CreateUnit(p,'e008',a,b,bj_UNIT_FACING),p)

Will it understand? o.0
Because you use GetPlayerStartLocationX(p) twice and I'm confused =/


[EDIT]
Nevermind my rant above, it was a typo, I realized.

[Edit]

What's vJASS about? o.0
 

Nestharus

o-o
Reaction score
84
Quote:
Originally Posted by Nestharus
ForceAddPlayer(force, Player(id))

There's a bj var that contains all playing players already ><.


Also, there are a couple of player tracking utilities that do this but put them into an indexed array (better/faster than a force)

; )
Really? ForceAddPlayer(Player(id)) is incorrect syntax, and player tracking isn't relevant - who even says he has vJass?

I agree, what you wrote there is def wrong, but what I wrote is right ; )

Also, I thought he was using forces for some strange reason o-o, probably because I saw a force var in there ; ). Oh well, bad me for glancing at code for a split sec ;o.

What's vJASS about? o.0

Lots of tutorials... there's a link in this forum..
 

Jesus4Lyf

Good Idea™
Reaction score
397

LearningCode

New Member
Reaction score
24
Code:
set location c=GetPlayerStartLocationLoc(b)
Everyone here did not like me using the above code and used:

Real x
Real y

Is there a particular reason to not use it? o.0
Just asking =x
Very curious.

[Edit]
I'm already very confused as it is, I don't want vJASS to confuse me more >.<
At least not till I'm 1week through with this thing and I can code basic spells or something.
 

LearningCode

New Member
Reaction score
24
Got it.

Do I have to null Player variables?
Do they leak?

[Edit]
@ Mister-Shortest-Code-Contest

You didn't define Player 'p', I believe xD
INVALID ENTRY!!! >;(
 

Jesus4Lyf

Good Idea™
Reaction score
397
Oops.
JASS:
function creation takes nothing returns nothing
    local integer i=8
    local player p
    loop
        exitwhen i==0
        set i=i-1
        set p=Player(i)
        if GetPlayerSlotState(p)==PLAYER_SLOT_STATE_PLAYING then
            call SelectUnitForPlayerSingle(CreateUnit(p,&#039;e008&#039;,GetStartLocationX(i),GetStartLocationY(i),0),p)
        endif
    endloop
endfunction

Do I have to null Player variables?
Do they leak?
Assuming you got my other post, players are objects, but they are never destroyed, meaning their handle ("sticky note") is never removed, meaning the counter for it incrementing and not going back down doesn't matter because it won't be removed anyway. :D

>You don't create players do you ;p
Who cares? You don't necessarily create units either (they can be trained). Point is players don't get destroyed. Anything that doesn't get destroyed, or isn't an agent, doesn't need nulling. :p
 

Nestharus

o-o
Reaction score
84
The better way is-

JASS:
if GetPlayerTeam(Player(i)) != 0 then


;p

>>You don't create players do you ;p
>Who cares? You don't necessarily create units either (they can be trained). Point is players don't get destroyed.

Meant to say you don't destroy player do you ;p

Just finished an 8 hour exam a little bit ago, so I'm out of it atm ;o
 

LearningCode

New Member
Reaction score
24
That means..
They do not leak, right?

Something needs to be nulled if it has been destroyed?
But if it has not, you don't have to?

hmm..
Now I think I don't understand..
pfft.
 

Nestharus

o-o
Reaction score
84
Actually, globals don't need to be nulled. I think Blizzard was just being lazy with garbage collection on locals ; |.


Furthermore, the leaks are just from the handle ids that aren't recycled ><

By nulling it, you recycle the handle id given that you destroyed the handle.

If you don't destroy the handle, nulling it does absolutely nothing

Furthermore, all local variables that point to the given handle must be nulled in order for it's handle id to get recycled.
 

LearningCode

New Member
Reaction score
24
So I have to null every variable related to an object I want to remove from the game?

Like say.. a dummy unit?
 
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