• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Issues with a function / global var

Status
Not open for further replies.
Level 1
Joined
May 24, 2013
Messages
7
I have been trying to find the problem for hours now.
call DisplayTimedTextToForce( GetPlayersAll(), 60.0, CREATOR )
works, but the next line does not work at all. The Trigger stops at the code
call ForceAddPlayer( Players, owner )

I tried the ForceAddPlayerSimple() with changed positions of force and player, but it still did not work.

It was working earlier, before i made all the global variables in jass, but changed other aspects of the code as well.


This is at the top of the custom script code:
JASS:
globals
    constant string CREATOR = "Respwner"
    force Players
    group Player_Heroes
    group Creeps
endglobals

This is the trigger named Mapstart:
JASS:
function Trig_Mapstart_Actions takes nothing returns nothing
    local location mapstartpoint
    local rect picknewhero = gg_rct_Picknewhero
    local integer i = 0
    local unit wisp
    local player owner
    
    loop
        if GetPlayerSlotState( Player( i ) ) == PLAYER_SLOT_STATE_PLAYING then
            set owner = Player( i )
            set mapstartpoint = GetRandomLocInRect( picknewhero )
            set wisp = CreateUnitAtLoc( owner, 'e000', mapstartpoint, GetRandomDirectionDeg() )
            call SelectUnitAddForPlayer( wisp, owner )
            call PanCameraToTimedLocForPlayer( owner, mapstartpoint, 0 )
            
            call DisplayTimedTextToForce( GetPlayersAll(), 60.0, CREATOR )
            call ForceAddPlayer( Players, owner )
            
            call RemoveLocation ( mapstartpoint )
            set mapstartpoint = null
            set wisp = null
            set owner = null
        endif
        set i = i + 1
        exitwhen i == 9
    endloop

    set picknewhero = null
endfunction

//===========================================================================
function InitTrig_Mapstart takes nothing returns nothing
    set gg_trg_Mapstart = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Mapstart, 0.3 )
    call TriggerAddAction( gg_trg_Mapstart, function Trig_Mapstart_Actions )
endfunction

Im still a noob at jass, since this is the first map where im actually trying to make something, not just mess around. I feel like i should have found my error here though. "Arrrg..."

EDIT: Off to bed, going to sleep off some frustration xD
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
JASS:
force Players

->

JASS:
force Players = CreateForce()

When you create a variable in GUI, the variable manager automatically creates all the variables at map init.

When you use JASS, you need to create the variables yourself.

@Almia: Only a few are really "buggy", but nevertheless you should always use a native if available.
 
Level 1
Joined
May 24, 2013
Messages
7
Bah, so obvious really, but thanks a bunch!

For your trouble, +rep rulerofiron99.


Because BJs are bugged and slow. Use natives.

As stated, im quite new to jass. Im trying not to use BJs unless no other options are available though (that i can find). Could you perhaps point out to me where im currently using BJs?
I thought all BJs actually had BJ in them.:S
 
Level 1
Joined
May 24, 2013
Messages
7
Ah, thanks, was looking around trying to find what functions called other functions in the "Function List", but didnt notice they were all red on the forums :p
 
Level 1
Joined
May 24, 2013
Messages
7
Nice tip about that ctrl + click thingy, saves me time when im sorting through the functions i wrote yesterday, replacing the BJ ones ^^

Btw, im quite certain it does not, but going to go ahead and ask anyways.
CreateUnit(...) x-y-coordinates only acts as integers right? The function does not create a leaking location? =)
 
Nice tip about that ctrl + click thingy, saves me time when im sorting through the functions i wrote yesterday, replacing the BJ ones ^^

Btw, im quite certain it does not, but going to go ahead and ask anyways.
CreateUnit(...) x-y-coordinates only acts as integers right? The function does not create a leaking location? =)

x/y coordinates are reals. And no they do not leak thats y they should be used instead of locations.

On another note u should use
JASS:
TriggerAddCondition
instead of
JASS:
TriggerAddAction
adding actions has something wrong with it i cant remember what atm lol.
 
Level 1
Joined
May 24, 2013
Messages
7
Thanks again :)
Yeah, i did mean real values ofc, not integers xD

Alright, ill try to use TriggerAddCondition instead.
Currently going through the triggers and generally just getting a better grip on jass/vjass while cleaning up the mess at the same time =)
 
Level 7
Joined
Jan 22, 2013
Messages
293
I have been trying to find the problem for hours now.
call DisplayTimedTextToForce( GetPlayersAll(), 60.0, CREATOR )
works, but the next line does not work at all. The Trigger stops at the code
call ForceAddPlayer( Players, owner )

I tried the ForceAddPlayerSimple() with changed positions of force and player, but it still did not work.

