Jump to content
  • 0

Callfunc help


Onairda

Question


  • Group:  Members
  • Topic Count:  71
  • Topics Per Day:  0.03
  • Content Count:  167
  • Reputation:   8
  • Joined:  12/30/16
  • Last Seen:  

Hello

 

Good day!

 

I am planning to create a Global function that will be used by different NPCs at the same time, and this Global function requires the variable. please see the below.

I have an Idea in C#, but not sure how this will work with Rathena

//------------------------

Test.txt - SCript

Prontera,150,150  - - - -{


mes "Input  1st Number:";

input .@FirstNumber;

next;


mes "Input  2nd Number:";

input .@SecondNumber;

.@total = callfunc add_numbers(.@FirstNumber, .@secondNumber)

}

 

//------------------------

GlobalFunc.txt - Script

GLOBAL function add_numbers(a, b)

 result = a + b

query_sql(Insert result to addition_tbl) 

return result

end
 

Edited by G-RO
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  18
  • Reputation:   0
  • Joined:  03/02/12
  • Last Seen:  

---------------------------------------

*callfunc "<function>"{,<argument>,...<argument>};
*callfunc("<function>"{,<argument>,...<argument>})

This command lets you call up a function NPC. A function NPC can be called from
any script on any map server. Using the 'return' command it will come back to
the place that called it.

	place,50,50,6%TAB%script%TAB%Woman%TAB%115,{
		mes "[Woman]"
		mes "Let's see if you win...";
		callfunc "funcNPC";
		mes "Well done, you have won!";
		close;
	}
	function%TAB%script%TAB%funcNPC%TAB%{
		.@win = rand(2);
		if (.@win == 0)
			return;
		mes "Sorry, you lost.";
		close;
	}

You can pass arguments to your function - values telling it what exactly to do -
which will be available there with getarg() (see 'getarg')
Notice that returning is not mandatory, you can end execution right there.

If you want to return a real value from inside your function NPC, it is better
to write it in the function form, which will also work and will make the script
generally cleaner:

	place,50,50,6%TAB%script%TAB%Man%TAB%115,{
		mes "[Man]"
		mes "Gimme a number!";
		next;
		input .@number;
		if (callfunc("OddFunc",.@number)) mes "It's Odd!";
		close;
	}
	function%TAB%script%TAB%OddFunc%TAB%{
		if (getarg(0)%2 == 0)
			return 0;// it's even
		return 1;// it's odd
	}

Alternately, as of rAthena revision 15979 and 15981, user-defined functions
may be called directly without the use of the 'callfunc' script command.

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

	place,50,50,6<tab>script<tab>Man<tab>115,{
		mes "[Man]";
		SayHello strcharinfo(0);
		close;
	}

Note:

 !! A user-defined function must be declared /before/ a script attempts to
 !! call it. That is to say, any functions should be placed above scripts or NPCs
 !! (or loaded in a separate file first) before attempting to call them directly.

---------------------------------------

https://github.com/rathena/rathena/blob/master/doc/script_commands.txt

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

function	script	add_numbers	{
	.@number_1 = getarg(0, 0);
	.@number_2 = getarg(1, 0);
	query_sql("INSERT INTO `table` (`value1`, `value2`) VALUES ("+.@number_1+", "+.@number_2+")");
	return (.@number_1 + .@number_2);
}
@sum = callfunc("add_numbers", 100, 200);

.

Link to comment
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.   Paste as plain text instead

  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.

×
×
  • Create New...