Calling a function as a script command

maqc1

New member
Messages
51
Points
0
Location
Québec
Github
maqc1
Emulator
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!

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

function Add;

mes ""+Add(1,2);

close;

function Add {

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

}

}

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

 
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.

 
Last edited by a moderator:
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


 
Last edited by a moderator:
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
default_wink.png


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

 
Last edited by a moderator:
Back
Top