Struct/vJass Tutorials - Help wanted please

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
so you have to call static right from your struct and if using other variable it won't work?
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
Why would you make another instance of exactly the same thing? And how can you change that instance if need be?

Hmm, you don't seem to be understanding what structs are for.

When you declare a struct

JASS:
struct A
integer a = 1
integer b = 2
integer c = 3
endstruct


It's like a template.

When you create an instance of it,

JASS:
A.create()


This here being based off of A,
it's like creating 3 different variables: a, b, and c.

JASS:
local A s = A.create() //{local integer s.a, local integer s.b, local integer s.c}


Except the struct can be treated as a single variable, and can be stored or attached to a unit as a single integer.

I.E. instead of attaching three different integers, i can store just one and it gives me all three.

Here's an example of usage:
JASS:
struct Spell
	unit Caster
	unit Target
	
	method Damage takes nothing returns nothing
		call UnitDamageTarget(this.Caster,this.Target,...)
	endmethod
endstruct

function Trig_Spell_Timeout takes unit u returns nothing
	local Spell s = GetHandleInt(u,"something") //Get the struct from the unit and do actions.
	call s.Damage()
	call s.destroy()
endfunction

function Trig_Spell_Actions takes nothing returns nothing
	local Spell s = Spell.create() //Creates a new structure of data from Spell.
	set s.Caster = GetSpellAbilityUnit()
	set s.Target = GetSpellTargetUnit()
	call SetHandleInt(GetSpellTargetUnit(),"something",s) //Attach the struct to the target.
endfunction


Later, If I were to call Trig_Spell_Timeout passing the targeted unit as the variable, It would retrieve the stored struct from that unit and perform actions with it.

Remember, think of a struct like a package with variables and functions in it. I've created a package with two unit variables and a function inside it, attached that package to the target unit, then later retrieved that package and called the function.
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
just a question what does making it static will give me that i don't have in a none static value?
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
So a struct is a template of "integer" or "real", "point" and all those others?
it's the handle of the variable and the value?
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
Here we go again :p

It's a single variable that has multiple other variables in it, which are defined in the struct...endstruct block.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
"but it's good for you sensei! It will help you with patience!"

Ok I believe you. :)
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Sorta, but not. I semiunderstand how to use it, but not what it is.
I will use now and understand later. Thanks for that indepth.....explanation.

DoomAngel still has a Q.
just a question what does making it static will give me that i don't have in a none static value?
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
I apologize for the lack of explanation. If I was a teacher I would be doing that now, not posting on a forum. Play around with them a little, look at how other people have used them. That's how I learn stuff.

Doomangel ->

Static variables are basically just globals, however they are only accessed via <Structname>.<variable>.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
What are these in your example? I can't find them in TESH.

GetHandleInt()
SetHandleInt()
 

0zaru

Learning vJASS ;)
Reaction score
60
They are some old handle vars that kattana created. anyway you can use some better things like SetCSData and GetCSData (Also HSAS or ABC)
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
CS_Cache (or Kattana's?) functions, they simply trasfer local data from function to function.

You can think of structs as arrays Chovynz. Instead of variablename[#] to access information you do structname.membername. More than that, instead of holding the exact same type of values, structs vary the types of their values, and can have methods in them, etc.

Edit: I'm suprised this haven't been locked yet. Usually moderators prefer to have seperate thread for each question, rather than a confusing thread like this. I think it would be better if we leave this thread and move to threads that as specific questions.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
It probably hasn't been locked as it all relates to basic vJass / struct questions. Maybe.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top