• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Making a Fade Unit Function

Status
Not open for further replies.
Level 6
Joined
Nov 24, 2012
Messages
218
Hello Hive, I need major help in making a vJass function.
I am very new to vJass. This does not work at all... can anyone enlighten me?
Okay I know TriggerSleepAction and BJ are bad, but if I were to make it periodic would I use a timer or something?
Let's say I wanted the fade to be extra smooth instead of +20% transparency at a time, how would I do it without 100 TriggerSleepActions (and without Timer systems)?

JASS:
scope
function Fade takes unit returns nothing
    call SetUnitVertexColorBJ( unit, 100, 100, 100, 20.00 )
    call TriggerSleepAction (0.25)
    call SetUnitVertexColorBJ( unit, 100, 100, 100, 40.00 )
    call TriggerSleepAction (0.25)
    call SetUnitVertexColorBJ( unit, 100, 100, 100, 60.00 )
    call TriggerSleepAction (0.25)
    call SetUnitVertexColorBJ( unit, 100, 100, 100, 80.00 )
    call TriggerSleepAction (0.25)
    call RemoveUnit(unit)
    return false
endfunction
endscope

What I want is to write this line to make a certain unit fade away, and ultimately be removed:

JASS:
call Fade(unit)

The Fade thing is sort of like a system, so would I put it in a library?
What are library and how/when to use specifically?
 
The problem is ur returning nothing with the function but inside the function ur trying to return a Boolean. U should get rid of all the bjs

For scopes and libraries the syntax is very close. Systems should be in libraries. Here is the syntax

scope test initializer function name

The initializer will run on map init. This is used to create and register triggers.

Libraries are declared like this

library test initializer function name

Libraries can require other libraries tho

They do so like this

library test requires library name initializer function name
 
Level 6
Joined
Nov 24, 2012
Messages
218
Okay so since this is a System, would I wrap this around Library tags?
I'm still so confused how to call a unit to fade away :(.

This is my new one but it still doesn't work

JASS:
library Fade

function Fade takes unit u returns nothing
    call SetUnitVertexColor(u, 100, 100, 100, 20)
    call TriggerSleepAction (0.25)
    call SetUnitVertexColor(u, 100, 100, 100, 40)
    call TriggerSleepAction (0.25)
    call SetUnitVertexColor(u, 100, 100, 100, 60)
    call TriggerSleepAction (0.25)
    call SetUnitVertexColor(u, 100, 100, 100, 80)
    call TriggerSleepAction (0.25)
    call RemoveUnit(u)
endfunction

endlibrary


I use custom script in my GUI trigger:
JASS:
call Fade( GetLastCreatedUnit () )

Didn't work!
 
Level 6
Joined
Nov 24, 2012
Messages
218
There are dummy units created periodically while the hero casts a dashing spell.
They are afterimages that do nothing but visual effect left behind the hero's dashing trail.
I want them to fade away slowly and disappear.
I tried generic expiration timer but then they die and play death animation, plus that doesn't fade it gradually.
I want to be able to create the dummy unit then call a function to fade it.
Okay, a repeating countdown timer? I could try that and post back later ?
I have no idea how to start it though xD.
 
I never ran into that problem. I always used timers.
*sigh* no offense, but really, you always try to "fix" stuff for people that is not even broken (Like replacing scope with library or removing the BJs ... people DO NOT CARE about such optimizations when the script itself is not being fixed by that). Stop that. Like, really!
 
*sigh* no offense, but really, you always try to "fix" stuff for people that is not even broken (Like replacing scope with library or removing the BJs ... people DO NOT CARE about such optimizations when the script itself is not being fixed by that). Stop that. Like, really!

Lol u should reread what he asked help with. Then complain about how I decide to help ppl.
 
Lol u should reread what he asked help with. Then complain about how I decide to help ppl.
Just that it didn't fix the problem.
It's not just this thread.

Whenever someone asks for help, you rush to assistance (which is a good thing!), but then you look over it, point out issues that are none, improve performance issues that make no sense (as if a replacement of a BJ would actually make a difference in a case like this?) and - which is the most horrible thing about it - spread sciolism.

It's okay to tell people how to improve performance, really. It's crucial, people are meant to learn something from this. However, first priority should always be to fix the actual problem the poster has, not increasing performance. And you often forget about that.

@ TO: the most simple way to do it would be this (if you use SetUnitVertexColor instead of the BJ, remember that the numbers are 0-255, not 0-100).

JASS:
library Fade

globals
 private constant hashtable HASH = InitHashtable()
 private constant integer ALPHA_PER_TICK = 2
 private constant real UPDATE_INTERVAL = 0.2
