Jass Questions.

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: How to convert color to string?

Post by Aero »

Yes, you can convert it to a string but you wouldn't get what you wanted...

PLAYER_COLOR_RED = "0" when converted to string..
PLAYER_COLOR_BLUE = "1"
PLAYER_COLOR_CYAN = "2" ...ect

Only way out is custom function
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Jass Questions.

Post by weirdone2 »

Hmm i'll just use this thread for all my jass questions lolz. Anyway i'm wondering if this has any leaks in it.

Code: Select all

local unit u1=GroupPickRandomUnit(GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h000'))
local unit u2=GroupPickRandomUnit(GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h001'))
local unit u3=GroupPickRandomUnit(GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h002'))
local unit u4=GroupPickRandomUnit(GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h003'))
Also is their a more efficient way of doing this w/o using a global or is this the best way?
HINDYhat
Senior Member
Posts: 101
Joined: June 1st, 2007, 9:05 pm

Re: Jass Questions.

Post by HINDYhat »

That leaks in groups, I think. You have to create the group as a variable, then get the random unit, then destroy the group and null the handles. It's also better not to refer to functions in blizzard.j and such.
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Jass Questions.

Post by weirdone2 »

alrite then so now i'm still wondering if ters a more efficient way cuz now I got this rofl...

Code: Select all

local group g1=GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h000')
local group g2=GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h001')
local group g3=GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h002')
local group g4=GetUnitsOfPlayerAndTypeId(Player(PLAYER_NEUTRAL_PASSIVE), 'h003')
local unit u1=GroupPickRandomUnit(g1)
local unit u2=GroupPickRandomUnit(g2)
local unit u3=GroupPickRandomUnit(g3)
local unit u4=GroupPickRandomUnit(g4)
call GroupRemoveUnit(g1,u1)
call GroupRemoveUnit(g2,u2)
call GroupRemoveUnit(g3,u3)
call GroupRemoveUnit(g4,u4)
call DestroyGroup(g1)
call DestroyGroup(g2)
call DestroyGroup(g3)
call DestroyGroup(g4)
set u1=null
set u2=null
set u3=null
set u4=null
set g1=null
set g2=null
set g3=null
set g4=null
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Jass Questions.

Post by Aero »

Tell me what you're trying to do / what you want done.

Of course there's a more efficient way but it depends on what needs doing.

However, this is probably the most efficient, effective and leak-free way of doing the above:

Code: Select all

function func takes nothing returns nothing
local integer i=1747988528
local group g=CreateGroup()
local player p=Player(15)
loop
exitwhen i>1747988532
set bj_groupEnumTypeId=i
call GroupEnumUnitsOfPlayer(g,p,filterGetUnitsOfPlayerAndTypeId)
set bj_ghoul[i-1747988428]=FirstOfGroup(g)
call GroupClear(g)
set i=i+1
endloop
call DestroyGroup(g)
set g=null
set p=null
endfunction
This will return your 4 units as:

bj_ghoul[100]
bj_ghoul[101]
bj_ghoul[102]
bj_ghoul[103]
HINDYhat
Senior Member
Posts: 101
Joined: June 1st, 2007, 9:05 pm

Re: Jass Questions.

Post by HINDYhat »

..You could reduce that code by like 9832439 lines by using local array variables + loops.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Jass Questions.

Post by Aero »

Nice timing HINDYhat, posting directly after my solution.

Rofl.
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Jass Questions.

Post by weirdone2 »

Thx aero though i'm curious how do you find out that 1747988528 = h000? And i'm just using it to move a few units every 5mins. XD

Edit: also should I null the units after im done using them or does it not matter when using the bjghoul?

Edit: Updated first post.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Jass Questions.

Post by Aero »

No, bj_ghoul is a pre-defined Blizzard.j global array that doesn't need to be nulled.

About 1747988528 = h000, it's just Blizzard's complicated integer system.
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Jass Questions.

Post by weirdone2 »

hmm, yes well could you tell me how I would go about converting it to that?