HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Triggers in Jass

11-04-2007, 01:40 AM#1
Salbrismind
I recently have started learning Jass, and up to now it was pretty straight forward. I made this code:

Collapse JASS:
function DivideNumbers takes integer num returns nothing

local integer lnum = 0 
loop 
    set lnum = lnum+1  
    
    if ModuloInteger(num,lnum) == 0 then
    call BJDebugMsg (I2S(num/lnum))
     endif
     
     exitwhen lnum == num    
    endloop
endfunction



function DivideNumbersAct takes nothing returns nothing
call DivideNumbers(15)
endfunction



function InitTrig_ActCode takes nothing returns nothing

local trigger Activate = CreateTrigger()
call TriggerRegisterPlayerEvent(Activate,Player(0),EVENT_PLAYER_ARROW_UP_DOWN)
call TriggerAddAction(Activate, function DivideNumbersAct)
set Activate = null
endfunction

I try it in the game and nothing happens when I press Up. Whats wrong with my code?
11-04-2007, 04:19 AM#2
zen87
add some debug message here and there, including the DivideNumbersAct see the trigger really runs =\
11-04-2007, 07:00 AM#3
sinners_la_b
change

Collapse JASS:
function InitTrig_ActCode takes nothing returns nothing

to

Collapse JASS:
function InitTrig_Activate takes nothing returns nothing
11-04-2007, 04:59 PM#4
Salbrismind
I tried both your suggestions, and the message "call BJDebug ("This works?")" in the function DivideNumbersAct didn't show me anything when I pressed up and with the second idea it still didn't work. Is there a certain place to put this code? I have every function in the map's custom script section.
11-04-2007, 05:43 PM#5
Captain Griffen
The init function won't be being run, then, so the trigger isn't initialised.
11-04-2007, 06:55 PM#6
Salbrismind
Quote:
Originally Posted by Captain Griffen
The init function won't be being run, then, so the trigger isn't initialised.

So how do i make it work?
11-04-2007, 07:18 PM#7
Pyrogasm
Tell us the name of the trigger in the trigger editor.
11-04-2007, 07:59 PM#8
Salbrismind
Quote:
Originally Posted by Pyrogasm
Tell us the name of the trigger in the trigger editor.

Currently it wasn't a trigger in the editor the code was just up in the custom script area of the map (map name on the trigger list). I tried it with the name Jass Test, and even Activate. Why?
11-04-2007, 08:24 PM#9
Jazradel
Nothing is running.
You have to have something named:
InitTrig_TriggerName
in trigger TriggerName and it will run that when the maps starts (registering the events).
11-04-2007, 08:35 PM#10
Deaod
when I came over this error I solved it by creating a Dummy Trigger, calling the InitTrig of my custom Script; That trigger called every other InitTrig needed.
That worked for me, I don't know if this is the best way.

Deaod
11-04-2007, 08:39 PM#11
cohadar
This is how pros make triggers:

Collapse JASS:
scope Example

private function Conditions takes nothing returns boolean
    return false
endfunction

private function Actions takes nothing returns nothing
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( trig, Player(0), "-test", true )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

And then just make sure your scope name is the same as your trigger name.
11-04-2007, 09:27 PM#12
Salbrismind
Quote:
Originally Posted by Jazradel
Nothing is running.
You have to have something named:
InitTrig_TriggerName
in trigger TriggerName and it will run that when the maps starts (registering the events).

Explain it a little bit more? This is my second Jass code (first was just a simple find the factors).


Quote:
Originally Posted by Deaod
when I came over this error I solved it by creating a Dummy Trigger, calling the InitTrig of my custom Script; That trigger called every other InitTrig needed.
That worked for me, I don't know if this is the best way.

Deaod

What do you mean "called every other InitTrig"?


And Cohadar, All i need then is to put scope and endscope around my trigger? I'll try your suggestion.

Updated: Jasscraft won't highlight scope and when i input the code it doesn't work.
11-04-2007, 09:48 PM#13
Captain Griffen
It's vJASS that cohadar is using.

Please learn JASS. Thank you.
11-04-2007, 10:20 PM#14
Salbrismind
Quote:
Originally Posted by Captain Griffen
It's vJASS that cohadar is using.

Please learn JASS. Thank you.

Oh okay, but how would I fix this is normal Jass...

"Please learn JASS." Is this directed toward me? I am trying to learn JASS and as I have been reading tutorials and this is how it taught me to write a trigger, yet it doesn't work. Thus i came here in hopes someone would be nice enough to spend a few minutes to explain it to me. Some of you have and I am thankful but if you could just help me a bit more until I can do triggers on my own.

Heres a question: Is doing triggers like this even that nessicary? Or can I just use the custom script action to call a function to do the things I want.
11-04-2007, 10:34 PM#15
cohadar
Download NewGen and start learning vJass.
Plain Jass is lame, and since you will be eventually learning vJass anyway
you can save yourself the trouble and skip common Jass.

Oh and jasscraft will highlight the scope and endscope keywords,
you don't have the latest version.