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

[JASS] Need help with structs thistype

Status
Not open for further replies.
Level 18
Joined
Jan 21, 2006
Messages
2,552
I'm not quite sure what you're trying to use it for. The type thistype is used as a "placeholder" for the label of the encapsulating struct. In your example thistype would simply be a dynamic way of saying StructName, with the added bonus that if you happen to change your struct name the identifiers that you used throughout the struct will still work without you having to change anything.

The actual value, this, refers to this struct instance. It should only really be used in instance-methods - while you can still declare a variable outside of an instance with the name "this" it can cause more confusion than necessary since vJass has special syntax modifiers when there is a variable named "this".

JASS:
struct VeryLongAndAnnoyingStructName

    integer a
    integer b
    integer c

    method doSomething takes nothing returns nothing
        // Inside this method you will be able to use "this" to refer to what was referred to in
        // "static method create" as "d". In order to call an instance-method we need an instance,
        // and that instance is what we refer to as "this".
        set this.a = 5
        set this.b = 5
        
        // If there is an unambiguous variable named "this" then you don't need to type it out, 
        // instead just do:
        set c = 6
        set a = 5   // These values won't change from what they were above.
        set b = 5
    
    endmethod
    static method create takes nothing returns thistype // notice how i use it instead of "VeryLong..."
        local thistype d = allocate()   // don't declare variables named "this" - it just makes the code 
                                        // harder to read.
            set d.a = 0
            set d.b = 1
            set d.c = 2
            call d.doSomething()        // notice how for this method we need to associate it with a variable
                                        // of "thistype", which we named "d".
            return d
    endmethod

endstruct
 
Level 11
Joined
Sep 12, 2008
Messages
657
so.. is it recommanded to use another name then this?
even tho this saves alot of space?.. dam, changing alot of codes, here i come ;/

edit: i just saw.. and basicly..
your jass code goes like this:

JASS:
this.variable

and this isnt like i do it.. i do:

JASS:
.variable

cuz localtype is converted into this automaticly, i just use the name this instead of adding a name before the dot.

is that still wrong?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I don't usually use this.variable unless the name variable is ambiguous in that method (used more than once for different things) but when there is no ambiguity then you don't even need the .variable you just need to use variable.

It really isn't that important but don't be declaring variables in static methods with the name this, it just causes problems.
 
Level 11
Joined
Sep 12, 2008
Messages
657
oh.. so if i do set this = Struct.allocate() it will cause problem?
dam.. ill see what i can do for that..

and btw..
how can i make like, a option to manually insert a code so it does the manual code on impact of the missle?
i've tried a code static, but well.. it doesnt allow array ^^
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well if you're in a static-method and you declare a variable "this" you're going to have two syntax shortcuts available. First, any static members that are available in your struct will not need to have thistype. before their name - second any instance members will not need to have this. before their name. It is not very explicit whether you are referring to a static member or an instance member, and the ambiguity may cause the compiler to do different things. This is just an example but I have definitely seen code before that doesn't work as it is written due to these problems.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
The way to do that would be to implement an interface, use a delegate (the functionality of this probably won't match that of using an interface), or use a function interface - all of these are dynamic ways of passing code through scripts.

If you're not entirely sure what one (or all) of these things are, just click the JassHelper link that I have in my signature and do a search for them. They aren't very difficult to find.
 
Level 11
Joined
Sep 12, 2008
Messages
657
nah, i wont do that.. guess its kind of useless,
well, anywyas, thanks for the help =]
and i guess i gotta switch this part.. this will take quite a time tho xD

edit:.. im done but,
im trying to reset all counters, since im regular to regular indexing, using Table
i ussualy reset all counters, and it works.
but since this is vjass, and i do Struct.allocate(), how do i reset the Struct?
i've tried Struct.destroy(), but it requires a name..
 
Last edited:
Level 11
Joined
Sep 12, 2008
Messages
657
well.. how can this be done then?
StructName(Mine is PS)

PS.Destroy(PS) PS dont exist.
PS.Destroy() requires a variable name.
PS.Deallocate(PS) PS Dont exist.
PS.DeallocatE() requires a variable name.

and btw, what fails about this, or how could i do it better?

JASS:
            local real dist = SquareRoot(GetUnitX(P.Missle) * P.StartX + GetUnitY(P.Missle) * P.StartY)
            local real maxdist = SquareRoot(P.EndX * P.StartX + P.EndY * P.StartY)
            local real curve = P.ArcHeight
            local real Formula = JumpParabola(dist, maxdist, curve)
                call SetUnitFlyHeight(P.Missle, Formula, 0)

StartY/StartX = setted at beggining, as the creation x/y
EndX/EndY used in 2 diffrent ways..
1. if its duration, then caculate max distance using DieHard@Azeroth's math.
2. if its max distance, just set it to startx + maxdistance * Cos (angle *bj_DEGTORAD)
and so on for Y.

but for some reason, it starts from max height, and goes down, instead going up then down?

P.ArcHeight is setted in creation of missle by default.
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
Let's say you've got a struct:

JASS:
struct somedata
    integer i
    integer j
endstruct

Now you have an instance of this struct created:

JASS:
    local somedata yourStruct = somedata.create()
    set yourStruct.i = 5
    set yourStruct.j = 7

Now you've got a struct of type somedata named "yourStruct" and you want to destroy it. There are a couple of methods of doing this, and it is possible to use deallocate but I'm going to spare you the trouble of learning that.

So, here's your options:
JASS:
    call somedata.destroy(yourStruct) // this looks bad
    call yourStruct.destroy() // this one is much better

Of course you can draw your own conclusions about which one you use, I don't think there is much difference.
 
Level 11
Joined
Sep 12, 2008
Messages
657
basicly, it doesnt work.. i do this:

struct PS
private static thistype M

blah blah blah

static method CreateMissle takes ...
set M = PS.allocate()

endmethod

private static method EndMissle takes thistype P returns nothing
call M.destroy()
endmethod

this way fails. ofcourse there are alot more actions, etc, just didnt show em all....
the second counter that determines how many missles are on is 0, but M stays same.
 
Level 11
Joined
Sep 12, 2008
Messages
657
lol if you read the old posts, M = max count. P = a local.
in create method, i do set M(M is a global) = Struct.allocate()

ill try removing private =]

edit: wait a minute..if i remove private, it becomes an array.. thats really useless and unhelping? ;p
 
lol if you read the old posts, M = max count. P = a local.
in create method, i do set M(M is a global) = Struct.allocate()

ill try removing private =]

edit: wait a minute..if i remove private, it becomes an array.. thats really useless and unhelping? ;p

on my post above: I'm just wondering why you took P as a parameter if the only action that the function does is M.destroy(), I dont see any usage of P there... ^^

IDK... never used private keyword in structs or struct members...

anyway, M will always return the last created/allocated struct since you only set it at the create method...
 
Status
Not open for further replies.
Top