| 05-14-2008, 08:52 AM | #1 |
1) i have the feeling, that the function GetLastCreatedUnit() sux if i create a unit and then want to set it to some variable. right? even if create unit X and set variable=X are right next to each other some other trigger might fire inbetween right? 2)how does wc3 check trigger events and conditions? whenever something happens it compares the event with all trigging events - then compares all events that fire a trigger with the respective conditions? or does it simply keep track of all events (?and conditions) of all triggers and whenever one comes to be it fires the respective trigger? or does it make a difference which of the two event/conditions you choose? (1)Event(UnitEntersRegion A ),Condition(TriggeringUnit=X) (2)Event(UnitEntersRegion "playable area" ),Condition(TriggeringUnit=X) assumption: in both cases X can only be created inside of A which is a small subset of "playable area" but during the game other units are created all the time in "playable area" but not in A thanx4help ![]() |
| 05-14-2008, 05:38 PM | #2 | |
Quote:
It is theoretically possible, but it doesn't happen in practice. Even Blizzard use that method with stuff like points/locations. Scripting is, as usual, a better option: set myUnitVariable = CreateUnit(Player(0),'hfoo',x,y,0) PS. If you want reliable triggers/code then you should definitely go for JASS Scripting and local variables. |
| 05-14-2008, 06:20 PM | #3 |
I have always written code under the assumption that it is atomic, unless I use a wait. In other words, the code runs 'instantly' (in game time). I'm pretty sure this assumption is correct, but have never tested it. If anyone has counter-examples, that would be great. |
| 05-14-2008, 11:17 PM | #4 |
JASS only runs one thread at a time. Code cannot execute simultaneously so it's safe to code with that assumption in mind. That said you should just set the created unit directly to a variable and stop using BJ functions... |
| 05-15-2008, 08:33 AM | #5 |
thanx a lot ppl for reply!!! that really helps i guess i should have remembered that there is something like a trigger queue ... but still the last question : is it faster to use many specific trigger events, or few general trigger events ... that both add up to the same result? |
| 05-15-2008, 11:02 AM | #6 | |
Quote:
Or, just use locals and you can be sure nothing bad will happen :P |
| 05-15-2008, 02:12 PM | #7 |
i dont think that it makes sense to use local variables when you need the same variable within two different functions (triggered on different events). unless, a trigger, once it is activated keeps the value of the local variable even if the triggered function has finished running, ... is that the case? im at work so cant check right now :) but id still like to know :) |
| 05-15-2008, 03:30 PM | #8 |
There's only one 'real' Jass thread going at the same time. However, there's something you need to consider, things that may pass control to other threads: - waits - TriggerSyncwhatever - In some situations, if you do something that triggers an event, then it might call the trigger to which it was registered, blocking the current thread. |
| 05-15-2008, 03:39 PM | #9 | |
Quote:
Local variables are local to the function call, so no that won't work. You should elaborate on what you're trying to do, since your explanation sounds like an oh-so-wrong way to do things. |
| 05-15-2008, 05:13 PM | #10 |
well i was trying to figure out how to write good(stable,fast ect...) code, but to do so i need to know how the game handles it. So when i goto a larger scale i wont have to worry about unclean/slow code that will slow down the game which code is faster (going towards large numbers of regions)?: (units are placed in the game randomly all the time, Type A unit can only be placed in region1/2/3... , Sum[region1/2/3...] is a small subset of the playable map) Code:
EVENT: unit enters region (playable map)
CONDITION: unit is of type A
IF (unit is in region1) THEN
XXX
ELSE IF (unit is in region2) THEN
YYY
ELSE IF ...or Code:
EVENT: unit enters region (region1) CONDITION: unit is of type A XXX EVENT: unit enters region (region2) CONDITION: unit is of type A YYY EVENT: unit enters region (region3) CONDITION: unit is of type A ... |
| 05-15-2008, 08:22 PM | #11 | ||
Quote:
Example: Edit: Quote:
|
| 05-16-2008, 09:16 AM | #12 | |
Quote:
|
| 05-17-2008, 05:45 PM | #13 |
Learning how to write efficient code takes time, you have to dedicate some time to get familiarized with the scripting language, knowing bugs, techniques and other things related. Sometimes you have to review codes of other people to learn things. Also, A journey of a thousand miles begins with a step, you can start writing efficient code after you learn jass. I hope you realized that. |
