HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

New to JASS

11-25-2006, 06:31 PM#1
skatj
Hello, i've been following Vexorian's JASS tutorial and here's what I got. JASScraft gives me no syntax errors yet WE gives me like twenty when I try to save it.

Collapse JASS:
function Msg takes string s returns nothing
    call DisplayTextToForce( GetPlayersAll(), s )
endfunction

function Trig_loop_Actions takes nothing returns nothing
local integer i = GetRandomInt(1, 5)
local integer a = 1

call Msg("Loop will be repeated "+I2S(i)+" times")

loop
    exitwhen (a>i)
    call Msg("Hello, World!")
    set a =a+1
endloop

endfunction

//===========================================================================
function InitTrig_loop takes nothing returns nothing
    set gg_trg_loop = CreateTrigger(  )
    call TriggerRegisterPlayerKeyEventBJ( gg_trg_loop, Player(0), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP )
    call TriggerAddAction( gg_trg_loop, function Trig_loop_Actions )
endfunction

I attached my error log showing the first error I get, which is the in the Msg function.

Which is weird because I have the exact same function in my other trigger and it works perfectly fine, can you not have more than one of the same function?

I also get a lot of missing endloops at the end, but I have no idea where those errors are, but it's definitely not in my trigger.

I know how to GUI trigger but this JASS stuff is just gibberish to me.
Any help would be appreciated.
Attached Images
File type: jpgerrors.jpg (39.7 KB)
11-25-2006, 06:48 PM#2
wyrmlord
Quote:
Originally Posted by skatj
Which is weird because I have the exact same function in my other trigger and it works perfectly fine, can you not have more than one of the same function?

You cannot have more than 1 function with the same name.
11-25-2006, 06:54 PM#3
Fireeye
Change it this way and it will work.
Collapse JASS:
function Msg takes string s returns nothing
    call DisplayTextToForce( GetPlayersAll(), s )
endfunction

function Trig_Loop_Actions takes nothing returns nothing
local integer i = GetRandomInt(1, 5)
local integer a = 1

call Msg("Loop will be repeated "+I2S(i)+" times")

loop
    exitwhen (a>i)
    call Msg("Hello, World!")
    set a =a+1
endloop

endfunction

//===========================================================================
function InitTrig_Loop takes nothing returns nothing
    set gg_trg_Loop = CreateTrigger(  )
    call TriggerRegisterPlayerKeyEventBJ( gg_trg_Loop, Player(0), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_UP )
    call TriggerAddAction( gg_trg_Loop, function Trig_Loop_Actions )
endfunction
Attached Files
File type: w3mHello World!.w3m (12.1 KB)
11-25-2006, 06:54 PM#4
skatj
Quote:
You cannot have more than 1 function with the same name.

Okay I apologize, I should have just tried that before posting, but I was a bit confused I didn't think something like that would cause 26 compile errors.

It works now, thanks.

So if I have a function in any one trigger I can call it from any other trigger? Or does the trigger have to be in front of it or something?

Quote:
Change it this way and it will work.

So I should change the trigger name to uppercase? Or did I miss something else that you changed.

+rep to both of you
11-25-2006, 06:59 PM#5
Fireeye
you missed KEYEVENTTYPE_RELEASE
And if you want to use 1 action in more than 1 trigger, you have to add it into the custom script section, you find it when you click on the map button, on the top, in the trigger editor.
11-25-2006, 07:00 PM#6
skatj
Alright thanks, I just copied the event straight from the WE by converting it from GUI.

Works now.
11-27-2006, 11:47 PM#7
Joker
careful with loops, they create lots of compiled errors when you do something wrong with them. We you see like an error on everyline, just go over your loops and see if they are fine. Happened to me before
11-28-2006, 12:05 AM#8
TaintedReality
Quote:
So if I have a function in any one trigger I can call it from any other trigger? Or does the trigger have to be in front of it or something?

You can call it from any trigger as long as it's in front of it. However, in front does not mean on the trigger screen. From my experience, here are two rules (which might or might not be true) that seem to work.

1. The trigger with the function must have been created before the trigger calling the function.

2. When a map is loaded, it re-orders the triggers (or this might just be if a trigger has been deleted since the last load or something), and triggers are ordered by their position in the trigger editor.

So, just make sure the trigger holding the function was created before the calling trigger, and make sure it's above it in the trigger editor, and you should be fine. That's a good way to prevent your custom script section from becoming cluttered up when you're working on a large project.

Quote:
careful with loops, they create lots of compiled errors when you do something wrong with them. We you see like an error on everyline, just go over your loops and see if they are fine. Happened to me before

Actually several things can cause a large numbers of errors to show up, even if there is really only 1. Usually if you go to the first error and look on the line below it, that's where the real error will be.