• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] vJass

Status
Not open for further replies.
Level 7
Joined
Jun 16, 2008
Messages
253
I've just found some time to experiment with what I am assuming is vjass... structs. The simplest of all vjass I know, but that's why I'm starting there before moving on to stuff i don't really need.

Could someone please tell me in simple terms, how I would use a struct in conjunction with a unit. Say I have:

struct attribute
(public?) real strength
(public?) real mass
endstruct

and the unit, such as Hero.

How would I go about creating the struct for that unit, and then calling it or finding say, the strength of Hero in other triggers or functions?

I would be hugely grateful for anyone who can give me a simple concise explanation.

:Just imagine a big smiley face here giving you a giant cookie.:
 
Level 3
Joined
Sep 13, 2008
Messages
63
I don't believe what your looking for is a struct. You can give a unit a integer number with SetUnitUserData(). With a struct (which is a integer) you can attach multiple variables (see example below). To get a units strength use GetHeroStr().

JASS:
public/private struct NAME
    public/private TYPE NAME
endstruct

JASS:
scope test

struct Data
    public real strength //Public adds the scope name before strength. So strength becomes test_strength
    public real mass
endstruct

public function Add takes unit u returns nothing
    local Data d = Data.create() //creates the struct
    call SetUnitUserData(u, d) //d is a integer and adds the integer (struct) to the unitdata
    set d.strength = 1 //Changes the variable in the struct to whatever
    set d.mass = 1 //Same
endfunction

public function Get takes unit u returns nothing
    local Data d = GetUnitUserData(u) //Get the struct from the unit
    call BJDebugMsg("strength: " + R2S(d.strength)) //Simply says the stored information
    call BJDebugMsg("mass: " + R2S(d.mass))
endfunction

endscope
 
Level 7
Joined
Jun 16, 2008
Messages
253
Thanks for your reply dude!

In fact it is what I'm looking for, I don't want to find the normal GetHeroStr(), (if that was the problem I could figure at least that small bit of jass out out. :D)

Normal Warcraft attribute:strength messes with the units HP and other stats which I didn't want to happen, becauseI'm using an entirely new Combat System. In fact Im trying to find a way to make their attacks cause 0 damage without actually disabling the attack. My thought at the moment is to replace it with a substitute ability.

But thank you very much for the example, and the notes inside help clarify some other things as well.

One question, do structs become types? As you have struct Data, and then in the public function Add, you have
local Data d.
I understand the whole creating the struct for inside the function though. :D

Also, I have on my map a struct all by itself with a couple of static values that I seem to be able to call easily, although there is no scope surrounding it.

Does making it a public function mean it is only usable within the scope? And that I couldn't call it with a normal function?

Don't answer anything that needs an involved explanation, because it's probably easier to figure out than to explain.

So thanks again!
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Yes, structs are treated as their own types.

public means that it's usable anywhere, but prefixed with the scope name (eg ScopeName_FunctionName).

Also, you don't need 'public' for struct members.

Also also, you can change what the attributes affect (To a limited degree) in the Gameplay Constants.
 
Level 7
Joined
Jun 16, 2008
Messages
253
Cheers once again PP! :D

(I assume you mean hero strength/agility/intelligence. I guess I could make them all have 0 effect, hadn't thought of that. :D)
 
Level 3
Joined
Sep 13, 2008
Messages
63
Normal Warcraft attribute:strength messes with the units HP and other stats which I didn't want to happen, becauseI'm using an entirely new Combat System. In fact Im trying to find a way to make their attacks cause 0 damage without actually disabling the attack. My thought at the moment is to replace it with a substitute ability.
-You could use a "attack detection" system and apply damage.
-Give all units the mountain giant's hardened skin ability (make it take a lot more damage) then use triggers to damage the unit.
 
Level 7
Joined
Jun 16, 2008
Messages
253
:D That is basically the combat system, unit artificially applies damage.
I've heard of people using the mountain giant ability, it seems to me that still wouldn't truly solve it. I've stuck everyone's damage to 1 (the lowest it can go), and even if I gave them all Divine Armour and Hardened Skin, there would still be a tiny bit of damage that accumulates over time. Although this isn''t a huge deal and can be worked around, I'd rather remove it as an issue altogether.

Thanks though! :D
 
Status
Not open for further replies.
Top