HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Arrays and Code

02-24-2009, 09:56 PM#1
Blacktastic
I was curious as to what the most efficient way to make an array of functions? I am working on a Casting System with castbars and I planned to use a timer to call a function for the actual spell affect. I would assign each spell an ID and then call a function from an Array with the same index as the ID, but I have never made a code array before. Any help?

To give more information, I simply need something where I can store functions inside of an Array. I can use attached tables to store all the data I need, I just simply need a way to store a function. Driving me bonkers.
02-24-2009, 11:12 PM#2
Blackroot
Expand JASS:

Read this if you don't understand the code: \/

http://www.wc3c.net/showthread.php?t=103408
02-25-2009, 01:09 AM#3
Blacktastic
Awesome, this is exactly what I need.

If a spell takes a point target, and I use GetSpellTargetUnit(), will that return null? Trying to make a function that will return a boolean as to whether it takes a point or unit target. Once I have that I believe all the pieces I need will be complete.


To give some further insight, the reason I need the point/unit target function is because I am going to be attaching a Table to a unit whenever it learns a spell. The table will be named EXACTLY what the spell is. All the data for the spell is passed to that table. Upon the spell being cast, I can recall the table since the spellname is exactly what the table is labeled. I will do the casttime, and then the table will have an ID number that will correspond to the SL index that will hold it's function. This function is what will play the graphic and do the damage.
02-25-2009, 01:28 AM#4
Av3n
It should I believe since point target spells don't target units.

-Av3n
02-27-2009, 04:49 AM#5
Blacktastic
Ok, first off. This is the first piece of code I have that I am posting on here. I have several questions.

1) Removed

2) Notation. I believe I have decent notation. I know I comment well, so at least there is that. If you cannot help me with the function interface question, please assist me in bettering my notation so the next pieces of code I write are legible.

3) Inefficiency. Once again, if you cannot assist with number 1, please point out any type of inefficiency I have in this code so I can better it and in turn better my coding skills.


Explanation: What this code does is upon any type of spell being cast, it calls CastSpell. This function creates a struct for all neccisary data, and displays a cast bar and a Spellname + ( + Timeleft + ) to make it look real nice. Upon Castime ending, it calls a function from the function interface, which corresponds to the spell being case (The Id variable defines this).


Please note this is NOT FINISHED. I need to add in OrderID's to check if the unit interupts the cast still, and I need to finish the loop. However I wanted this checked out beforehand so I can get the function interface problem solved.

References:
CSData
CSSafteyCache
Intuitive Damage Detection System
TimerUtils (Blue)

Expand JASS:

Edit: Discovered I can highlight the problem. Awesome.
02-27-2009, 05:54 AM#6
Blackroot
Quote:
Expand JASS:
Function interfaces are not equivalent to code. This is all you have to do:

Expand JASS:

Your actual code is almost impossible to read; you indent fine but you don't space out related blocks of code [which I'd suggest].
02-27-2009, 06:14 AM#7
Blacktastic
Problem with that is I can't pass any relevant data to that.

Although I could just make the FI take arguements eh?

Oi

and it is spaced out isnt it?
02-27-2009, 06:25 AM#8
Blackroot
Quote:
Originally Posted by Blacktastic
Problem with that is I can't pass any relevant data to that.

Although I could just much the FI take arguements eh?

Oi

and it is spaced out isnt it?

I don't know what you mean 'spaced out'?

Use globals to pass the data you need between the timer and the function.
02-27-2009, 06:36 AM#9
Blacktastic
Your the one that told me my code isn't spaced out :p.

And is it safe to set them to globals despite many people may be using the functon?
02-27-2009, 07:02 AM#10
Blackroot
Since there's no pause between setting the variables and the execution; you'll be ok.

What I meant by 'space out'; your code looks like this:

Expand JASS:

There's no way to tell when the global block ends and the next part begins; without reading the comments. Also; you can't tell what segments of code are doing; because they're all together. Basically; where you have comments you should also add a whitespace to seperate, for legebility.
02-27-2009, 07:19 AM#11
Blacktastic
Ah, ok. That makes sense.