Is there a way to not need to define an array size? o.0

SineCosine

I'm still looking for my Tangent
Reaction score
77
Well..

There's this struct that has many array-variables in it.
And the size of the array needed varies for each time I call the Create method in the struct.

So..
Is there a way to not need to define a size?
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
No. Your options are basically:

JASS:
struct Bleh
    unit array mahUnitz[MAX_NUMBER_OF_UNITS_EVER_TO_BE_USED]
endstruct


or a linked list approach.
 

Bribe

vJass errors are legion
Reaction score
67
Initialize an array like this, you will have no problems unless you want to get past 8190 array slots.

Setting an array size slows things down a lot. I would avoid it as much as possible, seeing as how if you have 8190 units in an array stack your computer will die before vJass will glitch.

JASS:

struct awesome
    static unit array coolGuys
endstruct

//or

//! zinc
struct awesomer
{
    static unit coolGuys[]
}
//! endzinc
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Initialize an array like this, you will have no problems unless you want to get past 8190 array slots.

Setting an array size slows things down a lot. I would avoid it as much as possible, seeing as how if you have 8190 units in an array stack your computer will die before vJass will glitch.

JASS:

struct awesome
    static unit array coolGuys
endstruct

//or

//! zinc
struct awesomer
{
    static unit coolGuys[]
}
//! endzinc

How exactly does that substitute for being a unit array member?
What you've posted in no different than:
JASS:

globals
    unit array CoolGuys
endglobals

Which is very different in function than having member arrays particular to each struct.
 

Viikuna

No Marlo no game.
Reaction score
265
Lols, just realized that after all this vJassing Ive done, I stil yet dont know what vJass dynamic arrays do, nor have I used them or ever seen anyone using them.

Anyways, linked lists might work. Post some example so we can tell you more.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
I'd post an example.
But the thing is, I still don't have one yet.

I'm still thinking stuff through my head ._.
I don't know how you guys manage to do cool stuff like:
JASS:
method onHit_Enemy takes nothing returns nothing

endmethod


Like, when a projectile hits something (Maybe a system-triggered projectile) or enums some enemy units in range, you can allow a user to decide if he wants to use the onHit_Enemy function or not ._.

So..
How do you guys do it?

Is there a way for this?
JASS:
static method SomeFilterThingy takes nothing returns boolean

    //If GetFilterUnit() is an enemy, alive and not yet damaged and stuff
        //I duno, maybe something to do with onHit_Enemy?
    //Endif
    return false
endmethod

//Then, the user can decide if he wants to use the method onHit_Enemy
//And even decide if it's damage, a spell cast, etc.

method onHit_Enemy takes nothing returns nothing
    //Damage, Give some buff, etc.
endmethod
 

Bribe

vJass errors are legion
Reaction score
67
My Time Travel system uses a single hashtable to store unlimited array values so that it keeps a history of coordinates, though the way that I distribute parent keys between the instances is a little hard to grasp if you're not used to 2-D arrays.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
Are 2D arrays like..
A table?

Like..
JASS:
real array Something[8190][8190] //Is that it? =x


And I wasn't thinking about projectile collision.
More of collision with enemy units.
(Well, not really collision, just GroupEnumUnitsInRange sort of thing)

[EDIT]
I saw the interface keyword again ._.
I saw it in SpellStruct and in your TimeWarp.

What is it for? =x
 

Bribe

vJass errors are legion
Reaction score
67
By 2-D array I mean if you want to store three "arrays" inside of one array.

array[3*i + 0] = 10;
array[3*i + 1] = 11;
array[3*i + 2] = 15;

^ Using 2-D arrays is like that, you can get three values stored with just the key integer of i within the same array and they won't overlap. Now that I think of it, I guess I am using 3-Dimensional arrays in my Time Travel system. The first dimension is the parent keys, the second the above method, and then further indexing with child keys.

Interface is for when you extend the struct. So my Time Travel library has no methods of "onLoop" or "onCollapse", but I have an interface that makes provisions so that a child struct can use an "onLoop" and "onCollapse" method as if they were events. It's a dynamic concept overall, and I recommend digging through JASSHelper manual because it has some interesting notes about interfaces.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
Hey!
I've done that before!
You mean there's a name for it? xD

I think I've only ever used it twice.
When I was making a nova spell that spawned more novas and when I was making a trap-like spell ._.

So..
What's defaults nothing?

[EDIT]
So..
Do I extend the interface or the struct?

JASS:
    interface printable
        method toString takes nothing returns string
    endinterface

    struct singleint extends printable
        integer v
        method toString takes nothing returns string
            return I2S(this.v)
        endmethod
    endstruct


That example shows a struct extending an interface ._.
 

Bribe

vJass errors are legion
Reaction score
67
"defaults nothing" is used in case there are no methods calling it, the parent struct gets a default return value. If you're using an interface method called "evaluate" that the parent struct calls before adding a unit to the system, you want to make sure that evaluator "defaults true".


JASS:

interface MyInterface
    method onLoop takes nothing returns nothing defaults nothing
endinterface

struct ParentStruct extends MyInterface
    
    private timer T=CreateTimer()
    
    /* Parent structs should have private methods for ones you don't want child structs calling. */

    private static method test takes nothing returns nothing
        call BJDebugMsg(&quot;We are looping <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />&quot;)
        call onLoop() /* Notice there is no &quot;onLoop&quot; in this struct */
    endmethod
    
    private static method onInit takes nothing returns nothing
        call TimerStart(T,1.0,true,function thistype.test)
    endmethod

endstruct

struct ChildStruct1 extends ParentStruct
    method onLoop takes nothing returns nothing
        call BJDebugMsg(&quot;Hey, I am using the loop.&quot;)
    endmethod
endstruct

struct ChildStruct2 extends ParentStruct
    method onLoop takes nothing returns nothing
        call BJDebugMsg(&quot;Hey, I am, too!&quot;)
    endmethod
endstruct

struct ChildStruct3 extends ParentStruct
    method onLoop takes nothing returns nothing
        call BJDebugMsg(&quot;There can be 8190 structs doing this IIRC.&quot;)
    endmethod
endstruct
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
And it will not clash? ._.
Wow.

So that's how u guys do it ^^
I have learned something new again!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top