- Joined
- Jul 10, 2007
- Messages
- 6,306
Please do show how it is easier for a user to use function interfaces. I'm not seeing it at all. Modules are much easier on the user than function interfaces are, lol.
Last edited:
struct Test extends array
private static method onDamage takes nothing returns nothing
endmethod
implement DDS
endstruct
struct Test extends array
private static method costfun takes nothing returns real
return 0.0
endmethod
implement Optimization
private static method onInit takes nothing returns nothing
// Lets imagine minimize is a static method of the struct Optimization
// This method then calls costfun several times. How should I access
// now to the parameters 1.0 and 5.2 from costfun without loosing
// abstraction by storing them in some placeholder fields of Optimization?
call Optimization.minimize(1.0, 5.2)
endmethod
endstruct
struct Test extends array
private static method costfun takes CostFunction costfun, real para1, real para2 returns real
return 0.0
endmethod
private static method onInit takes nothing returns nothing
local CostFunction costfun = CostFunction.costfun
call Optimization.minimize(costfun, 1.0, 5.2)
endmethod
endstruct
The system has 2 global variables, it sets them to the two parameters, then it calls all functions registered to the system.
If you are just talking about wanting to use your function directly, then use it directly, don't even bother with a function interface.
Any other examples? Clearly the first thing with the module is simpler than the second thing (in real scenarios). The second thing you gave is a very unrealistic scenario, it would normally have much more code associated with it. The first thing however is a realistic scenario.
Yes, but then I have to rely on those placeholder variables and can't just use the ones from my functions parameter list. That means I have to know and remember those names. Also this won't work when calling another cost function from the running cost function
No, because I might have multiple costfunctions with the same signature. Thats why function interfaces are so practical here.
You can pass them in too, and wtf, it will work when calling a cost function from a running cost function, it'll work perfectly, lol.
Does not UnitIndexer work with nested events? What about DDS? There's no reason why this wouldn't work as well. You simply need to know how to make it work, and doing that is easy.
Multiple structs![]()
And adding a new costfunction with a new signature will cause a lot of work because you have to index all parameters to allow those nested calls. When you now add a signature with four parameters instead of three you will have to adapt the indexing too.
local integer prev = var
set var = new
call event.fire()
set var = prev
Modules are easier on the user for events. For things other than events, like filters and options, it's best not to do them in the first place.
Indexing? huh?
Look up my tutorial on custom events
Lol, so the "solution" is "not do it"? Because of a performance drop that is hardly measurable? You can't be serious![]()
Well, that uses indexing, either with a stack or a list, but still you index the event data, so what?
globals
private trigger myEvent = CreateTrigger()
private integer data = 0
endglobals
function OnMyEvent takes boolexpr c returns nothing
call TriggerAddCondition(myEvent, c)
endfunction
function FireMyEvent takes integer d returns nothing
local integer prev = data //store the previous data in a local
set data = d
call TriggerEvaluate(myEvent)
set data = prev //set the data back to the previous value
endfunction
function GetEventData takes nothing returns nothing
return data
endfunction
Ahem, for filters/options, there is no solution. You wouldn't be using modules, triggers, or anything, heh. There is no performance to compare it against ;p. Filters/options just aren't recommended under any circumstances. You can do those in SC2 just fine though.
Filters/options just aren't recommended under any circumstances.
and I guess all made by you?
Why is this still being discussed anyway?
This should have come like 9 years ago.
Now you have 95% of the resources that don't follow any real convention.