• 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] Errors on compiling (newbie to JASS)

Status
Not open for further replies.
Level 3
Joined
Jul 15, 2007
Messages
36
Hello all, and thank-you for reading this.

I should point out; I am just starting to use JASS after soley GUI'ing for a few projects.

I have a couple of JASS problems that I'd like help with;

Problem 1) Have i named them wrong?
I have tried the following script. The intent is that it fires when a unit enters "gg_rct_Player1Zone" (defined in the world editor). It checks if the player that belongs to that zone has "lives" left (integer array gg_lives[x], defined in the WE variable editor), and if it is less than or equal to zero, to warp the unit to another zone, and issue a move order.

I get the following errors when the WE compiles the map when saving;
"expected a name" at
JASS:
    set l = gg_lives[0]
"type mismatch in assignment" at
JASS:
            set l = null

{EDIT}
reading the handlevars thread, could I be looking at the wrong line, and the problem is with the
JASS:
    set u = GetTriggerUnit()
and then trying to null a unit variable?{/EDIT}
have i defined the variables wrongly?

JASS:
//---------------------------------------------------------------------------
// Skip player one is status is not playing, when unit enters player1 zone

function Trig_Skip1_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) != 'n000'
endfunction

function Trig_Skip1_Actions takes nothing returns nothing
    local unit u
    local integer l
    set u = GetTriggerUnit()
    set l = gg_lives[0]
    if l <= 0 then
            call SetUnitPositionLoc( u, GetRandomLocInRect(gg_rct_Player1Spawn) )
            call IssuePointOrderLocBJ( u, "move", GetRectCenter(gg_rct_Player2Hall) )
            set u = null
            set l = null    
        else
            return
    endif
    return
endfunction

//===========================================================================
function InitTrig_Skip1 takes nothing returns nothing
    set gg_trg_Skip1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Skip1, gg_rct_Player1Zone )
    call TriggerAddCondition( gg_trg_Skip1, Condition( function Trig_Skip1_Conditions ) )
    call TriggerAddAction( gg_trg_Skip1, function Trig_Skip1_Actions )
endfunction

(additionally tried to remove leaks; are these valid leaks? have i fixed them?)


Problem 2) Reducing the copy-paste
As I am running several copies of essentially the same code, with minor variations, for each player zone, can I use the same "conditions" function for all of them? I.E. can I rename
JASS:
function Trig_Skip1_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) != 'n000'
endfunction
to
JASS:
function Trig_Notn000_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) != 'n000'
endfunction

and change all the triggers that need to satisfy that condition to
JASS:
    call TriggerAddCondition( gg_trg_Skip1, Condition( function Trig_Notn000_Conditions ) )

and if I do, could that cause problems when multiple triggers are calling it, or does each instance of a trigger access it independantly and the return value doesn't get mucked up?
(did that make sense? I.E. by having multiple triggers running that call the same conditions, is that better/worse than having a copy for each trigger, for which the only difference is the actions.)

Problem 3) GUI -> JASS
Being new to using JASS, I'm not really sure how to put it into the world editor. Basically at the moment I seem to need to make each trigger from the "new trigger" command in the GUI, convert it to text, then paste that trigger in.

Is it possible to put more than one set of functions in? I.E. instead of the GUI having "Warp1", "Warp2", "Warp3", all of which are similar, can i put them all in one "trigger" in the GUI? It seems to be doing things in the background like defining trigger objects in the globals.

If so, how? do I have to put "globals" and define the trigger objects at the start of the script? Will multiple copies of that be compiled by WE?

Problem 4) Global Variables
How do I define variables manually, bypassing the WE variable control window? do i just put
JASS:
globals
    // User-defined
    leaderboard             udg_leaderboard01          = null
    integer                 udg_integer01              = 0
    integer                 udg_integer02              = 0
    integer                 udg_integer03              = 0
    trigger                  gg_skip1                     = null

Thank-you again for bothering to read this :)

Cheers,
AussieLauren
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
gg_lives[0] is not defined. Globals are "udg_" then name like "udg_lives[0]".

null is not a number, thus you should not be supprised it errors. Numbers do not leak so do not need to be set to default but if you do want to anyway they start as 0 since they are a normal number.

You leak a lot of locations.

I recomend imrpoving your GUI skills since you use far too many "end trigger" (return s) than nescarry.
Also you can asign locals to a value appon creation.
In jass, "if - then" do NOT NEED to have an else/elseif.
It is pointless to return at the end of a function that returns nothing since it has already ended and so returning does nothing.

I can recomend looking at some of our jass based spells to lear a thing or two, thats how I learned most of my jass.
 
Level 3
Joined
Jul 15, 2007
Messages
36
Thank-you for your tips, particularly about the returns, the declaring local values on creation and spotting my (somewhat stupid) mistake with the global array.


Problem 1)
================{EDIT}============
Okay, went back to GUI, and re-wrote the script, then tried to clean it up, and it works!
JASS:
function Trig_Skip1_Conditions takes nothing returns boolean
    if GetUnitTypeId(GetTriggerUnit()) == 'n000' then
        return false
    endif
    if udg_Lives[0] <= 0 then
        return true
    endif
    return false
endfunction

function Trig_Skip1_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location spawn =  GetRandomLocInRect(gg_rct_Player1Spawn)
    local location hall = GetRectCenter(gg_rct_Player2Hall)
    call SetUnitPositionLoc( u, spawn )
    call IssuePointOrderLocBJ( u, "move", hall )
    set u = null
    call RemoveLocation(spawn)
    call RemoveLocation(hall)
endfunction

//===========================================================================
function InitTrig_Skip1 takes nothing returns nothing
    set gg_trg_Skip1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Skip1, gg_rct_Player1Zone )
    call TriggerAddCondition( gg_trg_Skip1, Condition( function Trig_Skip1_Conditions ) )
    call TriggerAddAction( gg_trg_Skip1, function Trig_Skip1_Actions )
endfunction
Main change was to move the lives check to the conditions where it probably belongs.
Just double-checking I've cleaned the leaks with this one?

Problem 2)
Just reiterating, can i have multiple triggers calling the same condition function without causing an issue?


Cheers and thank-you
 
Last edited:
Level 8
Joined
Jul 23, 2005
Messages
329
Problem 1) Looks good.
Problem 2) I don't think there would be any issues, so long as the condition function is in the section labeled "custom map script", else the other triggers won't be able to find said condition.
 
Level 3
Joined
Jul 15, 2007
Messages
36
Thank-you very much for your replies,
Looks like custom script is the place to put them so I don't have to worry too much about things calling it too early.

Cheers!
 
Status
Not open for further replies.
Top