• 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.

[JASS] Code giving a lot of errors

Status
Not open for further replies.
Level 2
Joined
Aug 30, 2007
Messages
11
Hello everybody, I'm new to scripting in JASS but I'm a Sophmore in Computer Science and have previous coding experience in Java and am looking to try my hand at JASS. The following code is what I hope to expand to be the movement code for a tower wars I'm creating.

JASS:
// Checks if the entering unit is not owned by a given player and if it is not unit u000
function Trig_Conditions takes nothing returns boolean
    if ( GetOwningPlayer(GetEnteringUnit()) != Player(0) ) then
        return false
    endif
    if (  GetUnitTypeId(GetEnteringUnit()) != 'u000' ) then
        return false
    endif
    return true
endfunction

// Moves the unit from the start location to the provided rect and adds the custom value of the unit
// to the income array for the player
function Trig_Move_Start_Actions takes rect r returns nothing
    if ( GetUnitTypeId(GetEnteringUnit()) != 'u000' ) then
        call IssuePointOrderLoc( GetEnteringUnit(), "move", GetRectCenter(r) )
    endif
    if ( Trig_Conditions() ) then
        set udg_Income[GetPlayerId(GetOwningPlayer(GetEnteringUnit()))] = ( udg_Income[GetPlayerId(GetOwningPlayer(GetEnteringUnit()))] + GetUnitUserData(GetEnteringUnit()) )
    endif
endfunction

//Moves the unit from the rect it entered to the given rect
function Trig_Move_Actions takes rect r returns nothing
    if ( GetUnitTypeId(GetEnteringUnit()) != 'u000' ) then
        call IssuePointOrderLoc( GetEnteringUnit(), "move", GetRectCenter(r) )
    endif
endfunction

//===========================================================================
function InitTrig_Move takes nothing returns nothing

    // Initializes player 1's rects and sets them to listen for entering units
    set gg_trg_P1S = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_P1S, gg_rct_P1S )
    call TriggerAddAction( gg_trg_P1S, function Trig_Move_Start_Actions )

    set gg_trg_P1M1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_P1M1, gg_rct_P1M1 )
    call TriggerAddAction( gg_trg_P1M1, function Trig_Move_Actions)

endfunction
 
Last edited:
Level 2
Joined
Aug 30, 2007
Messages
11
Thank you for your prompt response. I edited the code as suggested, namely removing handle from all places it was used (I edited my OP to reflect the changes). I'm still getting a lot of compiler errors... the first one is on the line

function Trig_Move_Start_Actions takes integer i, rect returns nothing

with the error "Expected a name."
 
Level 2
Joined
Aug 30, 2007
Messages
11
Alright, I changed the code in the prescribed manner (OP updated again), but now it crashes upon compiling. Took the last hour of two of work (other than the code) with it too, but that's my fault for not saving.
 
Level 2
Joined
Aug 30, 2007
Messages
11
Alright, fired it up in NewGen (which I can tell I'm going to become great friends with) and now it gives me a few syntax errors and such... I'll play around with it a bit and repost if I can't figure it out.
 
Level 2
Joined
Aug 30, 2007
Messages
11
I've managed to fix everything, except for this one problem. The line

call TriggerAddAction( gg_trg_P1S, function Trig_Move_Start_Actions(0, gg_rct_P1S) )

throws a syntax error.
 
Level 2
Joined
Aug 30, 2007
Messages
11
While that fixed my syntax error, it raises larger conceptual problems in my mind. What passes parameters to Trig_Move_Start_Actions if it's not declared there, as the function Trig_Move_Start_Actions takes an integer and a rect. The primary purpose of the function was to send a unit from the triggering rect to a rect provided in the parameters of the function.
 
Level 2
Joined
Aug 30, 2007
Messages
11
The pseudocode of my idea was something like this

If a unit enters a rect (and the unit satisfies conditions),
then send entering unit from this rect to next rect

How would you propose I go about doing that? Code in OP updated to reflect current state. I'm sorry for taking everybody's time, I really appreciate the help I've gotten so far.
 
Since you have newGen I suggest you go straight into vJASS. What you requested would look like this (vjass).

JASS:
scope EnterRect initializer InitTrig

private function Conditions takes nothing returns boolean
    return GetUnitTypeId(GetEnumUnit()) == 'u000' // your condition here
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local rect newRect = gg_rct_Region_001
    call SetUnitPosition(u, GetRectCenterX(newRect), GetRectCenterY(newRect))
    set u = null
endfunction

//===========================================================================
private function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRectSimple( t, gg_rct_Region_000 )
    call TriggerAddAction( t, function Actions )
endfunction

endscope

Remeber, if you want to compile vJASS you must hit "save".
 
Level 2
Joined
Aug 30, 2007
Messages
11
Alright. I think that might be as far as I develop my code then. If I were to follow the form that you prescribe, I'd have to have 28 move action functions to move from this rect to pre-defined rect b. While I'm somewhat surprised that Jass wouldn't have some way to pass a parameter to a function as part of a certain trigger triggering an event, if I have to code 28 separate functions to achieve what I could do in other programming languages in one that's what I'll do.
 
Status
Not open for further replies.
Top