• 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.

Issues with some code.

Status
Not open for further replies.
I've been having some issues with my code for the "Floating Text Kills System"
I'm changing it JASS/vJASS, but for some reason, the floating texts won't show up in game D:

Here's the code:

JASS:
library FTKS initializer InitFTKS
//************************************************************************
//                  Floating Text Kills System v2.0.0
//
//                             Created by:
//                            Magtheridon96
//
//                          Written in: vJASS
//
//                      [url]www.hiveworkshop.com[/url]
//************************************************************************
//
//************************************************************************
//
//      This system was created on January 30, 2011.
//
//      To implement the system, simply go to the "Implementation"
//      section of the Documentation and follow the given instructions.
//
//      If you find any bugs, exploits, leaks, or problems in general,
//      please report them to me at [url]www.hiveworkshop.com[/url]. Suggestions
//      and "gentle" constructive critisism would be appreciated.
//
//      Remember to give credit to me (Magtheridon96) if you implement
//      this system into your map.
//
//************************************************************************
//
//************************************************************************
//
//
//                                Changelog
//
//  Last Updated: April 9, 2011
//
//  *** v1.0.0 ***
//  Release of Floating Text Kills System
//
//  *** v1.1.0 ***
//  Fixed some leaks
//  Added new strings
//  Gave system a bit of intelligence (It's still stupid anyways :P)
//
//  *** v2.0.0 ***
//  Completely rewrote the system in vJASS
//  Changed version numbers =P
//
//************************************************************************
//
//************************************************************************
//
//                             Implementation
//
//  1- Create a new trigger
//  2- Click Edit -> Convert to Custom Text
//  3- Copy all the contents of this trigger into your trigger
//  4- Enjoy :)
//
//************************************************************************
//
//************************************************************************
//
//                              Modifications
//
//  This system is just begging for user modifications.
//  I gave you samples of strings you can use as floating texts.
//  Feel free to modify them, and in rare cases, if your map has
//  completely different player colors, feel free to change the
//  Player Color variables.
//
//************************************************************************
    globals
        // The Kill Strings
        private     constant    string  array   KS
        // The Player Colors
        private     constant    string  array   KC
        // How many strings correspond to a hard kill?
        private     constant    integer         SH              = 5
        // How many strings are there?
        private     constant    integer         MAX_STRINGS     = 10
        // What do you consider as "High HP" in your map?
        private     constant    real            HIGH_HP         = 2000.00
        // Does the system work for heroes and ONLY heroes?
        private     constant    boolean         ONLY_FOR_HEROES = false
        // The lifespan of the floating text
        private     constant    real            TEXT_AGE        = 2.50
        // The fading age of the floating text
        private     constant    real            TEXT_FADE_AGE   = 1.75
        // The size of the floating text
        private     constant    real            TEXT_FONT       = 8.00
        // The velocity of the floating text
        private     constant    real            TEXT_SPEED      = 64.00
        // The angle of the floating text
        private     constant    real            TEXT_ANGLE      = 90.00
    endglobals
    
    private function Settings takes nothing returns nothing
        //======================================
        // Strings that correspond to hard kills
        //======================================
        set KS[1] = "PWNED"
        set KS[2] = "OWNED"
        set KS[3] = "ULTRA KILL!"
        set KS[4] = "EPIC!"
        set KS[5] = "AWESOME!"
        //======================================
        // Strings that correspond to easy kills
        //======================================
        set KS[6] = "NOOB!"
        set KS[7] = "lol"
        set KS[8] = "Omg"
        set KS[9] = "Ouch :/"
        set KS[10] = "HEY!"
        //==============
        // Player Colors
        //==============
        set KC[1] = "|cffff0303"
        set KC[2] = "|cff0042ff"
        set KC[3] = "|cff1ce6b9"
        set KC[4] = "|cff540081"
        set KC[5] = "|cffffff01"
        set KC[6] = "|cfffe8a0e"
        set KC[7] = "|cff20c000"
        set KC[8] = "|cffe55bb0"
        set KC[9] = "|cff959697"
        set KC[10] = "|cff7ebff1"
        set KC[11] = "|cff106246"
        set KC[12] = "|cff4e2a04"
        set KC[13] = "|cffffffff"
        set KC[14] = "|cffffffff"
        set KC[15] = "|cffffffff"
        set KC[16] = "|cffffffff"
    endfunction
    
    private function CreateFT takes integer i, integer i2 returns nothing
        local   unit        u       = GetTriggerUnit()
        local   player      p       = GetOwningPlayer(u)
        local   integer     pi      = GetPlayerId(p)
        local   texttag     tt
        local   real        v
        local   real        x
        local   real        y
        //===============================
        // We create the floating text
        //===============================
        set tt = CreateTextTag()
        //===============================
        // Here, we set:
        //
        //    -Text
        //    -Text Age
        //    -Text Fading Age
        //    -Text Position
        //    -Text Permanency
        //    -Text Font
        //===============================
        call SetTextTagAge(tt, TEXT_AGE)
        call SetTextTagText(tt, KC[pi+1] + KS[GetRandomInt(i, i2)] + "|r", TEXT_FONT)
        call SetTextTagPosUnit(tt, u, 100.00)
        call SetTextTagFadepoint(tt, TEXT_FADE_AGE)
        call SetTextTagPermanent(tt, false)
        
        //===============================
        // Here, we give the floating
        // text it's velocity.
        //===============================
        set v = TEXT_SPEED * 0.0005546875 // Don't ask :P
        set x = v * Cos(TEXT_ANGLE * bj_DEGTORAD)
        set y = v * Sin(TEXT_ANGLE * bj_DEGTORAD)
        call SetTextTagVelocity(tt, x, y)
    endfunction
    
    private function execFTKS takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real hp = GetUnitState(u, UNIT_STATE_MAX_LIFE)
        local integer i = 1
        
        if (ONLY_FOR_HEROES) then
            if IsUnitType(u, UNIT_TYPE_HERO) and hp <= HIGH_HP then
                call CreateFT(1, SH)
            else
                call CreateFT(SH + 1, MAX_STRINGS)
            endif
        else
            if hp <= HIGH_HP then
                call CreateFT(1, SH)
            else
                call CreateFT(SH + 1, MAX_STRINGS)
            endif
        endif
    endfunction

    private function InitFTKS takes nothing returns nothing
        local trigger t
        local integer i = 0
        
        set t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
        call Settings()
        call TriggerAddAction(t, function execFTKS)
    endfunction
