| 09-13-2011, 06:08 PM | #1 | |
this ones had me stumped for a few days and now that my brain hurts, I'm coming here i tried to do it with lists like Anitarf showed me with wisp wheel but it doesn't quite work yet Easy To Read Version:globals timer LevelTimer = CreateTimer() group LevelGroup = CreateGroup() endglobals library LevelStructure requires ListModule struct Level //Member variables implement List method LevelWait takes real r returns nothing call TriggerSleepAction(r) endmethod //unit has reached a checkpoint method LevelRegionEntry takes unit u returns nothing endmethod private method LevelGroupHook takes nothing returns nothing call LevelRegionEntry(GetEnumUnit()) endmethod private static method LevelPeriodic takes nothing returns nothing local Level l = .first loop exitwhen l == 0 call GroupEnumUnitsInRect(LevelGroup, l.StartCPRect, PlayerOwned) call ForGroup(LevelGroup, function Level.LevelGroupHook) set l = l.next endloop endmethod private static method onInit takes nothing returns nothing call TimerStart(LevelTimer, .1, true, function Level.LevelPeriodic) endmethod //creates a level struct static method create takes integer number, string name, integer diff, trigger start, trigger stop, trigger nextpre, trigger nextun, boolean hasnext, rect startrect, rect vision returns Level call new.listAdd() return new endmethod endstruct endlibrary so basically what I want to happen is the timer periodically checks all the Level structs in the list to see if a PlayerOwned unit is in the matching rect for that instance of the Level struct if there are such units, then for all units in that rect call LevelRegionEntry LevelRegionEntry is pretty complex so it'd be really really helpful if I could do this like I'm trying to also Anitarf (since I'm like 99% sure its gonna b you answering) you said that you like to periodically go through all your regions instead of using the region entry event built into the game engine. what do you use for a periodic time? and last question: I'm gonna need to use waits in some of my triggers coming up, so this is important. if I put a triggersleepaction in a function but that function gets called again, it glitches up and skips the rest of the actions (in the original function call after the wait call) so if I make a function JASS:myWait(real x) ie mainFunction calls myWait myWait calls TriggerSleepAction() in the middle of that, mainFunction happens to be called again does it skip just the myWait call or the entire rest of the first mainFunction?
many thanks to those who help/try to help =) edit 1 more question: which one of these is preferable? JASS:globals constant integer x = 10 real array a[x] string array b[x] integer array c[x] integer array d[x] boolean array e[x] endglobals versus JASS:globals example array ex[x] endglobals struct example real a string b integer c integer d boolean e endstruct ie. hows the lookup on ex[i].a compare to a[i]? is it around the same amount of space to store everything in 1 struct versus lots of different arrays? so far all my triggers have been using the first method (so it'll suck to switch to the second one). so if the second one is preferable, how preferable exactly? |
| 09-17-2011, 05:24 AM | #2 | ||
Quote:
You will probably want to refrain from using TriggerSleepAction. In periodics especially, it can lead to very odd wait times. Generally, it may do things you just don't want it to do. I recommend that you opt for a timer method, it is harder to implement but the results will be a lot less varying. Quote:
Well, I am not sure exactly what you mean. Do you mean a global array vs. a struct array? They are pretty much different things. The first one is just a bunch of arrays, so that will be very fast. The second one is an array variable of a struct, aka an integer array. So when reading the globals, it would just be a[x] while reading it from the struct will be ex[x].a. The second method will be slower because it is actually doing a[ex[x]], which is two array reads compared to a simple a[x]. ... but there is always the high chance that I misunderstood your question. :P But if you are curious about strictly speed, the global block will be faster. It really depends on what you are doing as to which one you will use. If you are questioning structs vs using globals and doing all the work yourself, then I say you should just opt for structs because they were made for a reason. =) However, if you don't need a struct, then don't use one. |
| 09-17-2011, 08:23 AM | #3 | ||
Quote:
Quote:
As for your wait question, I think you can't use TriggerSleepAction in timer callbacks at all. Use a timer instead. |
| 09-17-2011, 06:13 PM | #4 | |||
Quote:
i still might since 2 array lookups isnt really worth caring about especially since doing it that way would make object oriented jesus cry :( thank you very much for ze info's Quote:
it doesn't like me calling LevelGroupHook from the ForGroup call JASS:call ForGroup(LevelGroup, function Level.LevelGroupHook) JASS:private method LevelGroupHook takes nothing returns nothing call LevelRegionEntry(GetEnumUnit()) endmethod the error is LevelGroupHook is not an static method of Level that takes nothing. Quote:
so if someone would do a crash course with me that'd be awesome if i have timerutils should i always create timers through it? can i release timers that weren't made with timerutils? whats the easiest way to get the integer value of a handle? i'm assuming thats the main point of the data attachment feature, pls correct me if i'm wrong. or wait, is it possible to flat out attach a struct to a timer? |
| 09-17-2011, 10:42 PM | #5 | |||
Quote:
Quote:
Quote:
|
| 09-21-2011, 01:52 AM | #6 | |||
Quote:
not like something elaborate, just a short example... with a comment or two Quote:
JASS:call SetTimerData(t, myStruct) JASS:call GetTimerData(t).methodName Quote:
Could I do: JASS:exitwhen FirstOfGroup(g) == null JASS:exitwhen IsUnitGroupEmpty(g) |
| 09-21-2011, 10:50 AM | #7 | |||
Quote:
JASS:globals group someGroup = CreateGroup() endglobals function unitCheck takes nothing returns boolean return (not IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD) and GetUnitTypeId(GetFilterUnit) == 'hfoo') // Enumerate only living footmen. endfunction function healthDisplay takes nothing returns nothing call BJDebugMsg(R2S(GetWidgetLife(GetEnumUnit())) // Display the health of all enumerated units (footmen). endfunction // Pretend that the following code is somewhere within a function. call GroupEnumUnitsInRange(someGroup, 0.0, 0.0, 500.0, Filter(function unitCheck)) call ForGroup(someGroup, function healthDisplay) call GroupClear(someGroup) you should do this: JASS:globals unit filterUnit = null // We'll use this only to improve the efficiency. group someGroup = CreateGroup() endglobals function unitCheckAndHealthDisplay takes nothing returns boolean set filterUnit = GetFilterUnit() // We can't use a local, 'cos we won't get the chance to null it and prevent it from leaking. if (not IsUnitType(filterUnit, UNIT_TYPE_DEAD) and GetUnitTypeId(filterUnit) == 'hfoo') then // Check if the unit is a footman. call BJDebugMsg(R2S(GetWidgetLife(filterUnit)) // Display its health. endif return false // This prevents any unit from passing the filter, so not a single units gets added to the group. endfunction // But there's no need to - as we've already done all actions we needed. // Pretend that the following code is somewhere within a function. call GroupEnumUnitsInRange(someGroup, 0.0, 0.0, 500.0, Filter(function unitCheckAndHealthDisplay)) // We no longer need to use ForGroup(), or even clear the group, because no units get added to it anyway. Quote:
Quote:
JASS:// Pretend that the following code is somewhere within a function. local unit temporaryUnit // Enumerate units and everything else... loop set temporaryUnit = FirstOfGroup(someGroup) // Pretend that the group is filled with units. exitwhen (temporaryUnit == null) // Do stuff with the "temporaryUnit" unit. endloop |
| 09-21-2011, 12:54 PM | #8 | |
Quote:
|
| 09-21-2011, 02:10 PM | #9 | |
Quote:
|
| 09-23-2011, 07:55 PM | #10 | |
Quote:
are the integer values given by GetHandleId(h) pointers to the actual handle or a kinda hashed version of the handle? thanks everybody for the help, you guys are da best |
| 09-23-2011, 08:44 PM | #11 | |
Quote:
|