endglobals

private function Update takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local integer id = GetHandleId(t)
 local integer alpha = LoadInteger(HASH, id, 0)-ALPHA_PER_TICK
 if alpha > 0 then
   call SetUnitVertexColor(LoadUnitHandle(HASH, id, 1), 255, 255, 255, alpha)
   call SaveInteger(HASH, GetHandleId(t), 0, alpha)
 else
   call FlushChildHashtable(HASH, GetHandleId(t))
   call DestroyTimer(t)
 endif
 set t = null
endfunction

function Fade takes unit u returns nothing
 local timer t = CreateTimer()
 call SaveInteger(HASH, GetHandleId(t), 0, 255)
 call SaveUnitHandle(HASH, GetHandleId(t), 1, u)
 call TimerStart(t, UPDATE_INTERVAL, true, function Update)
 set t = null
endfunction

endlibrary

EDIT: Using a dedicated hashtable for this is overkill. I highly recommend using just one single global non-private hashtable called HASH and remove the line in the library globals that initializes it.
 
Thanks Death! I remember last year I was so ahead of you on Jass stuff even though I was a newbie at that time XD. Argh, I only took a year off and now you're way up there XD.

i havent spent a yr on this yet lol. almost done.


@ zwiebelchen
i did point out what i thought was the problem

his scope name wasnt there and the function was returning something when it wasnt supposed to. then i said about the improvements.

edit: testing system now
 
well its better to actually fix it first...

BTW, you should post all the triggers that has to do with this so that we can figure out what's wrong...

Also please describe the problem more... What do you mean by it didn't work? Does it not work at all or does it go instantly into the remove unit part?
 
Level 6
Joined
Nov 24, 2012
Messages
218
@Adiktuz: The other part of the trigger is just me creating some units one at a time and then I used custom script right after creating each unit " Call Fade(GetLastCreatedUnit()) " The problem I believe was that it was not working at all.

Thanks Zwiebel :) Tested it, it works!
Ty for example on how to use hashtables, those always confused me even in GUI.
I haven't thoroughly gone over the Fade library yet, which I will do so now.

Edit: @Zwiebel's recommendation, do you mean like I go in variable editor and make one, so like udg_HASH?

Thanks death too! If death put up another version... I'll study it lots too
 
here u go bud i uploaded a test map with the fade system in it to see it in action just press the ESC button. the unit will be spawned at middle of map and immediately begin to fade.

add the unit using the FadeUnit function it takes a unit

you can change the fading rate by changing the
JASS:
private constant real FADE_RATE = 0.25
that one is the constant so use that as the most common fade variable.

if u want to change it manually call the ChangeFadeRate function it takes a real variable.
note: it only changes the last indexed unit. u can change this if u want to use hashtables or bribes Table.
 

Attachments

  • fade unit system.w3m
    16.5 KB · Views: 43
@Adiktuz: The other part of the trigger is just me creating some units one at a time and then I used custom script right after creating each unit " Call Fade(GetLastCreatedUnit()) " The problem I believe was that it was not working at all.
This should work. Try it with the library above.
However, you still need to kill the dummy units after they faded out.
Either add a lifetimer to them, give them negative health regen or add
call RemoveUnit(LoadUnitHandle(HASH, GetHandleId(t), 1))
right after the "else".

Edit: @Zwiebel's recommendation, do you mean like I go in variable editor and make one, so like udg_HASH?
Yes. You just need to rename all instances of "HASH" to "udg_HASH" then. Also, you must set the initial value of udg_HASH in the variable editor, so that it's not null.
 
well its better to actually fix it first...

BTW, you should post all the triggers that has to do with this so that we can figure out what's wrong...

Also please describe the problem more... What do you mean by it didn't work? Does it not work at all or does it go instantly into the remove unit part?

i like to just point everything out at once. if the OP wants to fix it then make it more efficient thats their choice.
 
Thanks deathismyfriend, testing the fade unit system.
Although I received 2 systems, they are totally different.
Yours has no hashtable :)
This will be very helpful for me,

Thanks zwiebelchen, added RemoveUnit and created udg_HASH.

np it can easily be made with hashtables as they are good to use i just prefer indexing a little bit. you shouldnt need to use any udg's tho since u are using vJass. im guessing its a JASS system ?
 
you shouldnt need to use any udg's tho since u are using vJass. im guessing its a JASS system ?
It's fine to have a hashtable declared in variable editor, as he obviously also wants to use GUI in his map and only GUI created tables can be accessed with the GUI editor.
 
Status
Not open for further replies.
Top