spell works for 1st time cast, the second cast doesnt work

waaaks!

Zinctified
Reaction score
255
JASS:
globals
 constant integer DemonSpellId   = 'A000' //Demon's Sanctum Spell Id
 constant integer FirstSpellId   = 'A001' //First Santuary Spell Id
 constant integer SecondSpellId  = 'A002' //Second Sanctuary Spell Id
 constant integer DummySanctuary = 'u000' //Dummy Sanctuary Spell Id
 constant string DemonSpellOrder = "starfall" //Demon's Sanctum Order Id
 constant real FirstRange        = 300.0 //How far the First Sanctuary is created
 constant real SecondRange       = 600.0 //How far the Second Sanctuary is created
endglobals

struct Ddata
 unit caster
 location loc
 location pol1
 location pol2
 integer level
 unit first
 unit second
 integer n
endstruct

function Trig_DemonSanctum_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == DemonSpellId
endfunction

function Trig_DemonSanctum_Actions takes nothing returns nothing
 local Ddata d = Ddata.create()
 set d.caster = GetTriggerUnit()
 set d.loc = GetUnitLoc(d.caster)
 set d.level = GetUnitAbilityLevel(d.caster, DemonSpellId)
 loop
   exitwhen d.n > 36
   set d.pol1 = PolarProjectionBJ(d.loc, FirstRange, 10*d.n)
   set d.pol2 = PolarProjectionBJ(d.loc, SecondRange, 10*d.n)
   set d.first = CreateUnitAtLoc(GetOwningPlayer(d.caster), DummySanctuary, d.pol1, 10*d.n)
   set d.second = CreateUnitAtLoc(GetOwningPlayer(d.caster), DummySanctuary, d.pol2, 10*d.n)
   call UnitApplyTimedLife(d.first, 'BTLF', 8 + (2*d.level))
   call UnitApplyTimedLife(d.second, 'BTLF', 8 + (2*d.level))
   call UnitAddAbility(d.first, FirstSpellId)
   call UnitAddAbility(d.second, SecondSpellId)
   call SetUnitAbilityLevel(d.first, FirstSpellId, d.level)
   call SetUnitAbilityLevel(d.second, SecondSpellId, d.level)
   set d.n = d.n + 1
 endloop
 call d.destroy()
endfunction

//===========================================================================
function InitTrig_DemonSanctum takes nothing returns nothing
    set gg_trg_DemonSanctum = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DemonSanctum, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_DemonSanctum, Condition( function Trig_DemonSanctum_Conditions ) )
    call TriggerAddAction( gg_trg_DemonSanctum, function Trig_DemonSanctum_Actions )
endfunction


this is the spell ive made before...and it works fine, for the first cast...but for the second cast...it wont work...

any ideas?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Why are you using a struct? There is no reason to use a struct, as far as I know, if you are not going to transfer local data across functions.

> but for the second cast...it wont work...

Add BJDebugMsgs and report back. I would say:

JASS:
function Trig_DemonSanctum_Actions takes nothing returns nothing
 local Ddata d = Ddata.create()
 set d.caster = GetTriggerUnit()
 set d.loc = GetUnitLoc(d.caster)
 set d.level = GetUnitAbilityLevel(d.caster, DemonSpellId)

 call BJDebugMsg(I2S(d)) // Created, yes?
 // Show all the variables in d, make sure everything is correct.

 loop
   call BJDebugMsg(d.n) // Running? More than once?
   exitwhen d.n > 36
   set d.pol1 = PolarProjectionBJ(d.loc, FirstRange, 10*d.n)
   set d.pol2 = PolarProjectionBJ(d.loc, SecondRange, 10*d.n)
   set d.first = CreateUnitAtLoc(GetOwningPlayer(d.caster), DummySanctuary, d.pol1, 10*d.n)
   set d.second = CreateUnitAtLoc(GetOwningPlayer(d.caster), DummySanctuary, d.pol2, 10*d.n)
   call UnitApplyTimedLife(d.first, 'BTLF', 8 + (2*d.level))
   call UnitApplyTimedLife(d.second, 'BTLF', 8 + (2*d.level))
   call UnitAddAbility(d.first, FirstSpellId)
   call UnitAddAbility(d.second, SecondSpellId)
   call SetUnitAbilityLevel(d.first, FirstSpellId, d.level)
   call SetUnitAbilityLevel(d.second, SecondSpellId, d.level)
   set d.n = d.n + 1
 endloop
 call d.destroy()
endfunction


Also:

JASS:
function t takes nothing returns nothing
    if true then
        loop
            loop
                // 1337 action
            endloop
        endloop
    endif
endfunction


Is a way better way to display your functions.

Lastly, test the spell when not using a struct.
 
J

JRPereira

Guest
Does jass support classes/methods/oop? Is there some information on this that I can refer to?

You mention passing local data across functions - do you mean this as an alternative to long argument lists? or do you mean it as a way to avoid using globals for things such as complex spelltriggers?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Silvenon got most of it I think.

Waaaks! is using what is called vJass language, which is much like Jass, but with many more features, such as structs, global blocks, text macros, scopes (and libraries), and the list goes on and on.

In order to use vJass you need to download Jass NewGen (linked above), it comes with a detailed Read Me (also linked) that explains it quite well.

> You mention passing local data across functions ...

Well, let's think about the difference between globals and locals. Globals stay the whole game, and can be changed from everywhere, whenever they are called. However, locals are created only once, each time a function runs it creates a set of new local variables, that at the end of the function will be removed, in other words, we could not refer back to them, in this function or any other function.

So, why are locals better then globals (excluding the technical benefiets of course)? Well say we run a trigger, and before it ends, the same trigger runs again. What will happen in that case if we used globals? They will be overwritten, and as the trigger will keep refering to those, it will break. However, if we used locals, it would simply create a new set of them, and the triggers will not interrupt each other.

But when using locals we have a problem. We can't send their information acorss functions easily. How do we solve this? Well when using regular Jass, we had to use old fashionshed systems to store the data, and restore it when running other function, however when using structs with vJass we keep all the information on the sturct, trasfer only it, and restore the information stored only on it. We gain safety and speed.

I'm sure there are much more detailed tutorial about this, feel free to search for them if my explanation wasn't clear enough.
 

waaaks!

Zinctified
Reaction score
255
JASS:
function t takes nothing returns nothing
    if true then
        loop
            loop
                // 1337 action
            endloop
        endloop
    endif
endfunction


what does this function do?
will i put a function inside it?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
No, what I meant is, is that it is easier to read my function than reading your function. Use some space " ", if you are using TESH tab will automatically create 4 spaces for you, and pressing enter will not delete the spaces you have already, it will recreate them.

As for the trigger, what were the results?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top