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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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