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.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". 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
this.variable
.variable
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
.this
, it just causes problems.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.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 ^^
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/ystartx + maxdistance * Cos (angle *bj_DEGTORAD)
struct somedata
integer i
integer j
endstruct
local somedata yourStruct = somedata.create()
set yourStruct.i = 5
set yourStruct.j = 7
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. call somedata.destroy(yourStruct) // this looks bad
call yourStruct.destroy() // this one is much better
private static method EndMissle takes thistype P returns nothing
call M.destroy()
endmethod
//you take thistype P but you do M.destroy()???
//have you tried removing the private keyword from static thistype M?
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