HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

"expected end of line" error, why is it coming up???

06-20-2006, 04:21 AM#1
darkwulfv
here's my JASS that seems to be causing problems. It's very crappy JASS, most of the variables was guessing, I'm a noob

Collapse JASS:
//===========================================================================
set udg_random = GetRandomInt(1, 4)
function Trig_RandomP1_Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 4 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 3 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 2 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001C takes nothing returns boolean
    if ( not ( udg_random == 1 ) ) then
        return false
    endif
    return true
endfunction
set udg_random = null
function Trig_RandomP1_Actions takes nothing returns nothing
    if ( Trig_RandomP1_Func001C() ) then
        call CreateNUnitsAtLoc( 1, 'hpea', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
    else
        if ( Trig_RandomP1_Func001Func001C() ) then
            call CreateNUnitsAtLoc( 1, 'hfoo', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
        else
            if ( Trig_RandomP1_Func001Func001Func001C() ) then
                call CreateNUnitsAtLoc( 1, 'hkni', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
            else
                if ( Trig_RandomP1_Func001Func001Func001Func001C() ) then
                    call CreateNUnitsAtLoc( 1, 'hrif', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
                else
                endif
            endif
        endif
    endif
endfunction

//===========================================================================
function InitTrig_RandomP1 takes nothing returns nothing
    set gg_trg_RandomP1 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(0), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(1), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(2), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(3), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(4), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(5), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(6), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(7), "-random", true )
    call TriggerAddAction( gg_trg_RandomP1, function Trig_RandomP1_Actions )
endfunction

//===========================================================================
// Trigger: Floating Text Copy
//===========================================================================
function Trig_Floating_Text_Copy_Actions takes nothing returns nothing
local texttag ft1 = CreateTextTagUnitBJ( "PEASENTS", gg_unit_hpea_0067, 0, 10, 100, 100, 100, 0 )
local texttag ft2 = CreateTextTagUnitBJ( "KNIGHTS", gg_unit_hkni_0066, 0, 10, 100, 100, 100, 0 )
local texttag ft3 = CreateTextTagUnitBJ( "PRIESTS", gg_unit_hmpr_0065, 0, 10, 100, 100, 100, 0 )
local texttag ft4 = CreateTextTagUnitBJ( "RIFLEMEN", gg_unit_hrif_0064, 0, 10, 100, 100, 100, 0 )
    call PolledWait( 120.00 )
    call DestroyTextTagBJ( ft1 )
    set ft1 = null
    call DestroyTextTagBJ( ft2 )
    set ft2 = null
    call DestroyTextTagBJ( ft3 )
    set ft3 = null
    call DestroyTextTagBJ( ft4 )
    set ft4 = null
endfunction

Look at the top line of the JASS, that's the line of the first error

Sry for making you read so much, I don't know whats wrong. Bits and pieces were guessed in there. Rep to anyone who helps!
06-20-2006, 04:32 AM#2
harshateja
Unfortunetly cause jass ain't oop, everything has got to be in a method. Your top line aint in a method.
06-20-2006, 04:57 AM#3
Rising_Dusk
set udg_random = null
And other "set udg_random"s are not in functions.

Harsh meant everything has to be in a function.
(Just had to clarify. :P)
06-20-2006, 07:50 AM#4
aquilla
another thing, in the Trig_Floating_Text_Copy_Actions, you got a PolledWait. Is that the init of a trigger? In that case it won't destroy the texttags as TriggerSleepAction (which PolledWait uses) can't be used on init. You could use a global floating text and a timer instead, eg:

Collapse JASS:
function DestroyFloatingTexts takes nothing returns nothing
    local integer i = 1
    call DestroyTimer(GetExpiredTimer())
    loop
        exitwhen i > 4
        call DestroyTextTag(ft[i])
        set ft[i] = null
        set i = i+1
    endloop
endfunction

function Trig_Floating_Text_Copy_Actions takes nothing returns nothing
    set ft[1] = CreateTextTagUnitBJ( "PEASANTS", gg_unit_hpea_0067, 0, 10, 100, 100, 100, 0 )
    set ft[2] = CreateTextTagUnitBJ( "KNIGHTS", gg_unit_hkni_0066, 0, 10, 100, 100, 100, 0 )
    set ft[3] = CreateTextTagUnitBJ( "PRIESTS", gg_unit_hmpr_0065, 0, 10, 100, 100, 100, 0 )
    set ft[4] = CreateTextTagUnitBJ( "RIFLEMEN", gg_unit_hrif_0064, 0, 10, 100, 100, 100, 0 )
    call TimerStart(CreateTimer(), 120, false, function DestroyFloatingTexts)
endfunction

Edit: since I am completely bored, I improved your code, hope you don't mind

Collapse JASS:
function Random takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer rand = GetRandomInt(1, 4) // by using a local you can delete the udg_random, wohoo
    local integer id
    local integer sloc = GetPlayerStartLocation(p) // this is which player's startloc the player has (if you have random startlocs for example, this still works)
    if rand == 1 then // check the random number and set the unittype to be created accordingly
        set id = 'hpea'
    elseif rand == 2 then
        set id = 'hfoo'
    elseif rand == 3 then
        set id = 'hkni'
    else
        set id = 'hrif'
    endif
    call CreateUnit(p, id, GetStartLocationX(sloc), GetStartLocationY(sloc), 270) //create the unit at the X and Y of the start location, since we use X/Y we don't need to remove the location, 270 is the facing angle which bj_UNIT_FACING returns
    set p = null
endfunction

//===========================================================================
function InitTrig_RandomP1 takes nothing returns nothing
    local trigger t = CreateTrigger() // use a local to save some bytes of memory :D also looks cooler (but can't be refered to in triggers etc)
    local integer i = 0
    loop
        exitwhen i > 7
        call TriggerRegisterPlayerChatEvent(t, Player(i), "-random", true)
        set i = i+1
    endloop
    call TriggerAddAction(t, function Random)
    set t = null
endfunction
06-20-2006, 08:09 AM#5
Captain Griffen
You may wish to clean that up a lot, as at the moment it looks exactly like how the GUI translates it, which isn't a good thing. Using functions for conditions for anything other than boolexprs and the trigger conditions is uncalled for, and inefficient, as is the usage of BJs in almost all cases, so use natives.

Example:

Collapse JASS:
function Trig_RandomP1_Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 4 ) ) then
        return false
    endif
    return true
endfunction

...

                if ( Trig_RandomP1_Func001Func001Func001Func001C() ) then
                    call CreateNUnitsAtLoc( 1, 'hrif', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
                else
                endif

Could be changed to:

Collapse JASS:
                if udg_random == 4 then
                    call CreateUnitLoc( GetTriggerPlayer(), 'hrif', l, 270 )
                endif

And put at the begining of that function:

Collapse JASS:
local location l = GetPlayerStartLocationLoc(GetTriggerPlayer())

And at the end:

Collapse JASS:
call RemoveLocation(l)
set l = null
06-20-2006, 11:46 AM#6
darkwulfv
@aquilla: thx for improvign the code. This was one of those things I'd never figure out. +rep. This code is fixed, correct? Thx again, tons and tons. Glad my code gave you something to do :D. It seems to be ok now, just gotta tidy up another JASS later.