| 08-23-2007, 05:30 PM | #1 |
Hi. I'm trying to learn Jass, while reading some tuts I stumbled upon the global triggers. I need help to determine if this thing that i made is ok or not.Here it is: JASS:function InitTrig_multiinstanceable takes nothing returns nothing local trigger TRIG set TRIG = CreateTrigger() call TriggerRegisterTimerEvent(TRIG, 5.0, true ) call TriggerAddAction(TRIG, function multiinstanceable) call DestroyTrigger (TRIG) set TRIG = null endfunction I've also read about the local triggers and may I ask if I can use them as global triggers? Thanks for your answers! |
| 08-23-2007, 05:59 PM | #2 |
No that piece of code is local trigger, it even says local trigger TRIG ^^. Anyways you are doing it good, this code is ok, keep it up. EDIT: Ups I didn't see, you have a serious error there. DO NOT DESTROY TRIGGERS, JUST NULL THEM JASS:function InitTrig_multiinstanceable takes nothing returns nothing local trigger TRIG set TRIG = CreateTrigger() call TriggerRegisterTimerEvent(TRIG, 5.0, true ) call TriggerAddAction(TRIG, function multiinstanceable) //call DestroyTrigger (TRIG) set TRIG = null endfunction |
| 08-23-2007, 06:12 PM | #3 |
hey thanks for the quick reply! ^_^ And thanks for telling me about not destroying triggers. I tried putting this code to the custom script code and it didnt work lol. JASS:function message takes nothing returns nothing local string words = " Hello World! " call DisplayTextToForce( GetPlayersAll(), "words" ) set words = null endfunction //------------------------------------------------ function Init_CallMessage takes nothing returns nothing local trigger trig set trig = CreateTrigger( ) call TriggerRegisterTimerEventSingle( trig, 5 ) call TriggerAddAction( trig, function message ) set trig = null endfunction + rep |
| 08-24-2007, 11:40 PM | #4 |
Since "words" is a variable, you'll use that instead of "words": call DisplayTextToForce( GetPlayersAll(), words )
Additionally, you don't need to null strings (you can't either, if I remember). Thus, you'll want to remove this line: set words = null When you say "custom script" does that mean that you're putting it in the map header? 'cause if you are, then the "Init_CallMessage" function is probably never being run. Thus, you'll need to call it from somewhere upon map init. |
| 08-25-2007, 04:00 PM | #5 |
Yes i did put it there, I was just testing it if it would run lol, I'm still new to Jass so thanks for the valuable info!. And about strings, they don't leak do they? Thanks again! |
| 08-25-2007, 04:14 PM | #6 | |
Quote:
Unfortunately they do leak, but the special thing is: You can't prevent them from leaking, because there is no function to free the space the strings need. But if you use the same string (maybe diffrent variables, but the same content) more often the string will still only be saved one time. (So I would say: A string "only" leaks its first occurrence) |
| 08-25-2007, 04:26 PM | #7 |
So if i used the string " Text " 10 times it would only leak once? |
| 08-25-2007, 04:36 PM | #8 |
Exactly, but for example this: set string_var="text"+I2S(int_var) will leak 2 strings everytime you call it with a different int_var. But in general I don't think that the effects of string leaks are crucial. At least you can't prevent it in most cases. |
| 08-25-2007, 04:50 PM | #9 |
Alright! I understand it now thanks for the vital data. + rep |
