• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Expected a function name

Status
Not open for further replies.

sentrywiz

S

sentrywiz

I just started learning jass. Taking on this tutorial:

http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/beginning-jass-tutorial-series-30765/

But I can't even pass the first lessons without a boatload of errors.

I want to try this code:

JASS:
function Trig_bla_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_bla takes nothing returns nothing
    set gg_trg_bla = CreateTrigger(  )
    call TriggerAddAction( gg_trg_bla, function Trig_bla_Actions )
endfunction

function DisplayAMessage takes string message returns nothing
    call BJDebugMsg(message)
endfunction

And call the function from another trigger

  • Trigger
    • Events
      • Player - Player 1 (Red) Presses the Left Arrow key
    • Conditions
    • Actions
      • Custom script: call DisplayAMessage("Hello")
And its not letting me, tells me the "Expected function name" error and the function is clearly named DisplayAMessage.

Can anyone tell me why oh why?
 
JASS requires functions to be above the one you're calling in. For example:
JASS:
function C takes nothing returns nothing
    call A() // error, A is not above C
endfunction

function A takes nothing returns nothing
endfunction

function B takes nothing returns nothing
    call A() // no error
endfunction

In your case, GUI triggers are all converted to JASS and arranged in a particular order in the resulting war3map.j (the map's script). If trigger "bla" is put after "Trigger", then "Trigger" will throw an error. If "Trigger" is placed after "bla", then there won't be an error.

Usually, in regular JASS, you would put a function in the map's header. This places it on the top of the map script so that it can be used in any of your triggers. To find the map's header, open the trigger editor and click the map's name in the left window (above where all the triggers and folders are listed). On the right, you should see a window where you can add text. Simply cut and paste your function there, save, and it should work.

Almia has an alternative method: http://www.hiveworkshop.com/forums/...ials-280/use-functions-other-triggers-232537/

Otherwise, in vJASS (if you are using JNGP), we use libraries to ensure that our code is placed above others. This way, you can put it inside a trigger, but still have it above everything else. That is just a brief explanation of libraries (there is more to them), but here is an example of simple usage:
JASS:
library A
    function DisplayAMessage takes string s returns nothing
        call BJDebugMsg("Hello World")
    endfunction
endlibrary

If you are using vJASS (i.e. you have JassNewGenPack + jasshelper enabled), that would also allow your code to work.
 

sentrywiz

S

sentrywiz

Thanks for your detailed post.

However I posted this in the Triggers & Scripts and it was obviously my fault, but it was because I didn't put the code in the custom script section above the map. I just made triggers -> converted them to custom text. It even said that in the tutorial, but I managed to miss that part.

So if I am using vJass, I can make a library of functions I use and they will be automatically be put above everything else so it always works?

Do you mind answering, since I am just beginning to learn Jass, what is the difference between JASS and vJASS?
And should I learn JASS before advancing to vJASS?
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
That is the idea behind libraries. Essentially if you want to use functions outside of the library you're in, you need to use the requires keyword.

Here's an example

JASS:
library math

function A …
…
endfunction

endlibrary

Now if you want to use the function A from the library "math" somewhere else, you could do this.

JASS:
library usesMath requires math

function B …
…
call A(…) //this works, since we guaranteed A() is above B()
…
endfunction

endlibrary

In regards to your other questions:
what is the difference between JASS and vJASS?
And should I learn JASS before advancing to vJASS?

1. VJASS is simply a higher level version of regular JASS. They are the same exact language, but VJASS offers a lot of syntax simplifications which make doing things like OOP much easier, and also a pre-compiler so you do not have to busy yourself with the internals of the final map script (e.g. the globals block).

2. No. That would be like learning Assembly language before trying a higher level language like Python or Java.

Learning to write in vanilla JASS is tedious, but what is important is knowing the syntax and keywords, which are the same in VJASS.
 

sentrywiz

S

sentrywiz

Yeah, I just browsed a vJass tutorial, it explained to me.

Thanks for your post though. Libraries are what I was looking for yesterday, but I'm still a beginner so I will learn eventually :)
 
Status
Not open for further replies.
Top