HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Jass func

01-05-2007, 09:43 PM#1
Feroc1ty
hey im a total newb at jass but pretty good at gui, and tried to create my first jass func.

Collapse JASS:
function Kill2 takes nothing returns boolean
    if ( not ( GetTerrainTypeBJ(p[GetForLoopIndexA()]) == 'Lgrd' ) ) then
        return false
    endif
    return true
endfunction

function Kill takes nothing returns nothing
    local point array p
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set p[GetConvertedPlayerId(ConvertedPlayer(GetForLoopIndexA()))] = GetUnitLoc(udg_Unit[GetForLoopIndexA()])
        if ( Kill2() ) then
            call KillUnit( udg_Unit[GetForLoopIndexA()] )
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

Help ME!!
01-05-2007, 10:06 PM#2
oNdizZ
usually, it's good to say what doesnt work, and how you want it to work. but since this isn't any advanced i'd start and say that you should get an error msg due to your "local point array p" change point to location and you'll get rid of that one.

edit: now, some advantages with jass is the easy use of locals so instead of using the bjglobals use a local integer instead:

Collapse JASS:
function Kill takes nothing returns nothing
    local location array p
    local integer i = 1
    loop
        exitwhen i > 10
        set p[GetConvertedPlayerId(ConvertedPlayer(i))] = GetUnitLoc(udg_Unit[i])
        if ( Kill2() ) then
            call KillUnit( udg_Unit[i] )
        else
        endif
        set i = i + 1
    endloop
endfunction

now of course, the Kill2() boolean func won't work since you aren't using the global anymore, but since you can insert that function into your Kill function, you wont have to worry:

Collapse JASS:
function Kill takes nothing returns nothing
    local location array p
    local integer i = 1
    loop
        exitwhen i > 10
        set p[GetConvertedPlayerId(ConvertedPlayer(i))] = GetUnitLoc(udg_Unit[i])
        if GetTerrainTypeBJ(p[i]) == 'Lgrd' then
            call KillUnit( udg_Unit[i] )
        else
        endif
        set i = i + 1
    endloop
endfunction

and now for some cleanups, that location array is quite useless, and you'll also leak 10 locations, so:

Collapse JASS:
function Kill takes nothing returns nothing
    local location p
    local integer i = 1
    loop
        exitwhen i > 10
        set p = GetUnitLoc(udg_Unit[i])
        if GetTerrainTypeBJ(p) == 'Lgrd' then
            call KillUnit( udg_Unit[i] )
        else
        call RemoveLocation(p)
        endif
        set i = i + 1
    endloop
    set p = null
endfunction

and for the final part, since you prolly use this quite often considering what it does, you can get rid of the BJ function and optimize it a bit more:

Collapse JASS:
function Kill takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > 10
        if GetTerrainType(GetUnitX(udg_Unit[i]),GetUnitY(udg_Unit[i])) == 'Lgrd' then
            call KillUnit( udg_Unit[i] )
        else
        endif
        set i = i + 1
    endloop
endfunction

that should fix it
01-05-2007, 10:13 PM#3
Joker
1st of all, theres nothing called a "point" in jass, its either a location or a rect
01-05-2007, 10:15 PM#4
wyrmlord
Quote:
Originally Posted by Jokes-On-You
hey im a total newb at jass but pretty good at gui, and tried to create my first jass func.

Collapse JASS:
function Kill2 takes nothing returns boolean
    if ( not ( GetTerrainTypeBJ(p[GetForLoopIndexA()]) == 'Lgrd' ) ) then
        return false
    endif
    return true
endfunction

function Kill takes nothing returns nothing
    local point array p
    set bj_forLoopAIndex = 1
    loop
        exitwhen i > 10
        set p[GetConvertedPlayerId(ConvertedPlayer(GetForLoopIndexA()))] = GetUnitLoc(udg_Unit[GetForLoopIndexA()])
        if ( Kill2() ) then
            call KillUnit( udg_Unit[GetForLoopIndexA()] )
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

