Jump to content
  • 0
Sign in to follow this  
maqc1

Calling a function as a script command

Question

Hi folks! According to the wiki, it is possible to call a function as a script command :

 

http://herc.ws/wiki/Functions#Calling_Function_as_a_Script_Command

 

 


Calling Function as a Script Command
prontera,150,150,5<TAB>script<TAB>Calculator<TAB>999,{
    mes Add(1,2);

    function<TAB>Add<TAB>{
        return (getarg(0)+getarg(1));
    }
}

 

 

However, I am unable to reproduce the example. The console throws me a parse_line error :

 

[Error]: script error in file 'npc/test/test.txt' line 91 column 12
    parse_line: need ';'
    90: {
*   91:     mes Add(1,2);
        ~~~~~~~~~~~^
    92: 
    93:     function    Add     {
    94:         return (getarg(0)+getarg(1));

 

Is there any way to make this work? Or is it an error on the wiki?

 

Thanks in advance!

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0
prontera,155,175,5	script	Sample#npc	4_F_KAFRA9,{
	function	add	{
		return getarg(0,0) + getarg( 1,0);
	}
	
	mes "You get "+ add( 1,2 );
	close;
}


hmm, the forum seem like having some bug showing the tab indent ??

 

ORzJIhl.png

Edited by Emistry

Share this post


Link to post
Share on other sites
  • 0


prontera,150,150,5 script Calculator 999,{

function Add;

mes ""+Add(1,2);

close;

function Add {

return (getarg(0)+getarg(1));

}

}

Edited by Angelmelody

Share this post


Link to post
Share on other sites
  • 0

Nope, still the same error. It looks like this feature isn't implemented yet... Is anyone able to reproduce the wiki's example?

Share this post


Link to post
Share on other sites
  • 0

Iirc if you put tabs inside function declaration it'd try to read it as an NPC declaration, so just space them out and try. I use functions that way for a while, makes it easier to change and maintain.

Edited by Garr

Share this post


Link to post
Share on other sites
  • 0

Thanks Emistry, got it to work. The function needs to be declared ABOVE the function call. It was that simple!

 

Gotta get to work now ;)

 

 

EDIT : I just modified the wiki according to that rule.

Edited by maqc1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.