HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

CreateEffectsLine function

07-19-2007, 11:07 AM#1
deadlysheep_1
Hi. I made this function to let people easily be able to make a certain amount of effects from point a to point b. I know that there is another one somewhat like this in this site, but I especially like mine becauseit doesn't use any caches, handle vars or anything like that, so JASS newbies like me can easily understand the code and if they want, edit it easily. I know that some of the code isn't the best, for example the use of 1 or 2 BJ's, and the TriggerSleepActions, but since I am new to jass, I admit that I can't really fix this. I think that I got rid of most of the leaks, but please notify me if I have missed a couple.

I'm not sure if this section is the right place to post this, and move it if it is not.

Collapse JASS:
function CreateEffectsLine takes string whichModel, location start, location finish, integer amount, real time, real duration returns nothing
local string a = whichModel
local location b = start
local integer c = amount
local real d = DistanceBetweenPoints(start,finish)
local effect e
local integer f = 0
local real g = AngleBetweenPoints(start,finish)
local effect array h
local real i = duration-(time*amount)
set d = d/c
loop
exitwhen f == c
set e = AddSpecialEffectLocBJ(b,whichModel)
set h[f] = GetLastCreatedEffectBJ()
set b = PolarProjectionBJ(b,d,g)
call TriggerSleepAction(time)
set f = f+1
endloop
call TriggerSleepAction(i)
call RemoveLocation(start)
call RemoveLocation(finish)
call RemoveLocation(b)
set f = 0
loop
exitwhen f == c
call DestroyEffect(h[f])
set f = f+1
endloop
endfunction
Explanation of parametres:
string whichModel - the model of the effects being created
location start - the location where the effects start from
location finish - the location where the effects go to
integer amount - the amount of effects being created
real time - the amount of time between each effect being created, make this 0.00 is you want them all to be created instantly
real duration - how long the effects last before being destroyed
07-19-2007, 11:37 AM#2
CommanderZ
At least...you should nullify your handles. I also would be good idea to work with x/y coords rather than with locations where they are not necessary. Also remember, indentation is yor ally ;)

I reccomend you to work on this and try to improve it. You could learn a lot of things on it.
07-19-2007, 01:16 PM#3
xombie
Err.. you do realize that "TriggerSleepAction" is incredibly inaccurate, right? If somebody wanted to create effects every 0.15 seconds, TriggerSleepAction definitely would not be the one to do it.

This is why people use globals/cache/structs in coordinance with timers, because timers are infinity trillion times more accurate than TriggerSleepAction.

You should actually try setting values like 0.01 and see what you end up with -- guarantee you it won't be as pretty as you thought lol.
07-19-2007, 01:27 PM#4
Anitarf
A couple of things:
- indentation
- coordiantes instead of locations
- at least use PooledWait instead of TriggerSleepAction
- nullify local variables of handle type
- why duplicate the parameters?
- what if the user wants the effects to disappear one by one the same way they appear?
07-19-2007, 01:28 PM#5
DioD
trigger sleep may cause problems with ingame lag\pause.

you have yo use polledw8 or timers
07-19-2007, 10:57 PM#6
deadlysheep_1
Thanks for the feedback guys. A couple of things - What is indentation? And also, which of the handles haven't I nullified?

I will try to read a couple of tutorials about how to use polled waits, ExecuteFuncs and timers because as KaTTaNa pointed out to me, this function woul pause the calling function, which would most likely be an unwanted effect.

Quote:
- why duplicate the parameters?

What do u mean by this? Im still a jass newbie, so please explain.
Edit: Do u mean that the parametres make a local variable of themselves? So instead of setting the location b to the polar offset location, could I do:
set start = PolarProjectionBJ(.....)

Thanks again guys
07-20-2007, 12:03 AM#7
Beardo
Quote:
Originally Posted by deadlysheep_1
What do u mean by this? Im still a jass newbie, so please explain.
Edit: Do u mean that the parametres make a local variable of themselves? So instead of setting the location b to the polar offset location, could I do:
set start = PolarProjectionBJ(.....)
Thanks again guys

you said it exactly
thats the entire point of parameters

You can do

Collapse JASS:
set start = PolarProjectionBJ(ImAVariableThatWasAParameter)
07-20-2007, 12:12 AM#8
Earth-Fury
indentation is this:
Collapse JASS:
function abc takes integer i returns integer
    local integer k = i - 5
    return 54 + k
endfunction

versus without indentation:
Collapse JASS:
function abc takes integer i returns integer
local integer k = i - 5
return 54 + k
endfunction

always indent.
07-20-2007, 12:41 AM#9
ClichesAreSt00pid
You should use 2 spaces instead of 4 when indenting. I hate that 4-space indenting, it shoves all the stuff way off to the side with if/then statements etc..
07-20-2007, 12:49 AM#10
Anitarf
Perhaps you are using too many nested if/then statements?

Quote:
Originally Posted by deadlysheep_1
Do u mean that the parametres make a local variable of themselves?
Yes, parameters are effectively local variables. There's no need for local integer c = amount, you can use amount instead of c throughout the function.
07-20-2007, 06:42 AM#11
Ammorth
Quote:
Originally Posted by ClichesAreSt00pid
You should use 2 spaces instead of 4 when indenting. I hate that 4-space indenting, it shoves all the stuff way off to the side with if/then statements etc..

One persons opinion, yet the majority of programs that involve JASS use a 4-indent system, and most of the code on this web page is 4-indent. I would suggest sticking to the majority, so the majority of people are not annoyed with it.

Indenting also makes the code easier to dissect and see what happens where.
07-20-2007, 07:45 AM#12
deadlysheep_1
Thanks all. I thought before that using the parametres just gave you a value that stayed the same all the time, and that you couldn't modify the parametres values. I get what indentation is now. Thanks all for the help. I will now start trying to learn how to use ExecuteFunc and Local Handle Vars so that I can make this function more accurate with the waits, and so that it doesn't pause the calling function. +rep to all of u who helped
07-20-2007, 08:39 AM#13
zen87
Quote:
Originally Posted by deadlysheep_1
I know that there is another one somewhat like this in this site

does that mean my effect sys ? well actually i think it is really easy to use... as long as u can understands how to use caster system i dun think newbie have any problem with using the effect system