HeroEngine Forums

HeroEngine Support => Scripting & Programming => Topic started by: Arlohian on Mar 11, 12, 04:52:21 PM

Title: [Resolved] Problems with implementing DoT functionality to abilities
Post by: Arlohian on Mar 11, 12, 04:52:21 PM
Updated! (again)
Greatings fellow coders,
Im having some problems with implementing Dot/Hot functions to abilities (a function that ticks at a given interval for given ammount of time, doing some action)

I succesfully added my new ability to my action bar and such, yet im having problems with the tick function, it would appear that it does not recieve the 5 parameters it needs to execute sucessfully.

I would be very greatful for any help/pointers on how to solve the problem, I have been scouring the forums and the wiki but unable to find a solution


Im using about the same basic build you get with your herocloud(so its "clean" but not "truly clean").
Where "W_ab_Rejuvenation" is a field of type timer, in the genericTimer class.

abEffects
Code: [Select]
shared function ApplyTimeHeal(owner as NodeRef of Class E_CommonCharacter, target as NodeRef, ability as NodeRef of Class E_Ability, Heal as Integer, duration as TimeInterval, tick as TimeInterval)
  where target is kindof E_CommonCharacter
   timer as NodeRef of Class genericTimer = CreateNodeFromClass("genericTimer")
   timer.W_ab_Rejuvenation.fireRate = tick
   timer.W_ab_Rejuvenation.script = abEffects
   timer.W_ab_Rejuvenation.start()
   .
   target.AdjustHealth(1 , owner, ability, false, false) // just here instead of a println() statement
.
Code: [Select]
shared function W_ab_Rejuvenation_tick(owner as NodeRef of Class E_CommonCharacter, target as NodeRef, ability as NodeRef of Class E_Ability, heal copies Integer, duration as TimeInterval)
 target.AdjustHealth(2 , owner, ability, false, false) // just here instead of println() statement
 
 where me is kindof genericTimer
  if (me.W_ab_Rejuvenation.elapsedTime <= duration)

   //we do some calculations here

    // apply damage
    target.AdjustHealth(heal , owner, ability, isCritical, isGlance)
  .
  me.W_ab_Rejuvenation.stop()
 .
.

abRejuvenation
Just the part that executes the script that does anything
Code: [Select]
shared function ApplyEffects( owner as NodeRef of Class E_CommonCharacter, target as NodeRef, ability as NodeRef of Class E_Ability )
  abEffects:ApplyTimeHeal(owner, target, ability, GetHeal(), GetDuration(), GetTick())
 .

Thank you in advance!
Title: Re: Problems with implementing DoT functionality to abilities
Post by: FI-ScottZ on Mar 12, 12, 12:05:57 AM
I'm guessing you have many script errors happening?  (Check the Script Error panel)

The first thing that is confusing is that you're assigning the results of a tick function to the script field of the timer.  That makes no sense.  Perhaps you intend to have a function that determines which script to use based on the arguments passed in, but that does not explain why it would call itself recursively.  And it certainly would not be the tick function.

For the script field, unless you intend to use different scripts determined at run-time, just hard code the name of the script (I believe that it is preferred to specify scriptRef literals without quotation marks).  If the tick function is to be in abEffects, then everything after abEffects in that line should be deleted.

Next, the tick function should not call itself.  Recursing itself can cause all sorts of strange problems. It also should not create a new timer.

Overall, I am not certain what it is you are trying to perform.  If, as you said, a block of code should be executed 2 seconds apart for 6 seconds you are close, but need some adjustments.

I presume the block of code to execute is the parts about the damage possibly being glancing or possibly being critical, then regardless it gets applied.

