• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] How To Refer Last Created Lightning ?

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
  • Actions
    • Custom script: local unit Caster = GetTriggerUnit()
    • Custom script: local unit Target = GetSpellTargetUnit()
    • Custom script: local real x1 = GetUnitX(Caster)
    • Custom script: local real y1 = GetUnitY(Caster)
    • Custom script: local real z1 = GetUnitFlyHeight(Caster)
    • Custom script: local real x2 = GetUnitX(Target)
    • Custom script: local real y2 = GetUnitY(Target)
    • Custom script: local real z2 = GetUnitFlyHeight(Target)
    • Set Units[1] = (Triggering unit)
    • Set HandleID = (Key (Triggering unit))
    • Hashtable - Save Handle OfUnits[1] as (Key Puppeteer) of HandleID in Hashtable
    • Unit Group - Add Units[1] to PuppeteerGroup
    • Set Units[2] = (Target unit of ability being cast)
    • Hashtable - Save Handle OfUnits[2] as (Key Puppets) of HandleID in Hashtable
    • Custom script: call AddLightningEx("DRAB", true, x1, y1, z1, x2, y2, z2)
    • Set Lightning = (Last created lightning effect)
    • Hashtable - Save Handle OfLightning as (Key PuppetString) of HandleID in Hashtable
    • Custom script: set Caster = null
    • Custom script: set Target = null
    • Trigger - Turn on PM Loop <gen>
As you can see, I used AddLightningEx for creating the lightning effect and it is perfectly normal but, for the part where I saved my "Lightning" variable, the save data returns a null value (the data loads a null value in the next trigger, making the lightning doesn't move/change position for 0.03 second per move), I also use the set udg_Lightning = bj_lastCreatedLightning to save data, but to no avail, it fails too

But, when I turn the AddLightningEx to the normal GUI function of creating lightning, this:
  • Lightning - Create a Chain Lightning - Primary lightning effect from source (Position of (Triggering unit)) to target (Center of (Playable map area))
The saved data, works (it is working in another trigger called "PM Loop")

So, what I'm trying to know/ask is, what is the function that can perform a save data to the Last Created Lightning ?

I think that AddLightning = Lightning - Create Lightning Effect, but AddLightningEx is different thing, right ?

So, what script should I write in order to save the last created lightning data for the AddLightningEx ?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
So, 2 actions in one line ?
Saving data, and at the same time, creates a lightning ?
F***ing cool JASS :)

Hmmm, are there any other problem that is the same as this one ?
I mean, saving data and at the same time, does action ?
How to identify when to use it ?

Btw, thanks :)
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Hmmm, are there any other problem that is the same as this one ?
I mean, saving data and at the same time, does action ?
How to identify when to use it ?
Consider functions that return something as values that those functions return. You can use a function that returns real like any real number.
Example: call SomeFunction(Function1(),Function2(),Function3())
Imagine SomeFunction requires 3 parameters, like a unit, an integer and a string.
If Function1 returns a unit , Function2 an integer and Function3 a string, it will work properly.
You can even do call Function1(Function2(Function3(Function4())))

In your case, though, we're just assigning a value that the function returns to a variable since AddLightningEx returns a lightning.
 
LOL
NEVER search BJ on google xD
You'd get all kinds of results xD

A BJ is a function written in Jass (Very slow most of the time)
A native is a function written in C++ (Very fast compared to BJs)

The fastest natives you can find:
GetUnitX
GetUnitY
GetWidgetLife
...

That's because if you somehow had the oppurtunity to look at the source code, you'd
find this:

JASS:
class unit
{
    double hp
    double mp
    double ang
    double x
    double y
    double maxhp
    double maxmp
    double movespeed
    double attackspeed
    double baseDamage
    double damageMin
    double damageMax
    int array abilities[123]
    ....

    double getUnitX(void)        { return x;  }
    double getUnitY(void)        { return y;  }
    double getWidgetLife(void) { return hp; }

    //.... and much more ^^ (WAY more)
    // The unit class is about 3 KB (or so I've heard)
};
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
GetUnitX -> GetWidgetX -> GetItemX -> GetDestructableX in terms of speed, according to benchmarks. Interestingly, GetUnitX is faster and GetItemX is slower though. Perhaps GetUnitX does its own thing and GetItemX is a wrapper for GetWidgetX. Could be. And the reason why GetUnitX would be faster in that case is because it's a shorter function name than GetWidgetX because we know shorter names execute a lot faster on the JASS-side.
 
Status
Not open for further replies.
Top