Ahem, in constant timer loop 32, the code in the module may be calling code in the struct, and that code in the struct may be calling the code back in the module.
user timer code -> call destroy() (in struct)
struct code call stop (in module)
the destroyer has to be above the module so that the user's timer code can call it.
Then it's the design of the code which is flawed, because how jass work.
__________________
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.
You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag
I have a suggestion about the hooks. I think they should be more flexible.
There should be 2 more kinds of hooks, in my opinion :
- One that only calls the function instead of doing all this TriggerEvaluate thing. We definitely should have the choice, even if this solution causes problems in several situations, it would be usefull for the simpliest hooks that only use native functions and don't run much code. You may also give the option to use a TriggerExecute in the same way.
- One that totally replace the hooked function. Of course, the hook must not act inside the hooking function in that case. It would allow to call the function after the hooked one and get it's return value, for instance. It would also enable to make multiple calls (let's say if 2 objects are linked and that a function applying to one must apply to the other) or emulate the function with another.
An example of what could be done with those :
Code
Jass:
function CreateItemHook takesinteger itemid,real x,real y returnsitem localitem it =CreateItem(itemid, x, y) callSetItemInvulnerable(it,true) return it // I know it leaks but that's example. endfunction
// call and replace are the hook options. // The 2 last words are the usual arguments. hookcall replace CreateItem CreateItemHook
...
localitem it =CreateItem('I000',0,0)
And the output would be something like :
Jass:
globals triggerarray st___prototype2 item f__result_item integer f__arg_integer1 real f__arg_real1 real f__arg_real2
endglobals
// In current jasshelper, those functions are always created even if the "execute" version is never used. // You may adapt the creation of them to the hook option ("call", "evaluate" or "execute"). function sc___prototype2_execute takesinteger i,integer a1,real a2,real a3 returnsnothing set f__arg_integer1=a1 set f__arg_real1=a2 set f__arg_real2=a3
callTriggerExecute(st___prototype2[i]) endfunction function sc___prototype2_evaluate takesinteger i,integer a1,real a2,real a3 returnsitem set f__arg_integer1=a1 set f__arg_real1=a2 set f__arg_real2=a3
// Hook function moved to the header. In the worse case, it just pops an "undeclared function error". function CreateItemHook takesinteger itemid,real x,real y returnsitem //hook: CreateItemHook call replace localitem it=CreateItem(itemid, x, y)// CreateItem not hooked here. callSetItemInvulnerable(it,true) return it endfunction
...
call CreateItemHook('I000',0,0)
...
// jasshelper__initstructs functions ...
And the same example with an "evaluate" option :
Jass:
function CreateItemHook takesinteger itemid,real x,real y returnsitem localitem it =CreateItem(itemid, x, y) callSetItemInvulnerable(it,true) return it endfunction
// Same as "hook replace CreateItem CreateItemHook" hook evaluate replace CreateItem CreateItemHook
...
localitem it =CreateItem('I000',0,0)
And the output would be something like :
Jass:
globals triggerarray st___prototype2 item f__result_item integer f__arg_integer1 real f__arg_real1 real f__arg_real2
endglobals
function sc___prototype2_execute takesinteger i,integer a1,real a2,real a3 returnsnothing set f__arg_integer1=a1 set f__arg_real1=a2 set f__arg_real2=a3
callTriggerExecute(st___prototype2[i]) endfunction function sc___prototype2_evaluate takesinteger i,integer a1,real a2,real a3 returnsitem set f__arg_integer1=a1 set f__arg_real1=a2 set f__arg_real2=a3
function h__CreateItem takesinteger a0,real a1,real a2 returnsitem //hook: CreateItemHook return sc___prototype2_evaluate(1,a0,a1,a2)// As a side note : this doesn't leak anymore. endfunction
...
// Function not moved to top. function CreateItemHook takesinteger itemid,real x,real y returnsitem localitem it=CreateItem(itemid, x, y)// CreateItem not hooked here. callSetItemInvulnerable(it,true) return it endfunction
// jasshelper__initstructs functions called at map initialization : function sa___prototype2_CreateItemHook takesnothingreturnsboolean localinteger itemid=f__arg_integer1 localreal x=f__arg_real1 localreal y=f__arg_real2
localitem it=CreateItem(itemid, x, y)// CreateItem not hooked here either. callSetItemInvulnerable(it,true) set f__result_item= it returntrue endfunction
function jasshelper__initstructs1712796703 takesnothingreturnsnothing set st___prototype2[1]=CreateTrigger() callTriggerAddAction(st___prototype2[1],function sa___prototype2_CreateItemHook) callTriggerAddCondition(st___prototype2[1],Condition(function sa___prototype2_CreateItemHook))
endfunction
I hope it's clear and not too hard to make.
Thanks and congrats to update this tool. That's really an usefull work .
Is it possible to change the color scheme on the editor? or do I have to live with it? ^_^
Do you mean the JASS text? That is a TESH thing, you can just click "Options" in your trigger editor to change it. (or whatever the button is) It should have some color scheme options iirc.
@Tirlititi: I also hope that update occurs, hooking would be pretty powerful then--and a lot more useful.
I don't get it and I don't think you got it neither.
And that, my friends, is what happens when you read a post backwards and expect to get anything out of it. >.>
(No, I'm not talking about you, I'm talking about myself.)
Hooks are one of those arcane jasshelper features used by 0.0001% of mapmakers.
They replace standard wc3 functions with your own wrapper function.
In this they are similar to blizzard's BJ functions, but are worse because it is not obvious in other triggers code that something has changed.
Imho when you need to replace a default wc3 function with your own you should do it manually.
You can easily find all instances of a certain function by searching through your input .j script.
It is located in: jassnewgenpack5d\logs\input_war3map.j - my jasshelper mod jassnewgenpack5d\logs\inputwar3map.j - original jasshelper
It isn't for personal mapping so much as it is for systems. Hooking is rarely used because it is slow and very limited--we tend to avoid it even if it is a viable option either because: (A) it is slow or (B) we can't do what we actually want to 100%.
There are certain systems such as IDDS (just giving an example) which could benefit off this, as it makes the implementation/use much easier; especially if you already have code in your map.
At the moment hooks are weak and don't have many uses, but with a hook rewrite option people may be a bit more creative with their systems. For example, one could hook-rewrite certain registered player events and make them so they apply only for players actively playing to reduce handle count. Of course, that sort of thing isn't necessary, but it can give people more creativity in system design and will make implementation of certain systems far easier. (especially for GUI users)