HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Localizing Arrays Problem

05-30-2009, 11:20 PM#1
Forerunner
I'll give a brief rundown of what's supposed to happen before we jump into my GUI-Noob code...

Ok, so the idea of the spell was it would create two portals, one at the casting unit's position, and one at the target point of the ability, and then units could teleport from one to the other. It works, that isn't the issue.

What is the issue is that I wanted to go back and localize my units and points (I don't believe I actually need to do the points, but I tried anyways) and I always come up with an error. Here's the code, first.

Hidden information:

Trigger:
Events
Unit - A unit Finishes casting an ability
Conditions
(Ability being cast) Equal to Portals
Actions
Set Point[1] = (Target point of ability being cast)
Set Point[2] = (Position of (Triggering unit))
Unit - Create 1 Portal for (Owner of (Triggering unit)) at Point[1] facing Default building facing degrees
Set Unit[1] = (Last created unit)
Unit - Create 1 Portal for (Owner of (Triggering unit)) at Point[2] facing Default building facing degrees
Set Unit[2] = (Last created unit)
Neutral Building - Set Unit[1] destination to Point[2]
Neutral Building - Set Unit[2] destination to Point[1]
Neutral Building - Enable Unit[1]
Neutral Building - Enable Unit[2]


What I keep trying to do is localize the variable with
Trigger:
Custom Script: local unit udg_Unit

Gave me an error, so I tried this:
Trigger:
Custom Script: local unit udg_Unit[1]

Allow me to show you the error message that I get:
Click image for larger version

Name:	Errormessage.JPG
Views:	12
Size:	47.3 KB
ID:	43415

That's all I can think to say here, in hopes that someone identifies my foolish mistake. If you need anymore information about this, I will tell you everything I can.
Attached Images
File type: jpgErrormessage.JPG (47.3 KB)
05-30-2009, 11:22 PM#2
Captain Griffen
local unit array XXX
05-30-2009, 11:51 PM#3
Forerunner
Thanks for the quick answer, but I'm still having an issue (you did shrink it from six errors to one, though).

I've attempted
Trigger:
Custom Script: local unit array udg_Unit
And
Trigger:
Custom Script: local unit array udg_Unit[1]

But both of them bring me to the same error message:
Click image for larger version

Name:	ErrorMessage2.JPG
Views:	28
Size:	37.4 KB
ID:	43416

Also, once the arrays get localized, I am going to be removing the location leaks. Will this do the job?
Trigger:
Custom Script:call RemoveLocation(udg_Point[1])

As you can tell, I'm not experienced with using arrays and custom script, and I really appreciate your help.
05-31-2009, 12:04 AM#4
Bobo_The_Kodo
put the local unit array udg_Unit to be the first line in the function
05-31-2009, 05:03 PM#5
Forerunner
Man, it appears that I am moving from one problem to the next. At least now I am able to enable the trigger, but its not working as intended.

From what I can tell, the variables aren't becoming local every time that the trigger runs. For instance, I cast the spell the first time and it works great, but if I cast a second one before the first one finishes and dies off, then the second one will die off and the first will stay. Also, once it has been cast more than once, it messes up the target locations of the portals. Here's my script again, maybe you can see what I can't.

Hidden information:
Portals:
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Portals
Collapse Actions
Custom script: local unit array Unit
Custom script: local location array Point
Set Point[1] = (Target point of ability being cast)
Set Real = (Facing of (Triggering unit))
Set Point[2] = ((Position of (Triggering unit)) offset by 300.00 towards Real degrees)
Set Real = (Angle from Point[2] to Point[1])
Unit - Create 1 Portal for (Owner of (Triggering unit)) at Point[1] facing Real degrees
Set Unit[1] = (Last created unit)
Set Real = (Angle from Point[1] to Point[2])
Unit - Create 1 Portal for (Owner of (Triggering unit)) at Point[2] facing Real degrees
Set Unit[2] = (Last created unit)
Set Integer = (Level of Portals for (Triggering unit))
Neutral Building - Set Unit[1] destination to Point[2]
Neutral Building - Set Unit[2] destination to Point[1]
Neutral Building - Enable Unit[1]
Neutral Building - Enable Unit[2]
Wait (10.00 x (Real(Integer))) seconds
Unit - Kill Unit[1]
Unit - Kill Unit[2]
Custom script: call RemoveLocation(udg_Point[1])
Custom script: call RemoveLocation(udg_Point[2])


Thanks for the assistance that you guys have provided with me so far, I appreciate it!
05-31-2009, 05:19 PM#6
Zandose
If I remember correctly and I could be totally wrong but, you can only use the local trick once. So your locations/points are being put into the globals arrays (not the local one) and is being overridden by the second spell.

You probably cannot fix it unless you do some more complex GUI, like separate arrays for each spell instance with loops and if-statements, or a manual 2-d array. May I suggest you turn that into JASS? I can fix it, and comment it so you understand it.

Trying to get help with GUI is hard because others cannot readily edit it, unlike JASS, and it's just plain hard to read.
05-31-2009, 05:49 PM#7
Forerunner
If you would like to do it in JASS, I would be very grateful. This went from something I thought would be a nice spell for a hero to way more worry than it deserves.

I've tried to learn JASS, used Wyrmlord's tutorials a couple different times, I just get lost in it all.
05-31-2009, 06:00 PM#8
Zandose
Quote:
Originally Posted by Forerunner
If you would like to do it in JASS, I would be very grateful. This went from something I thought would be a nice spell for a hero to way more worry than it deserves.

I've tried to learn JASS, used Wyrmlord's tutorials a couple different times, I just get lost in it all.
Convert and post it, please.

Edit: Really, if you want my help you need to post the JASS code, or explain what your doing. I think your making two waypoints for a set amount of time, for units to cross, then destroying it.
06-04-2009, 01:35 AM#9
azlier
udg_Unit and udg_Point, not Unit and Point. GUI uses udg_, remember?
06-04-2009, 02:17 AM#10
Forerunner
I'm very sorry; it's Exam week at school and I this had completely slipped my mind :[. Here's my code (finally, lol). I believe this is what you need, correct?

Collapse JASS:
function Trig_Way_Point_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A001' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Way_Point_Actions takes nothing returns nothing
    local unit array Unit
    local location array Point
    set udg_Point[1] = GetSpellTargetLoc()
    set udg_Real = GetUnitFacing(GetTriggerUnit())
    set udg_Point[2] = PolarProjectionBJ(GetUnitLoc(GetTriggerUnit()), 300.00, udg_Real)
    set udg_Real = AngleBetweenPoints(udg_Point[2], udg_Point[1])
    call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(GetTriggerUnit()), udg_Point[1], udg_Real )
    set udg_Unit[1] = GetLastCreatedUnit()
    set udg_Real = AngleBetweenPoints(udg_Point[1], udg_Point[2])
    call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(GetTriggerUnit()), udg_Point[2], udg_Real )
    set udg_Unit[2] = GetLastCreatedUnit()
    set udg_Integer = GetUnitAbilityLevelSwapped('A001', GetTriggerUnit())
    call WaygateSetDestinationLocBJ( udg_Unit[1], udg_Point[2] )
    call WaygateSetDestinationLocBJ( udg_Unit[2], udg_Point[1] )
    call WaygateActivateBJ( true, udg_Unit[1] )
    call WaygateActivateBJ( true, udg_Unit[2] )
    call TriggerSleepAction( ( 10.00 * I2R(udg_Integer) ) )
    call KillUnit( udg_Unit[1] )
    call KillUnit( udg_Unit[2] )
    call RemoveLocation(udg_Point[1])
    call RemoveLocation(udg_Point[2])
