Jump to content

Functions


Matheus

Recommended Posts


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   6
  • Joined:  11/15/11
  • Last Seen:  

function call with script should be called like C, just the name of the function with the params, example:

functioname(param1, param2, param3...);

Much more easy in my vision .. this will make the emulador be more slowly ?

ps: sorry for my bad english

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  562
  • Reputation:   152
  • Joined:  02/21/12
  • Last Seen:  

you can actually do it.

function functionname;

functionname(param1, param2, param3,...);

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   6
  • Joined:  11/15/11
  • Last Seen:  

Yes, but the function should be inside the script. If the functions being called just by their names, out stead of changing the source, you can do with scripts (and you can create a lot of library's too, make the work of create a script, easier).

sorry for my bad english.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  562
  • Reputation:   152
  • Joined:  02/21/12
  • Last Seen:  

you can call the function by just using the functionname in script.

Read my snippet. ^

- script sample -1,{
function func_sample;

func_sample(param1,param2,...);

function func_sample {
blablabla getarg(0) blabla getarg(1)...
}
}

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   6
  • Joined:  11/15/11
  • Last Seen:  

I know tr0n, but what i mean, is call a function with the name, without her inside of script ..

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  562
  • Reputation:   152
  • Joined:  02/21/12
  • Last Seen:  

outside the script:

function script func_name {
}

you can call it like the other functions.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   6
  • Joined:  11/15/11
  • Last Seen:  

for god sake tr0n, i know that, i'm scripter, i know you can call that function, but need of "callfunc", i want call the function JUST WITH THE NAME !

again: sorry for my bad english

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  562
  • Reputation:   152
  • Joined:  02/21/12
  • Last Seen:  

It is possible to call the function with the functionname only.

That's what I'm telling you all the time.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  67
  • Reputation:   23
  • Joined:  11/14/11
  • Last Seen:  

I think he want to call the function without the "callfunc"

function	script	plus	{
return getarg(0) + getarg(1);
}

prontera,100,100,4	script	Plus NPC	508,{
mes "5 + 6 = " + plus(5, 6);
close;
}

yes you can't do that, but.. whats wrong with "callfunc"?

function	script	plus	{
return getarg(0) + getarg(1);
}

prontera,100,100,4	script	Plus NPC	508,{
mes "5 + 6 = " + callfunc("plus", 5, 6);
close;
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  562
  • Reputation:   152
  • Joined:  02/21/12
  • Last Seen:  

function	script	plus	{
return getarg(0) + getarg(1);
}

prontera,100,100,4	script	Plus NPC	508,{

function plus;

mes "5 + 6 = " + plus(5, 6);
close;
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  67
  • Reputation:   23
  • Joined:  11/14/11
  • Last Seen:  

Please read this: ../doc/script_commands.txt

*function <function name>;

*<function name>;

*function <function name> {

<code>

}

(Skotlex stop being so selfish and give us all the commands T~T! J/k lol :P)

This works like callfunc. It's used for cleaner and fast scripting. Also they

must be inside a script. They're not separated scripts and they work more like

labels with arguments.

for function outside npc script, it must use "callfunc"

Edited by FatalEror
  • Upvote 2
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  562
  • Reputation:   152
  • Joined:  02/21/12
  • Last Seen:  

Please read this: ../doc/script_commands.txt

*function <function name>;

*<function name>;

*function <function name> {

<code>

}

(Skotlex stop being so selfish and give us all the commands T~T! J/k lol :P)

This works like callfunc. It's used for cleaner and fast scripting. Also they

must be inside a script. They're not separated scripts and they work more like

labels with arguments.

for function outside npc script, it must use "callfunc"

I didn't read that. mkay..

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   6
  • Joined:  11/15/11
  • Last Seen:  

callfunc in my opinion is ugly, and tr0n, i know you can't call a function just by her name, that's why i created this topic, to see if some core developer can do it

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  4
  • Reputation:   0
  • Joined:  11/15/11
  • Last Seen:  

It's this?

prontera,150,150,5/*Tab*/script/*Tab*/normal/*Tab*/50,{

function exit;

exit "msg";

}

function/*Tab*/script/*Tab*/exit/*Tab*/{

mes getarg( 0);

return close;

}

To use a function without use a callfunc you, you just have to use function name_of_the_function; in the beggining of the script.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  67
  • Reputation:   23
  • Joined:  11/14/11
  • Last Seen:  

It's this?

prontera,150,150,5/*Tab*/script/*Tab*/normal/*Tab*/50,{
function exit;
exit "msg";
}

function/*Tab*/script/*Tab*/exit/*Tab*/{
mes getarg( 0);
return close;
}

To use a function without use a callfunc you, you just have to use function name_of_the_function; in the beggining of the script.

umm.. please read my post above..

you can't declare a function that is outside of npc script..

Edited by FatalEror
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  4
  • Reputation:   0
  • Joined:  11/15/11
  • Last Seen:  

=/

I figure out that the correct way is:

prontera,150,150,5 script normal 50,{
function exit;
exit "msg";


function exit {
mes getarg(0);
close;
}
}

But there is no way to use just "function exit;" in other scripts, just if you use the function together.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  4
  • Reputation:   0
  • Joined:  11/15/11
  • Last Seen:  

@edit sorry '-'

Edited by Ansen
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  633
  • Reputation:   78
  • Joined:  11/14/11
  • Last Seen:  

- script sample -1,{
function func_sample;

func_sample(param1,param2,...);

function func_sample {
blablabla getarg(0) blabla getarg(1)...
}
}

I think @Dreaming means is the global side of that function since it can only be use inside the script (hope Iam right).

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   6
  • Joined:  11/15/11
  • Last Seen:  

- script sample -1,{
function func_sample;

func_sample(param1,param2,...);

function func_sample {
blablabla getarg(0) blabla getarg(1)...
}
}

I think @Dreaming means is the global side of that function since it can only be use inside the script (hope Iam right).

Yes !! With that, you can use one function, with 9999999999999 scripts and use each function without putting them on everyone Edited by Dreaming
Link to comment
Share on other sites

  • 2 weeks later...

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  52
  • Reputation:   6
  • Joined:  01/06/12
  • Last Seen:  

You can use the function globally just with 'callfunc("FunctionName",arg1,arg2,...);', which other people have stated. Wouldn't it just be a cosmetic change to make it follow C syntax (as in, FunctionName(arg1,arg2,arg3,...); )?

I mean... call it 'ugly' but I actually like callfunc, using it as a way to keep track of various function calls is convenient for large scripts, especially when you can just ctrl+F for callfunc when you forget your function names after a month of not looking at a script.

I guess it would be cool and all, but is it really worth the work necessary to get it in? (Especially if SketchyPhoenix's Lua Script Engine gets finished and implemented)

tl;dr

Is it really that much of an inconvenience to type callfunc("FunctionName",arg1,arg2,...);?

Edit: Wow, 10 days later, sorry! Facebook just posted this up for me today so I thought it was more recent.

Edited by Variant
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  117
  • Reputation:   167
  • Joined:  11/10/11
  • Last Seen:  

After reviewing this topic, I dove into the source and had a poke around and support for direct function invocation was added in r15979 :o

As such, the following should now work:

function<tab>script<tab>helloworld<tab>{
       mes "Hello " + getarg(0);
       return 1;
}

prontera,150,150,4<tab>script<tab>Say Hello!<tab>811,{
       helloworld strcharinfo(0);
       close;
}

  • Upvote 3
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   6
  • Joined:  11/15/11
  • Last Seen:  

Thank you ! You're awesome :o !

Link to comment
Share on other sites

×
×
  • Create New...