[vJass] Array

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Now that I had holiday, starts my learning again.

Please explain what does this do:
I don't see it anywhere in the documentation...
JASS:

integer I = 0
integer O array I


What does the array do?

Edit -
Ah! Sorry for the confusing... guys.. It is from this post:
JASS:

//===========================================================================
//  Demo spell for using PUI in combination with global arrays
//  to create counters that are attached to unit
//
//  Author: Cohadar
//  Date: 2008.03.08
//===========================================================================

scope FleshHeap

globals
    private constant integer AID_FLESH_HEAP = 'A001'
    private constant integer AID_STR_BONUS  = 'A002'
    
    private constant integer HERO_PERCENT = 30
    private constant integer UNIT_PERCENT = 3
endglobals

globals    
    // do NOT use this arrays directly, use below functions
    private unit array PUI_unit
    private integer array PUI_counter
endglobals

//===========================================================================
private function GetCount takes unit whichUnit returns integer
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = 0
    endif
    return PUI_counter[index]
endfunction

//===========================================================================
private function AddCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = count
    else
        set PUI_counter[index] = PUI_counter[index] + count
    endif
endfunction

//===========================================================================
private function SetCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    set PUI_unit[index] = whichUnit
    set PUI_counter[index] = count
endfunction

//===========================================================================
private function Actions takes nothing returns nothing
    local unit pudge = GetKillingUnit()
    local integer level = GetUnitAbilityLevel(pudge, AID_FLESH_HEAP)
    
    if IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) then
        call AddCount(pudge, level*HERO_PERCENT)
    else
        call AddCount(pudge, level*UNIT_PERCENT)
    endif
    
    if GetCount(pudge) >= 100 then
        call SetCount(pudge, 0)
        debug call BJDebugMsg("|c0000FF00" + "strength increased")
        call IncUnitAbilityLevel(pudge, AID_STR_BONUS) // green stat way
        //call SetHeroStr(pudge, GetHeroStr(pudge, false)+1, true)  // Dota way
    endif
    
    set pudge = null
endfunction

//===========================================================================
private function Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetKillingUnit(), AID_FLESH_HEAP) > 0
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope




I saw something that is:
JASS:
    private unit array PUI_unit
    private integer array PUI_counter

What does the arraying does?

@Sooda
I don't understand.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Cohadar, please, don't give me nonsense answer.

>>I lol'ed
Do what ever laughing you want and don't spam on my thread.
 

notsoexpert

New Member
Reaction score
4
It basically declares a bunch of the same variable with the same name but a different index in brackets ()
Its useful in loops and stuff like that.

