• 🏆 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!

[JASS] Help, just a simple missile

Status
Not open for further replies.
Level 10
Joined
Sep 20, 2012
Messages
117
So I was trying to do a simple missile in JASS, you know, get cast position, create a dummy and move it to the target of the spell. But here comes the problem, I've tried doing it with loop + waits, didn't end well as you might suspect. Waits are really inconsistnet and setting them to 0.03 doesnt make them 0.03 at all. Tried with calling timers in a loop, but entering a function doesnt allow to pass parameters, so the move function doesnt know the caster and it's position, nor the spell target. Any help? Or any actual code, so I could do some reverse engineering on that?

It really seems simple to do in GUI. Not so simple in JASS, or maybe I've missed something.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
There exist many GUI and GUI-friendly missile handling systems in the spell section.

A basic missile launched when a spell is cast can be done by using the Sphere ability, though it will launch that missile for every ranged spell from that unit.

Coding a missile system is one of those projects everyone wants a shot at, which is why we have so many: everyone thinks theirs is the best.
 
Level 7
Joined
Oct 19, 2015
Messages
286
The main issue, as you have already noticed, is that we are not able to pass local variable information to the timer callback function. We solve this by "attaching" the data to the timer. We do this by storing the information in a global data structure, using the unique handle id of the timer as an index to avoid conflicts. Since handle ids are too large to be used as array indexes, the global data structure that we most often use for this purpose is a hashtable.

However, we mostly use this approach for timers with a longer duration. For fast periodic timers, we usually do not attach each instance to its own timer, but instead use a single timer that then loops through a list of all instances in its callback. This approach is more efficient, however we can only use it for fast periodic timers because on long timeouts, the inaccuracy of the first update would become noticeable.

That being said, the easiest and most sensible thing to do is to just use a missile system. Hive has plenty to choose from, while here is my favourite (requires vJass).
 
Status
Not open for further replies.
Top