| 05-21-2004, 01:31 AM | #1 |
If this is posted in the wrong place, forgive me please. I just started learning jass. For hours today I went over this script changing it and could not figure it out. I even wrote it all out in the GUI and converted it and just got rid of the gg_trg_ stuff and made the triggers local. I've searched and found nothing. I finally give up. Could anyone tell me what I've done wrong? What i want to do is to give a footman a modified version of mirror attack when he gets attacked (basically just one with no mana cost so the little footy can use it), hence the word mirror everywhere. I'll remove the ability, etc. later but one step at a time. :) I put this stuff in the section you get when you click the map's name in the trigger editor. There are no categories and no global triggers, no global variables (I hope I used the right terms, still trying to learn the JASS lingo). Code:
function Trig_mirrorgive_Conditions takes nothing returns boolean
if (GetUnitTypeId(GetTriggerUnit()) == 'hfoo' ) then
return true
else
return false
endif
endfunction
//===========================================================================
function Trig_mirrorgive_Actions takes nothing returns nothing
if ( Trig_mirrorgive_Conditions() == true) then
call UnitAddAbilityBJ( 'A000', GetTriggerUnit() )
endif
endfunction
//===========================================================================
function InitMirror takes nothing returns nothing
local trigger mirrorgive = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( mirrorgive, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( mirrorgive, Condition( function Trig_mirrorgive_Conditions ) )
call TriggerAddAction( mirrorgive, function Trig_mirrorgive_Actions )
endfunction |
| 05-21-2004, 01:25 PM | #2 |
This belongs more in the AI/JASS vault, *moved* However, the reason it doesn't run, is that you expect the code in "InitMirror" to be run, however, unlike normal global triggers (in the trigger list) it won't. So you would need to either call that code yourself from somewhere, or just.... why don't you put it in it's own global trigger? I see no reason not too. Just create a trigger, convert it to custom-text, copy the contents of your Init function into the bottom function and then CnP the rest of it to replace anything else (above the bottom function) in your trigger. It "should" work then. ~Cubasis |
| 05-21-2004, 02:10 PM | #3 |
I figured this goes in trigger area as the description for ai/jass vault is for already working jass scripts but whatever. And as for the whole making a new trigger... if I did that then wouldn't that defeat the whole purpose of local triggers? I see other scripts that use maybe one or 2 global triggers in their whole thing. But anyways thanks for telling me I had to call it. I've looked over other scripts and never saw the call InitTrigger until now. I feel like a retard. Thank you, it works now. All this time I thought it was just a bad script. o_O |
| 05-22-2004, 01:29 PM | #4 |
'K, I don't really see any reason for this specially to be a local trigger, and think that you may be misunderstanding local triggers. However, if you wanna call up on the Trigger Creation function (InitMirror), just somewhere, in another trigger, do: call InitMirror() (in a "Custom Script" action if you're in GUI) Then this will work. The reason you don't have to do this to normal triggers, is that if you convert a trigger to Custom Script, the function you see at the bottom, it gets run at the start of the game, that is, before anything else, where it then creates the trigger etc. F.ex. try opening a map up in WinMPQ or sumtin, and open the war3map.j file. And scroll all the way down. There you'll see a couple of functions that WE creates automatically, that is, in relations to other programming languages, are "Main" functions, where the code starts. Anyways, local functions, are most often used to perform specialized job to a special subject/whatever. F.ex. a trigger that you create at run-time to control a unit (simulated AI). So if you're creating this trigger in-game at a certain point, to give the unit a ability when he's attacked, you should be careful to destroy it when his ability has been given .... or constantly be removing the abilities, cuz else throughout the game the unit will always be getting that ability, again and again, becouse that trigger will always be running. So, how about you explain what exactly you want to do, and then we can come up with something? I mean, what are the conditions for him getting the ability, and what is the condition of him losing it, and that kind of stuff. ~Cubasis |
| 05-24-2004, 02:53 AM | #5 |
Oh I know this has no reason to be a local trigger. It was just a simple one for me to learn. I've advanced a lot since I last posted, and this post has helped me. It's all just about learning, baby steps you know. :) |