endlibrary

Please help :(
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
private constant string array KS
private constant string array KC

The arrays are constant (null arrays) and you attempt to set them to a value. This is invalid as a constant can not be assigned a new value (read only).

JASS does not support constant arrays as you have no constant array constructor that languages like C have.
In C you declare a constant array like this.
const signed int WTF[5] = {1337,911,247,118,999};
In Java...
static int[] WTF = {1337,911,247,118,999};

but in Jass...
constant integer array WTF

There is no ability to assign it on decleration and as such constant arrays will not work. Just use normal arrays instead.

Ok forget all the above if it magically works but it technically should not.

The actual reason for your problem is...
private constant real TEXT_FONT = 8.00
Why are you creating text that big?! Do you even realise how big text of size 8 is?

Let me put it this way, text of size 1 has a single letter take up most of the screen. Thus you have text which is approximatly 8 times bigger than the screen itself.

Do not worry, this is not your fault and I even made it once. It is none other than the fault of GUI as they use a converter function before passing the "font size" to the native.
function TextTagSize2Height takes real size returns real
return size * 0.023 / 10
endfunction

Thus try this instead.
private constant real TEXT_FONT = 0.0184

You should hopefully see something (if the constant array stuff is not causing problems).
The reason nothing shows is probably due to some clipping algorthim or chance (just happens to be a space at that part)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
In Java...
static int[] WTF = {1337,911,247,118,999};

Actually the keyword for constant in Java is not static, its final. Static has similar functionality to that of the static keyword in vJass.

It would be:

Code:
final int[] arr = {1, 2, 3, 4, 5, 6};

Just to be picky (static would cause an error compiling).
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Just to be picky (static would cause an error compiling).
No it would not, you clearly do not know java.

And yes I just tried it right now and it compiled perfectly.

I agree though that it should be final but it must also be static unless the constant is only constant for a specific instance of the class.

static means that the variable is global as opposed to an instance variable. This means it can be referenced without being passed (or invoked on, whichever you prefer) by an instance of the class.

What I did however was to create a non constant static array of size 5 with those initial values loaded into it. This means that the value or even the array referenced by the variable could be changed at anytime during the program.

Adding final to it would however prevent it from being modified.

Thus it should be....
final static int[] WTF = {1337,911,247,118,999};
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
What I was saying is that the static keyword alone does not make a constant variable in Java. You need to have the final keyword.

In Java...
static int[] WTF = {1337,911,247,118,999};

If you were to use this in Java you would not have a constant array. You would simply have a global one.

Java is really dumb though; even if you declare a variable as static final (array variable) you can still modify its indexed members without having a compile error of any kind.

If you declare a non-array variable as final it will function as a constant. You do not need the static keyword to do this.

In other words...

Code:
public class JavaDoc {
	public static void main (String[] args) {

		final int	A		= 4;
		final int[] B		= {5, 6, 6, 6, 5};

		System.out.println( A );
		for (int i = 0; i < B.length; i++)
			System.out.println( B[i] );

		A = 5;
		B[2] = 9;

		System.out.println(A);
		for (int i = 0; i < B.length; i++)
			System.out.println( B[i] );

	}
}

The only syntax error that arises here is setting A to 5, under the conditions that A is declared as a final and cannot be modified. On the other hand, Java doesn't seem to realize that I am modifying a constant array. In neither of these cases is the static keyword necessary.

No it would not, you clearly do not know java.

Well it entirely depends where you declare it. You did not specify at all and as such you have absolutely no right to tell me what I do and do not know about Java. If you declare the static variable inside a method you're going to get a compile error, so what I said was true.

If my understanding of Java is not sufficient enough for you then perhaps you should think twice when you say that static int[] WTF is going to give you a constant variable. It won't. No matter where you define it. You need the final keyword.

Thus it should be....
final static int[] WTF = {1337,911,247,118,999};

This still would not produce an unmodifiable integer array. You would still be able to modify the indexed members, as I show above (and it gives no compile error, and executes the program as if final were not even there.

you clearly do not know java.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
That is because arrays are objects in java and as such you will not be able to change the array object pointed at but still alter the contense of the array.

You should still declare them as final static variables to imply the constant holds for all instances of the class. Otherwise it might only be constant within each specific instance (instance variables instead of class).

you clearly do not know java.
Well, you deffinatly did not sound like you did in the orignal post. Additionally you seem to be lacking understanding of static variables and their need but I do admit that I was wrong about the final part. I guess that is what happens if you are studying C and Java at the same time and take a break from using them.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well as far as implementation I am familiar with most of what the Java syntax has to offer. There is also an uncanny resemblance to the static keyword in vJass and the static keyword in Java (though mechanically they are far different) - the concept is fairly simple.

That is because arrays are objects in java and as such you will not be able to change the array object pointed at but still alter the contense of the array.

Yea. Java is also really crappy with the protected keyword if I remember correctly.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Protected reduces the scope of the variables to only itself, classes in the same package and classes which extend that class. What is crappy about it?
If you want something only usable by that class, use private.
If you want a variable only usable in the package (thus the class as well), use no scope idenftifier
If you want a variable always usable, use public.

Vjass is a pesudo language made up by people prety much to best suit them. It also compiles down to pure JASS so all its OO support is only skin deep.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
In theory its all sunshine and rainbows, but I've definitely had problems before where the protected keyword was allowing access to members in a scope that should not have had access to the protected members.

classes in the same package and classes which extend that class

I think I've also had problems with this (classes in the same package not so much), but when you are dealing with classes outside of the package that extend the class with protected members I remember having problems. I think last time I did this it restricted my access to those protected members, though my memory of such Java exercises is cloudy.
 
Status
Not open for further replies.
Top