• 🏆 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!

integer arrays linked to units

Status
Not open for further replies.
Level 2
Joined
Oct 16, 2009
Messages
15
Hey there,

I'm trying to have a sort of integer value attached to each unit. But i cant figure out how to lower the value by 1 every 3 seconds for every unit.

so far i have this, every time a unit is created a variable unitID is increased by 1 and the array is set to 100. (so everytime its like: set Array[unitID] = 100)

but when i make this trigger to count down it resets the whole array to 100 when a unit is created.

i know the problem lies with : Array[Integer A] = Array[Integer A] - 1. this clearly resets everything obviously but i dont know how to write it differently so it wont reset every unit back to 100.

Anyone know this?
thanks
 
Level 13
Joined
May 11, 2008
Messages
1,198
what are you talking about? why would you even want to change the index position of your variables? how are you supposed to access them when you do that?

i'm guessing you're trying to make some sort of unit indexing system...if that is the case...

hmm...it sounds like you don't know how arrays work.

idk what you're trying to do, so i'll show two examples, integer array and unit array.
unit array bozmirunit
integer array bozmirunittype

set bozmirunit[0]=CreateUnit(...)
set bozmirunit[1]=CreateUnit(...)
set bozmirunit[2]=CreateUnit(...)
etc...

set bozmirunittype[0]="hfoo"
set bozmirunittype[1]="hpea"
set bozmirunittype[2]="hgry"
that's an example of how the arrays work.
[unitid] doesNOT work.
what's in those brackets is supposed to be a number, from your 1-100.
you can choose to start at 1 instead of zero if that is your choice, i believe.
0-99 or 1-100 are both mostly the same. gui uses 1-100 so when you convert those to custom text all the numbers get -1.

idk exactly how it all works in gui, but i know you create an array variable using the variable editor, and you edit the array's index count.
then you just take your time in declaring what units are or in declaring unittypes you can declare them at map initialization...back when i used gui a lot more i actually set the integer array variables in jass because it was far more efficient

are you trying to use integer array to keep track of units ids?
usually someone does that for allowing the player to randomly select something.
or perhaps you want random units to be spawned or something like that.

anyway, i don't understand why you're trying to reset anything back to 100, i don't know what you're trying to do with all this...and you're not supposed to put unit id in the bracket...that's where your index number goes.
 
Level 2
Joined
Oct 16, 2009
Messages
15
just trying to make an array attached to every unit in the map. With this array it should provide every unit with a counter. (after a special action it counts down and the unit will die when it hits 0)
if there is another way im really happy to hear it. im not really experienced with triggering so im trying to learn this.
 
Level 13
Joined
May 11, 2008
Messages
1,198
really? that's all you're trying to do?

use the timed life function.


set tempunit=CreateUnit(player, unittype, realx, realy, realf)
call UnitApplyTimedLife(tempunit, 'BTLF', 100.00)

that's all you need to do. well, tempunit is the name of your variable...you can change it as you see fit...if made in gui, it might read as udg_tempunit. usually people just use a local variable for a unit like this. if that's what you're going to do, your trigger will look a little more like this:

local unit x=null
local integer y=0
local integer z="hfoo"
local real rx=0.00
local real ry=0.00
local real rf=0.00
local real rd=100.00
local integer i=0
loop
set rx=RX[y]
set ry=RY[y]
set rf=RF[y]
set x=CreateUnit(Player(y), z, rx, ry, rf)
call UnitApplyTimedLife(x, 'BTLF', rd)
set y = y + 1
exitwhen y == bj_MAX_PLAYERS
endloop
set x=null

jass may be complicated, but themore you use it the easier it is to be free in what you code, and you can write more quickly. there's just a lot to learn.
presumably you have a spawn point for each player...if that's the case you can make 3 real arrays for all the players...so maybe player 1 spawns at middle of map, he can be RX[0]=0.00, RY[0]=0.00,RF[0]=90.00 and player 2 can be something like RX[1]=250.00, RY[1]=0.00, RF[1]=270.00. those spawnpoints can all be configured at map initialization if you want. you could also do the same thing for the unit type, change it for each player. perhaps at beginning of game they all get footmen, then later they might get tech up, and then they have a different unit type.
this could be another use for integer array for unit types.
which reminds me, i heard sc2 can use two dimensional arrays. it sounds exciting.
 
Last edited:
Level 2
Joined
Oct 16, 2009
Messages
15
I actually know how arrays work, thanks for the reply but it was allready clear to me :p the thing im trying is NOT reset it to 100 when a new unit spawns.
The thing im trying is to have every index to count down every x seconds.
normally i would do this with unitarray[1 to X]--;
but since this works different in GUI im trying to find a solution.

lets say:

event: unit spawns
action:
set unitarray[spawnedunit_ID] = 100;

--------
event:
every 3 seconds

action:
for each(integer X which is: 1 to spawnedunit_ID)
set unitarray[X] = unitarray[X] -1;

so every unit will have his counter decreased by 1 every 3 seconds :)
 
Level 2
Joined
Oct 16, 2009
Messages
15
just use a hashtable..

like
  • Hashtable - Create a hashtable
  • Set Hashtable = (Last Created Hashtable)
then just set the hashtable value at 0, handle id of triggering unit = hashtable value at 0, handle id of triggering unit - 1

I used some hashtables and it worked well for me. but im not really sure what you mean by this. could maybe create an example in a map? i understand if this is to much work :)
thanks
 
Level 2
Joined
Oct 16, 2009
Messages
15
cannot do that. its a very complex peasant system. expiration timers are allready in use for their duration.
didnt know it was this hard.

im now using hashtables with it.

create peasant trigger :

set peasantID = peasantID + 1
save peasantID as 1 of key last created unit in hashtable
set unitarray[load 1 of last created unit in hashtable] = 100;

countdown trigger :

every 3 seconds:

set unitarray[integer A] = unitarray[integerA] - 1

it goes wrong with the interger A. it resets every index to 100 because of the new spawn (example after 9 seconds with 1 spawn and 3 existing its: 100, 97 97 97 -> 100 100 100 100 another spawn after 3 sec means 99 99 99 99 -> 100 100 100 100 100 and so on....)
i need to find a different way to avoid this.

edit:

fixing it now with multiple dummies for every peasant property with expiration timers.
peasant action means extra time for expiration timer.
though i would really appreciate a solution for this.
thanks
 
Last edited:
Level 2
Joined
Oct 16, 2009
Messages
15
well not really.. i fixed it with a different kind of system.

creating a dummy. with X health and a negative health regeneration value.
with X as a "counter". when a peasant carries out an action which will give him extra hp or increase/decrease the counter, the dummie's life will be increased or decreased.
thanks for all the help! ;)
 
Status
Not open for further replies.
Top