You don't have to remember different names and you can do stuff in loops using arrays, such as:
JASS:
function wth takes nothing returns nothing
local unit u = GetTriggerUnit()
local effect array e 
local integer i = 0
loop
exitwhen i == 10
set e<i>= AddSpecialEffectTarget( &quot; effects//whatevah.mdl&quot;,u,&quot;origin&quot;)
set i = i + 1
endloop
set i = 0
loop
exitwhen i = 10
call DestroyEffect(e<i>)
set e<i> = null
set i = i + 1
endloop
set u = null
endfunction
</i></i></i>

Not very practical or useful here, but its just an example.
 

Joker(Div)

Always Here..
Reaction score
86
@notsoexpert
The post you posted has no relation to what he is asking for.

I'm assuming integer o is going to have 8192 instances of integer i, which seems pointless.
 

notsoexpert

New Member
Reaction score
4
Ah... well... :eek:

I don't see the difference between telling you what a variable array does and what that tiny piece of vJass up there does, because they are extremely similar as to concept and I figured that would be the easiest way to explain it. The "array" part does just that... declares a group of the same-named variable.
And...
I'm assuming integer o is going to have 8192 instances of integer i, which seems pointless.
...how exactly does that answer the question, as well?
 

Trollvottel

never aging title
Reaction score
262
@topic:
where did you find that if not in the documentation?
if i see the context i maybe know what it means.
now i guess its an integer of type O (struct?) with array but the I doesnt really fit in because its declared before and its not in brackets so it doesnt set the max array size o0
 

Sooda

Diversity enchants
Reaction score
318
JASS:

It indeed should syntax, something what would work looks like:
JASS:
struct O
    string s = &quot;Makes sence!&quot;
endstruct

globals
    integer I = 0 // zero
    O array I // This is struct &#039;O&#039; (struct name is O,
              // bad name anyway) array what is named &#039;I&#039;
              // (Again using &#039;I&#039; as a struct name is bad
              // because it dosn&#039; t tell nothing to JASSer.
              // I assume it&#039; s for max performance aka
              // optimised coding.
              // Now both integer and struct array are named
              // same - I. They don&#039; t syntax because &#039;O&#039; is
              // actually integer array.
              //    After vJASS syntax check it could become
              // something like
              // integer array O__I
              // As you can see &#039;O__I&#039; and &#039;I&#039; aren&#039; t same
              // (they never was).
endglobals

That 'integer' before struct O just confuses (it' s syntax error, at least in JASS).
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Ah! Sorry for the confusing... guys.. It is from this post:
JASS:
//===========================================================================
//  Demo spell for using PUI in combination with global arrays
//  to create counters that are attached to unit
//
//  Author: Cohadar
//  Date: 2008.03.08
//===========================================================================

scope FleshHeap

globals
    private constant integer AID_FLESH_HEAP = &#039;A001&#039;
    private constant integer AID_STR_BONUS  = &#039;A002&#039;
    
    private constant integer HERO_PERCENT = 30
    private constant integer UNIT_PERCENT = 3
endglobals

globals    
    // do NOT use this arrays directly, use below functions
    private unit array PUI_unit
    private integer array PUI_counter
endglobals

//===========================================================================
private function GetCount takes unit whichUnit returns integer
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = 0
    endif
    return PUI_counter[index]
endfunction

//===========================================================================
private function AddCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    if PUI_unit[index] != whichUnit then
        set PUI_unit[index] = whichUnit
        set PUI_counter[index] = count
    else
        set PUI_counter[index] = PUI_counter[index] + count
    endif
endfunction

//===========================================================================
private function SetCount takes unit whichUnit, integer count returns nothing
    local integer index = GetUnitIndex(whichUnit)
    set PUI_unit[index] = whichUnit
    set PUI_counter[index] = count
endfunction

//===========================================================================
private function Actions takes nothing returns nothing
    local unit pudge = GetKillingUnit()
    local integer level = GetUnitAbilityLevel(pudge, AID_FLESH_HEAP)
    
    if IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) then
        call AddCount(pudge, level*HERO_PERCENT)
    else
        call AddCount(pudge, level*UNIT_PERCENT)
    endif
    
    if GetCount(pudge) &gt;= 100 then
        call SetCount(pudge, 0)
        debug call BJDebugMsg(&quot;|c0000FF00&quot; + &quot;strength increased&quot;)
        call IncUnitAbilityLevel(pudge, AID_STR_BONUS) // green stat way
        //call SetHeroStr(pudge, GetHeroStr(pudge, false)+1, true)  // Dota way
    endif
    
    set pudge = null
endfunction

//===========================================================================
private function Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetKillingUnit(), AID_FLESH_HEAP) &gt; 0
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope

I saw something that is:
JASS:
    private unit array PUI_unit
    private integer array PUI_counter

What does the arraying does?

@Sooda
I don't understand.
 

Cohadar

master of fugue
Reaction score
209
Those are 2 arrays.
One is the array of unit handles,
the other is the array of counters (to be attached to the unit with PUI)

PUI is indexing not attaching system.
Therefore you need arrays to use the pui index.

It is all pretty simple and obvious for anyone who had at least one subject about programming in school.
You simply lack a programming knowledge of arrays that's all.
Not really something I can "answer" you - you need to learn yourself.

Start from the wiki link I posted before.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>It is all pretty simple and obvious for anyone who had at least one subject about programming in school.
Sorry but I don't have any, atleast on my age.

>>You simply lack a programming knowledge of arrays that's all.
Hmm, yea, I agree.

>>Not really something I can "answer" you - you need to learn yourself.
Not to answer me, teach me.

>>Start from the wiki link I posted before.
I don't understand what's written on there... :/

Edit -
AH! GodDamn I am so idiot, it is just a normal array system, I did messed it up with other things.
It is just a <type>array<name>. The example given by sooda it is the same, struct is the "type" and I is the name.
Sorry for the trouble, everyone.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top