HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Question about my spawning method

01-30-2004, 01:41 AM#1
Narwanza
As many of you know, I have made a TD and released it for beta. I am now revamping my beta so I can release a new beta version. I was going through and delagging my map, and wondered if there was an easier way to set what monsters would be in what level. Anyways, right now I have it set to the good old fashioned array with 40 pointers filled up so far. But I was thinking, why couldn't I just use one unit type variable that is not an array. Then I would run a trigger after each level that would set which unit will be next. Here is a sample of what I plan to do for the defining of the monsters.

Code:
Events:

Conditions:

Actions:
If (level = 1) then
    set EnemyType = footman
else
    call DoNothing()
endif

If (level = 2) then
    set EnemyType = Rifleman
else
    call DoNothing()
endif

etc....

I know that is kind of the GUI mixed w/JASS, but I hope you can understand it. Anywayz, do you think that running this trigger after each level will reduce the lag of having a huge 40 part array that defines them all at once, or will it lag more running through these conditions each time?
01-30-2004, 01:56 AM#2
weaaddar
an array will be faster as its predefined. This trigger your describing has quite a large bit of over head because of all the condtional blocks it'll have to run through. Triggers also have execution time, while functions do not. (functions for all extents and purposes run instantenous or atleast between a range timer of zero>execution of a function>0)

The would be more optimal:
I'd still suggest the variable method as its generally easier especially from the GUI point of view.
Code:
function switchenemyunit takes integer level returns nothing
if(level==1)then
  set udg_myenemy=this guy
elseif(level==2)then
  set udg_myenemy=this other guy
...
elseif(level==n-1)then
  set udg_myenemy=this really tough looking guy
else
  set udg_myenemy=your father, luke
endif
endfunction

this function only has one condtion block to be concerned with and once it matches one condition will prompty exit the function something your trigger does not.
01-30-2004, 02:27 AM#3
Narwanza
I did plan to do something like this weaaddar. I just wrote it like that ealier becasue the general public wouldn't be able to understand it if i put in it function form.;) I will end up doing it that way then, since it seems to be much more optimized. I just realized that if I did what I actually wrote up above(it was not going to be in gui, i was going to do it in function form, but if i did do it in gui...) then when the game went through and changed the gui into JASS i would have over 40 functions, because the WE converts any condition into its own little function that returns a boolean. That would be an ugly mass of triggers, lol.