Help ME!!

I suggest putting everything into a single function. Also, you cannot refer to variables in the Kill function from the Kill2 function, and definitely not arrays.

Collapse JASS:
function Kill takes nothing returns nothing
    local location p
    local intger i = 1
    loop
        exitwhen i > 10
        set p = GetUnitLoc(udg_Unit[i])
        if GetTerrainTypeBJ(p) == 'Lgrd' then
            call KillUnit( udg_Unit[i] )
        endif
        call RemoveLocation(p)
        set i = i + 1
    endloop
 set p = null
endfunction

Things highlighted in red are major changes to the code I made that you should take note of. The other highlighting (barely visible) are changes that are recommended, but aren't necessary.

EDIT: Seems ondizz beat me to it.
01-05-2007, 10:19 PM#5
oNdizZ
Quote:
Originally Posted by wyrmlord
...Also, you cannot refer to variables in the Kill function from the Kill2 function, and definitely not arrays.
...

unless they are globals, which bj_forLoopAIndex is, the local wont work though.

Quote:
Originally Posted by wyrmlord
EDIT: Seems ondizz beat me to it.

edit: the trick is to post some small notation and then edit ;)
01-05-2007, 11:37 PM#6
Anopob
Wow, I'm slow. But I think his trigger is like checking each unit's point, killing it if it's terrain type, meaning it's a maze. I do my maze like this too...except in GUI, or atleast did it last time.

Anyways, if you're going to use 2 functions, not one, use (as your condition): "return [condition]" It's suppose to be faster than the long and useless if statements.
01-06-2007, 01:22 AM#7
Feroc1ty
thank you, you guys awe awesome!!!!

+rep to ondiz

<3

edit: just a quick question, does this leak?
Collapse JASS:
function Kill takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > 10
        if GetTerrainType(GetUnitX(udg_Unit[i]),GetUnitY(udg_Unit[i])) == 'Lgrd' then
            call KillUnit( udg_Unit[i] )
        else
        endif
        set i = i + 1
    endloop
endfunction
01-06-2007, 02:16 AM#8
wyrmlord
No
01-06-2007, 02:39 AM#9
Vexorian
We can't be sure anymore
01-06-2007, 08:58 AM#10
Captain Griffen
The 'else' isn't needed.
01-06-2007, 10:56 AM#11
oNdizZ
Ye i know, i just forgot to remove it when editting his code.

Quote:
Originally Posted by Vexorian
We can't be sure anymore

ehumm?
01-06-2007, 05:22 PM#12
Feroc1ty
edit: could someone fix this for me pretty plz, and explain what i did wrong.

Collapse JASS:
function Check takes nothing returns nothing
    local location p
    local integer food = 0
    local integer i = 0
    loop
        exitwhen i > udg_players
        set food = food + GetPlayerState(ConvertedPlayer(i), PLAYER_STATE_RESOURCE_FOOD_USED)
        set i = i + 1
    endloop
    if food == 0 then
        set i = 0
        loop
            exitwhen i > udg_players
            set p = GetRandomLocInRect(udg_respawn)
            call ReviveHeroLoc( udg_Unit[i], p, false )
            set i = i + 1
        endloop
    endif
    set p = null
    set food = 0
    set i = 0
endfunction

Alright so basicly this makes a loop, and adds players 1-however many players are playing and if the food is 0, p(location) is set in a random respawn region spot and revived, and does it for every single player.
01-07-2007, 01:13 AM#13
Feroc1ty
Srry for dauble post put people that help see this as allready looked into and wont look again until someone posted :\
01-07-2007, 09:15 AM#14
Captain Griffen
ConvertedPlayer(0) will crash. Use Player(i), or start at ConvertedPlayer(1)
01-07-2007, 06:32 PM#15
Anopob
Also, I don't think you need the food/i = 0 part.