Q: Do you want the damage to happen right away when the timer begins, or would the first time be 2 seconds after the timer starts?
Title: Re: Problems with implementing DoT functionality to abilities
Post by: Arlohian on Mar 12, 12, 08:30:41 AM
Thanks for the response!
I updated the code a bit, after your recomendation.
Also, i dont have any script errors happening (yet its still not working) and thats whats bugging me  :(
I fixed the scriptref wierdness, removed the unessary calculations for crit/glance from the post.

Now instead my tick wont activate and the ability just keeps saying its in progress, i believe that the timer does not know what function to use, or possibly that the function is not getting the parameters it needs. Wiki doesnt seem to have as detailed info as i would need, im not a very seasoned programmer and im still learning.

Ive tried to put println("this works") statements everywhere but it never works?.. very strange, not even on abilities that do sucessfuly execute as intended.

I will try to explain better what my goal is, everything not implemented yet ofc.
1. an ability triggers by pressing a key or gui element with the mouse. (done and working)
2. function taking in target, heal ammount etc, is triggered.
  2.1. the timer is unique to the target, allowing several targets at once to have the effect, with different durations, yet only 1 stack at a time (recasting refreshes the timer).
3. the functions tick is repeated once every 2 seconds(starting at time 0) for 6 seconds, healing the target.
Title: Re: Problems with implementing DoT functionality to abilities
Post by: JMurdick on Mar 12, 12, 08:49:18 AM
If you look at this wiki page:  http://wiki.heroengine.com/wiki/Timer

Notice that the name of the function being called is the <timer_name>_tick().  Looking at your code examples makes me wonder if the timer in ApplyTimeHeal is being treated as a local variable and thus does not have scope beyond that function (hence, the other script cannot be called).  I'd recommend doing it the way you see in the wiki, place a timer onto the Effect class and instantiate that class and when its instantiated thats when you setup the timer and callback.
Title: Re: Problems with implementing DoT functionality to abilities
Post by: Arlohian on Mar 12, 12, 09:47:27 AM
Thanks, i did use that wiki page and did pretty much the same as i did before chaning some stuff, but now somehow when i did it again, atleast my function is beeing triggered. I also altered the code a bit again.

I think ive found the problem for sure this time, there appears to be besides "game chat" and console there is a "chat" that you open from "window". There it now clearly states(and spams indefenetly):

parameters passed (0) does not match the number accepted by this function (5)
03/12/2012 14:44:29 UTC
Call trace:
  Script abEffects line 68 me[9223372056119131553]
starting method/function W_AB_REJUVENATION_TICK
starting me[id=9223372056119131553 class=genericTimer]

Finally i know for sure what the problem is :D


Now the question remains how to pass my parameters to the tick function?
Title: Re: Problems with implementing DoT functionality to abilities
Post by: JMurdick on Mar 12, 12, 11:31:12 AM
In the wiki example the class itself could store the data since its instantiated with whatever data you need.   And therefore the timer which is a part of the class (node) can retrieve that data.
Title: Re: Problems with implementing DoT functionality to abilities
Post by: FI-ScottZ on Mar 12, 12, 01:42:21 PM
Getting closer.  For one thing, you would want "me.W_ab_Rejuvenation.stop()" to only happen if the elapsed time is > 6 seconds, so that should be under "else" from the check of being <= 6.  Otherwise it stops every time.

And yes, as you deduced, the tick function has a pre-defined signature (list of parameters and return) that it must have which cannot be deviated from.

As for getting data, you have a few options.


Whichever method you use, you want to be sure to clean up the timer when done with it.  If it was created as a new node, be sure to destroy it; if it was glommed onto a node, then remove that class from the node.  Either method should stop the timer as a side-effect, but you may wish to manually stop it, as well, as soon as you no longer need it.
Title: Re: Problems with implementing DoT functionality to abilities
Post by: Arlohian on Mar 12, 12, 07:40:49 PM
That should work! I feel silly for not thinking of it right away. Thanks a lot to both of you . :D

Will try it out once the servers are back up, currently in maintence  :'(
Title: Re: Problems with implementing DoT functionality to abilities (solved)
Post by: Arlohian on Mar 13, 12, 12:26:57 PM
Yep works perfectly now!  ;D Thanks a lot to both of you once again!

I used the solution to put the values of target and the other things i needed to send to _tick() into a class with the corresponding fields. Then just using the fields from that class instead of input values from function header. Seemed like the simplest way of doing it.