It was working earlier, before i made all the global variables in jass, but changed other aspects of the code as well.


This is at the top of the custom script code:
JASS:
globals
    constant string CREATOR = "Respwner"
    force Players
    group Player_Heroes
    group Creeps
endglobals

This is the trigger named Mapstart:
JASS:
function Trig_Mapstart_Actions takes nothing returns nothing
    local location mapstartpoint
    local rect picknewhero = gg_rct_Picknewhero
    local integer i = 0
    local unit wisp
    local player owner
    
    loop
        if GetPlayerSlotState( Player( i ) ) == PLAYER_SLOT_STATE_PLAYING then
            set owner = Player( i )
            set mapstartpoint = GetRandomLocInRect( picknewhero )
            set wisp = CreateUnitAtLoc( owner, 'e000', mapstartpoint, GetRandomDirectionDeg() )
            call SelectUnitAddForPlayer( wisp, owner )
            call PanCameraToTimedLocForPlayer( owner, mapstartpoint, 0 )
            
            call DisplayTimedTextToForce( GetPlayersAll(), 60.0, CREATOR )
            call ForceAddPlayer( Players, owner )
            
            call RemoveLocation ( mapstartpoint )
            set mapstartpoint = null
            set wisp = null
            set owner = null
        endif
        set i = i + 1
        exitwhen i == 9
    endloop

    set picknewhero = null
endfunction

//===========================================================================
function InitTrig_Mapstart takes nothing returns nothing
    set gg_trg_Mapstart = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Mapstart, 0.3 )
    call TriggerAddAction( gg_trg_Mapstart, function Trig_Mapstart_Actions )
endfunction

Im still a noob at jass, since this is the first map where im actually trying to make something, not just mess around. I feel like i should have found my error here though. "Arrrg..."

EDIT: Off to bed, going to sleep off some frustration xD

This is what you should be coding:

JASS:
globals
    constant string CREATOR = "Respwner"
    force Players
    group Player_Heroes
    group Creeps
endglobals

function Mapstart_Actions takes nothing returns boolean
    local rect pick_new_hero = gg_rct_Picknewhero
    local integer i = 0
    local unit wisp
    local player owner
    local real X
    local real Y
    loop
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            set owner = Player(i)
            //Dont use Locations they leak, win this case you can use reals
            set X = GetRectCenterX(pick_new_hero)
            set Y = GetRectCenterY(pick_new_hero)
            set wisp = CreateUnit( owner, 'e000', X, Y, GetRandomReal(0, 360))
            if (GetLocalPlayer() == owner) then
                call SelectUnit(wisp, true)
                call PanCameraToTimed(X, Y, 0)
            endif
            call DisplayTimedTextToPlayer( owner, 0, 0, 60.0, CREATOR )
            call ForceAddPlayer( Players, owner )
            set wisp = null
            set owner = null
        endif
        set i = i + 1
        exitwhen i == 9
    endloop
    set pick_new_hero = null
    return false
endfunction

//===========================================================================
function InitTrig_Mapstart takes nothing returns nothing
    local trigger T = CreateTrigger()
    call TriggerRegisterTimerEvent( T, 0.30, false )
    call TriggerAddCondition( T, Condition( function Mapstart_Actions ))
    set T = null
endfunction

Compare the differences lol
 
Level 1
Joined
May 24, 2013
Messages
7
The code actually looks alot like what you linked atm, only difference was that i hadnt changed the DisplayTimedTextToForce() -> DisplayTimedTextToPlayer() and TriggerAddAction() yet :)

Thanks for the pointers ^^
 
Level 1
Joined
May 24, 2013
Messages
7
Ye, ill stick to BJDebugMsg and DisplayTextToPlayer() for debugging in the future. :)

Ive soon gone through my code (multiple triggers, not just this one) and made it without BJs and switched out all variables so they are either made globally or locally with jass/vjass.

I also now make rects when i need them based on x and y maxmin (store all 4 in 4 different global arrays if needed later), and Ive gotten rid of all locations used, and rely only on coordinates concerning position.

I did add DestroyTrigger( GetTriggeringTrigger() ) for triggers that only runs once as well, although that prob wont be do much good until there really is a lot going on at the start. :p

Its not all working as intended yet, but it gets better by the minute, or at least by the half hour lol.


Really appreciate all the help Ive gotten already from this friendly community. =)
 
np lol. Also try to condense and make ur triggers more efficient when switching to Jass. the bjs are one part of efficiency. The other is better algorithms and stuff like that to help decrease the amount of processing required for that trigger. if u need any help making triggers more efficient just post on here or make a new thread and ill help u when i can.
 
Status
Not open for further replies.
Top