• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Problem with struct array member

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

I have a little problem and a question to that. When a hero cast my spell, all nearby units
are picked up. So it can be just 1 or 1000 units. Now I need to store every picked unit into an array variable and I do this:

JASS:
private struct ElementalSpin
     unit    array   target

Now he say,expect size, so I have to add [value] behind it. The problem is now, I don't know
how many values I need at the end, so what can I type here?

Edit: The end value of the number of loops is a struct member called "iloop" (integer loop), but when I enter this between the [],
he gives me an error "Wrong [size] definition"

Greetings and Peace
Dr. Boom
 
Level 11
Joined
Sep 12, 2008
Messages
657
Purge? he said this:

"So it can be just 1 or 1000 units"
1 OR 1000, he didnt say 1 TO 1000 xD,
and btw.. why not do what i did with my ShieldSystem?

JASS:
struct ShieldData
        public unit wielder
        public string shieldSFX
        public effect sEffect

globals
        public ShieldData array shieldData
endglobals
this way, you just have a struct array, and you dont have to put the amount..
depends how do you need it xD (if it does a loop inside the struct as if it was a group, this wont really work :p)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
What he is after is perfectly doable in OOP languages. You just allocate an array to the instance as needed with the required size and it will be placed in free memory and recycled when you deallocate that array. However JASS is not an OOP language as it is functional. It can be viewed very simlarly to C programming for microcontrollers whereby you can not do all the easy dynamic allocation you can in OOP languages. Due to the type saftey in JASS it is inact worse than C as you can not allocate and deallocate memory areas at will so it is even harder to emulate such dynamic behaviour as he wants.

I can say that 2 approaches could be used to obtain what he is after.
1. Using chains of instances to provide a joint collection of units which will only consume space from the arrays as nescescary but will need a lot of allocation and deallocation overhead.
2. Using a group, which for all purposes acts as a dynamicly allocatable array for units (although slower at times).
 
Purge? he said this:

"So it can be just 1 or 1000 units"
1 OR 1000, he didnt say 1 TO 1000 xD,

Oh. Lol. xP Well, either way, if he wants to keep all the unit data, then that would be how to make an array of it. The size definition determines the maximum amount of indices that the "array" can be filled with.

However, it is a bad choice as DSG said. The most practical choice is to use a unit group. You can also use a list, as chobibo said, but it really depends on what you are doing.
 
Status
Not open for further replies.
Top