The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling functions
Author Message
hctez
Apprentice
*

Posts: 11
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Apr 2012
Reputation: 0



Post: #1
Calling functions
Hello, i was wondering what is the difference between calling a function from an item, a player or using serv?
If i have a function that doesn't interact with a player or an item, for example a function that adds stuff to a list:

[function test]
list.test.add something
....
...

Is there a difference?
08-20-2015 11:17 AM
Find all posts by this user Like Post Quote this message in a reply
darksun84
Sir Spamalot
****

Posts: 1,687
Likes Given: 245
Likes Received: 162 in 151 posts
Joined: Mar 2012
Reputation: 35



Post: #2
RE: Calling functions
What actually changes is the type of the SRC object and default object (I).
So if you call a function from an item, the SRC object and the default object (I) references an item type, if you call from a character the SRC and default references to a character type .

The type means what default proprerties/function (like STR for a character) can be accessed from both SRC and the default object (I).
In your case the LIST command is a "global" command and can be used in a function that is called by items,characters and server object.

I am also sure that when calling a function from the server object, both SRC and default object are set to the server object only when the function is launched from the console.

Example:
[FUNCTION test]
log <name> <src.name>
serv.log <name> <src.name>

If this function is launched from the console the results will be:
1st line) Myshardname Myshardname
2nd line) Myshardname Myshardname

If this function is launched in game by typing .test the results will be:
1st line) An error, because log isn't accessible by a character type
2nd line) Myshardname, Charactername

If this function is launched in game by typing .serv.test the results will be:
1st line) Myshardname, CharacterName
2nd line) Myshardname, CharacterName

Even if you typed .serv.test the source object that called the function is still a character.
(This post was last modified: 08-20-2015 08:38 PM by darksun84.)
08-20-2015 08:38 PM
Find all posts by this user Like Post Quote this message in a reply
hctez
Apprentice
*

Posts: 11
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Apr 2012
Reputation: 0



Post: #3
RE: Calling functions
Thanks for answering, i already knew that, my question is when i have a function where i don't need to use any of those properties, is there a difference? Like the example function i use in my post. I can call that function from a player, item or using serv, and the result will be the same (add items to a list) but maybe is better to call it from serv instead of a random item for some reason, that was my question.
I talking maybe from a design or performance point of view

Thanks
(This post was last modified: 08-21-2015 05:05 AM by hctez.)
08-21-2015 05:02 AM
Find all posts by this user Like Post Quote this message in a reply
darksun84
Sir Spamalot
****

Posts: 1,687
Likes Given: 245
Likes Received: 162 in 151 posts
Joined: Mar 2012
Reputation: 35



Post: #4
RE: Calling functions
In a script, even if the function doesn't interact with a character or an item, most of time the one that call the function is an item or an character. As I wrote, the only way to set the SRC as the server object is to call the function from the server's console or use TRYSRV.

So at the end it doesn't matter Tongue

So i can understand better, when this function will be called ?
(This post was last modified: 08-21-2015 05:22 AM by darksun84.)
08-21-2015 05:10 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)