endfunction

//===========================================================================
function InitTrig_Way_Point takes nothing returns nothing
    set gg_trg_Way_Point = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Way_Point, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Way_Point, Condition( function Trig_Way_Point_Conditions ) )
    call TriggerAddAction( gg_trg_Way_Point, function Trig_Way_Point_Actions )
endfunction

I've also been trying to slug my way through learning JASS, but it's still pretty tough :P
06-04-2009, 02:24 AM#11
Zandose
Quote:
Originally Posted by azlier
udg_Unit and udg_Point, not Unit and Point. GUI uses udg_, remember?
LOL. That one completely passed me. Forerunner, try that first.
06-04-2009, 06:30 AM#12
0zyx0
The code can be improved to become slightly faster:
Collapse JASS:
function Trig_Way_Point_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

function Trig_Way_Point_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit Unit1
    local unit Unit2  // There is no need to use an array.
    local location l = GetSpellTargetLoc()
    local real x1 = GetLocationX(l)
    local real y1 = GetLocationY(l)
    local real x2
    local real y2
    local real angle = GetUnitFacing(caster)
    local integer level = GetUnitAbilityLevel(caster, 'A001')
    call RemoveLocation(l)
    set l = null

    set Unit1 = CreateUnit(GetOwningPlayer(caster), 'n000', x1, y1, angle)

    set angle = angle*bj_DEGTORAD
    set x2 = x1 + 300. * Cos(angle)
    set y2 = y1 + 300. * Sin(angle)
    set angle = angle*bj_RADTODEG + 180.

    set Unit2 = CreateUnit(GetOwningPlayer(caster), 'n000', x2, y2, angle)

    call WaygateSetDestination(Unit1, x2, y2)
    call WaygateSetDestination(Unit2, x1, y1)
    call WaygateActivate(Unit1, true)
    call WaygateActivate(Unit2, true)
    call TriggerSleepAction(10.00 * I2R(level))
    call KillUnit(Unit1)
    call KillUnit(Unit2)
    set Unit1 = null
    set Unit2 = null
    set caster = null
endfunction
This should work, but I haven't checked the syntax yet, so there may be some problems with it.
06-04-2009, 11:21 AM#13
Hans_Maulwurf
@0zyx0:
Since the only thing your doing after the Wait, is KillUnit(), you can get rid of it, by using UnitApplyTimedLife() instead
06-04-2009, 11:23 AM#14
Forerunner
Quote:
Originally Posted by Zandose
LOL. That one completely passed me. Forerunner, try that first.

Alright... I assume that you are talking about putting udg_ in front of the Arrays? That brings up
Hidden information:
Click image for larger version

Name:	Error.JPG
Views:	7
Size:	40.3 KB
ID:	43508


Quote:
Originally Posted by 0zyx0
This should work, but I haven't checked the syntax yet, so there may be some problems with it.

It's only got one problem when I try to run it. Line 56
Collapse JASS:
 call WaygateActivateBJ(Unit2, true)

says there in an "Invalid argument type (boolean)". Line 55, which appears to be nearly the same thing but with the first way-gate, works fine.
Attached Images
File type: jpgError.JPG (40.3 KB)
06-04-2009, 11:45 AM#15
Hans_Maulwurf
Quote:
Originally Posted by Forerunner
Collapse JASS:
 call WaygateActivateBJ(Unit2, true)

says there in an "Invalid argument type (boolean)". Line 55, which appears to be nearly the same thing but with the first way-gate, works fine.


its either
Collapse JASS:
 call WaygateActivateBJ(true, Unit2)
or
Collapse JASS:
 call WaygateActivate(Unit2, true)

(just remove the BJ)