HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Conditions: What are they good for?

06-23-2009, 04:37 AM#1
Storyyeller
I've gotten into the habit of not using conditions at all. Instead, I'll include the condition checking code at the beginning of my event function and make it return early if the check fails.

I've begun wondering if this is actually a good idea though. So I figured I'd ask some actual JASS experts.

Which way is more efficient? Using conditions or not?
06-23-2009, 05:15 AM#2
Bobo_The_Kodo
Conditions make cleaner code. The speed difference is negligeble, though they are faster than actions.
06-23-2009, 05:32 AM#3
Storyyeller
Wouldn't having fewer functions to deal with lead to cleaner code, especially when the condition is only a single line?
06-23-2009, 07:27 AM#4
Bobo_The_Kodo
But the actions are only run when the conditions are true: they're seperate
06-23-2009, 11:55 AM#5
Opossum
If you have a big local chunk in your actions function then it's more efficient to have a condition added to the trigger because you can't return before the locals are initialized. Also you might even have to null some of them again before being able to return.
06-23-2009, 12:02 PM#6
Captain Griffen
You could do it all in the condition function instead and then return false, assuming you don't need waits.
06-23-2009, 12:31 PM#7
Michael Peppers
Another thread about this

I suggest you to search before asking :)
06-23-2009, 05:02 PM#8
Troll-Brain
Quote:
Originally Posted by Michael Peppers
I suggest you to search before asking :)

Said a guy which didn't try to use the search tool.

Not offensive, but try to find this thread with it, hf.

EDIT :

Also you don't need to worry about leaks if you destroy a trigger with conditions, but you have to if you use action, then you must use TriggerRemoveAction and so in most of cases attach the action to the trigger.
TriggerClearActions doesn't help here, it just de activate the actions.