HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Do local vars null themselves? - Trouble with CreateUnit()

04-01-2006, 10:27 PM#1
knutz
It's my first attempt at a JASS spell and I can't figure out why I get the error message "Invalid Number of Arguments" whenever I use "CreateUnit()" or "CreateUnitAtLoc()" when I know I have it right.

Collapse JASS:
    local timer t = GetExpiredTimer()
    local timer array d
    local unit c = GetAttachedUnit(t,"caster")
    local real x = GetAttachedReal(t,"x")
    local real y = GetAttachedReal(t,"y")
    local location loc = Location(x,y)
    local group g = GetAttachedGroup(t, "group")
    local integer v = GetAttachedInt(t,"level")
//    local unit u = CreateUnit(GetOwningPlayer(c), Caster_UnitId(),x,y,0)
    local unit u = CreateUnitAtLoc( GetOwningPlayer(c), Caster_UnitId(), loc,0)
    local unit e
    local integer i = 0
    local integer o //target validation

My only guess is that some variables are nulling themselves before the function. Any ideas?

Edited by Blade.dk. Reason: Read the stickies before posting, we have JASS tags for a reason!
04-01-2006, 10:50 PM#2
Jacek
Are you sure Caster_Id() returns integer? But it shouldn't matter anyways, arguments look fine.
04-01-2006, 11:06 PM#3
PipeDream
CreateUnit/AtLoc has the right number of arguments, so maybe you accidentally gave caster_unitid an argument. Variable contents changing would be a run time problem. You would not get an error at save time.
04-02-2006, 04:39 AM#4
knutz
Quote:
Originally Posted by PipeDream
CreateUnit/AtLoc has the right number of arguments, so maybe you accidentally gave caster_unitid an argument. Variable contents changing would be a run time problem. You would not get an error at save time.

I don't touch Vexorian's functions. The code for that one is:
Collapse JASS:
constant function Caster_UnitId takes nothing returns integer
    return 'u000' //// Caster Unit type rawcode  (changes betwen maps, always use it inside '')
endfunction

and I've checked the raw code and it's fine. For some reason it doesn't have a problem with CreateNUnitsAtLoc, so I just use that one.

Only now I have a "Type mismatch error in assignment" when I try to assign a real to a real.

Collapse JASS:
    local real dmg = GetAttachedReal(t,"damage")

I checked GetAttachedReal, and it takes a handle, and string and returns a real. I assigned a timer to t, so this should be ok.
I'm starting to think the WE hates me, or is just giving me random error codes for something else I've done wrong.

Edited By Blade.dk. Reason: Read the stickies before posting, use jass tags!
04-02-2006, 05:04 AM#5
PipeDream
Hmm. Try running as much of the code as possible (preferably the entire war3map.j) through pjass. It is very good at this sort of thing. If you have never done this before, get a good MPQ utility like MPQMaster.
Then extract common.j and Blizzard.j from War3Patch.mpq, in the Scripts directory, and war3map.j from your map file. Get them all in one folder and run in a console "pjass common.j Blizzard.j war3map.j"
Twiddle until everything is happy.
04-03-2006, 11:46 AM#6
BertTheJasser
Please show us the whole functions you use, maybe c is null, what would bug everything.
04-03-2006, 12:35 PM#7
Vexorian
world editor is giving wrong messages again, I wouldn't worry about variables becoming null, this is a compiler message so it wouldn't matter
04-04-2006, 11:31 AM#8
knutz
Quote:
Originally Posted by BertTheJasser
Please show us the whole functions you use, maybe c is null, what would bug everything.


Ok, I started a new map with the same object data and added the functions line by line. After playing with it I managed to get the map to save without error. It still doesn't do what I want though and I isolated the code where it gets mixed up.

Collapse JASS:
  
local real dmg = GetAttachedReal(t,"damage") //Damage to be done to the victim
local real check = GetUnitStateSwap(UNIT_STATE_LIFE, v) //Remaining life of the victim


  if ( check > dmg ) then
        call UnitDamageTargetBJ( u, v, dmg, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL )
        
        if ( count == 0 ) then
            call DarkConversion_DamageDone(t)
            call UnitWakeUpBJ( v )
        else
            call AttachInt(t,"count",count-1)
            call TimerStart(t, 1.0, true, function DarkConversion_Damage)
        endif

    else
        set a = GetUnitFacing(v)
        call KillUnit( v )
        call CreateNUnitsAtLoc( 1, DarkConversion_ZombieUnitId(l), GetOwningPlayer(c), loc,a )
        call AddSpecialEffectLocBJ( loc, "Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl" )
        call DarkConversion_DamageDone(t) 
    endif

What this is meant to do is damage the victim once a second IF they can take the damage without dying. If they can't take it, kill the unit and a zombie (level 1 - 4) is to rise up in their place.

What it does is just keeps damaging the units until they die. No zombie. It never returns false on the first "if" statement.

Any ideas what I've messed up?

PS: this is an AoE Dark Conversion spell that works on any race.

Post 2:

OK, I saw the Animate Dead special effect when I just now tested, and realised I was using the wrong raw code for the zombies. But I'm not getting enough zombies.

There should be one for every victim, but it works out at about 1 for every 5.

I think I know what's wrong, but not how to fix, but is a new question for a new thread.

Thanks all for the help :-)

Edited by Blade.dk. Reason: Use jass tags and don't double post!